New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
mpp_nfd_generic.h90 in NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC – NEMO

source: NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/LBC/mpp_nfd_generic.h90 @ 13887

Last change on this file since 13887 was 10423, checked in by smasson, 5 years ago

dev_r10164_HPC09_ESIWACE_PREP_MERGE: switch off optimisation introduced in [10175], see #2133

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-fortran
File size: 13.1 KB
Line 
1#if defined MULTI
2#   define NAT_IN(k)                cd_nat(k)   
3#   define SGN_IN(k)                psgn(k)
4#   define F_SIZE(ptab)             kfld
5#   define LBC_ARG                  (jf)
6#   if defined DIM_2d
7#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D)     , INTENT(inout) ::   ptab(f)
8#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt2d(i,j)
9#      define K_SIZE(ptab)             1
10#      define L_SIZE(ptab)             1
11#   endif
12#   if defined DIM_3d
13#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_3D)     , INTENT(inout) ::   ptab(f)
14#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt3d(i,j,k)
15#      define K_SIZE(ptab)             SIZE(ptab(1)%pt3d,3)
16#      define L_SIZE(ptab)             1
17#   endif
18#   if defined DIM_4d
19#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_4D)     , INTENT(inout) ::   ptab(f)
20#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt4d(i,j,k,l)
21#      define K_SIZE(ptab)             SIZE(ptab(1)%pt4d,3)
22#      define L_SIZE(ptab)             SIZE(ptab(1)%pt4d,4)
23#   endif
24#else
25!                          !==  IN: ptab is an array  ==!
26#   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp)         , INTENT(inout) ::   ARRAY_IN(i,j,k,l,f)
27#   define NAT_IN(k)                cd_nat
28#   define SGN_IN(k)                psgn
29#   define F_SIZE(ptab)             1
30#   define LBC_ARG
31#   if defined DIM_2d
32#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
33#      define K_SIZE(ptab)          1
34#      define L_SIZE(ptab)          1
35#   endif
36#   if defined DIM_3d
37#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
38#      define K_SIZE(ptab)          SIZE(ptab,3)
39#      define L_SIZE(ptab)          1
40#   endif
41#   if defined DIM_4d
42#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
43#      define K_SIZE(ptab)          SIZE(ptab,3)
44#      define L_SIZE(ptab)          SIZE(ptab,4)
45#   endif
46#endif
47
48   SUBROUTINE ROUTINE_NFD( ptab, cd_nat, psgn, kfld )
49      !!----------------------------------------------------------------------
50      ARRAY_TYPE(:,:,:,:,:)   ! array or pointer of arrays on which the boundary condition is applied
51      CHARACTER(len=1) , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
52      REAL(wp)         , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
53      INTEGER, OPTIONAL, INTENT(in   ) ::   kfld        ! number of pt3d arrays
54      !
55      INTEGER  ::   ji,  jj,  jk,  jl, jh, jf, jr   ! dummy loop indices
56      INTEGER  ::   ipi, ipj, ipk, ipl, ipf         ! dimension of the input array
57      INTEGER  ::   imigr, iihom, ijhom             ! local integers
58      INTEGER  ::   ierr, ibuffsize, ilci, ildi, ilei, iilb
59      INTEGER  ::   ij, iproc
60      INTEGER, DIMENSION (jpmaxngh)       ::   ml_req_nf   ! for mpi_isend when avoiding mpi_allgather
61      INTEGER                             ::   ml_err      ! for mpi_isend when avoiding mpi_allgather
62      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat     ! for mpi_isend when avoiding mpi_allgather
63      !                                                    ! Workspace for message transfers avoiding mpi_allgather
64      INTEGER                             ::   ipf_j       ! sum of lines for all multi fields
65      INTEGER                             ::   js          ! counter
66      INTEGER, DIMENSION(:,:),          ALLOCATABLE ::   jj_s  ! position of sent lines
67      INTEGER, DIMENSION(:),            ALLOCATABLE ::   ipj_s ! number of sent lines
68      REAL(wp), DIMENSION(:,:,:)      , ALLOCATABLE ::   ztabl
69      REAL(wp), DIMENSION(:,:,:,:,:)  , ALLOCATABLE ::   ztab, ztabr
70      REAL(wp), DIMENSION(:,:,:,:,:)  , ALLOCATABLE ::   znorthloc, zfoldwk     
71      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   znorthgloio
72      !!----------------------------------------------------------------------
73      !
74      ipk = K_SIZE(ptab)   ! 3rd dimension
75      ipl = L_SIZE(ptab)   ! 4th    -
76      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
77      !
78      IF( l_north_nogather ) THEN      !==  ????  ==!
79
80         ALLOCATE(ipj_s(ipf))
81
82         ipj      = 2            ! Max 2nd dimension of message transfers (last two j-line only)
83         ipj_s(:) = 1            ! Real 2nd dimension of message transfers (depending on perf requirement)
84                                 ! by default, only one line is exchanged
85
86         ALLOCATE( jj_s(ipf,2) )
87
88         ! re-define number of exchanged lines :
89         !  must be two during the first two time steps
90         !  to correct possible incoherent values on North fold lines from restart
91
92         !!!!!!!!! temporary switch off this optimisation ==> force TRUE !!!!!!!!
93         l_full_nf_update = .TRUE.
94
95         ! Two lines update (slower but necessary to avoid different values ion identical grid points
96         IF ( l_full_nf_update .OR.                          &    ! if coupling fields
97              ( ncom_stp == nit000 .AND. .NOT. ln_rstart ) ) &    ! at first time step, if not restart
98            ipj_s(:) = 2
99
100         ! Index of modifying lines in input
101         DO jf = 1, ipf                      ! Loop over the number of arrays to be processed
102            !
103            SELECT CASE ( npolj )
104            !
105            CASE ( 3, 4 )                       ! *  North fold  T-point pivot
106               !
107               SELECT CASE ( NAT_IN(jf) )
108               !
109               CASE ( 'T' , 'W' ,'U' )                            ! T-, U-, W-point
110                  jj_s(jf,1) = nlcj - 2 ;  jj_s(jf,2) = nlcj - 1
111               CASE ( 'V' , 'F' )                                 ! V-, F-point
112                  jj_s(jf,1) = nlcj - 3 ;  jj_s(jf,2) = nlcj - 2
113               END SELECT
114            !
115            CASE ( 5, 6 )                        ! *  North fold  F-point pivot
116               SELECT CASE ( NAT_IN(jf) )
117               !
118               CASE ( 'T' , 'W' ,'U' )                            ! T-, U-, W-point
119                  jj_s(jf,1) = nlcj - 1     
120                  ipj_s(jf) = 1                  ! need only one line anyway
121               CASE ( 'V' , 'F' )                                 ! V-, F-point
122                  jj_s(jf,1) = nlcj - 2 ;  jj_s(jf,2) = nlcj - 1
123               END SELECT
124            !
125            END SELECT
126            !
127         ENDDO
128         !
129         ipf_j = sum (ipj_s(:))      ! Total number of lines to be exchanged
130         !
131         ALLOCATE( znorthloc(jpimax,ipf_j,ipk,ipl,1) )
132         !
133         js = 0
134         DO jf = 1, ipf                      ! Loop over the number of arrays to be processed
135            DO jj = 1, ipj_s(jf)
136               js = js + 1
137               DO jl = 1, ipl
138                  DO jk = 1, ipk
139                     znorthloc(1:jpi,js,jk,jl,1) = ARRAY_IN(1:jpi,jj_s(jf,jj),jk,jl,jf)
140                  END DO
141               END DO
142            END DO
143         END DO
144         !
145         ibuffsize = jpimax * ipf_j * ipk * ipl
146         !
147         ALLOCATE( zfoldwk(jpimax,ipf_j,ipk,ipl,1) )
148         ALLOCATE( ztabr(jpimax*jpmaxngh,ipj,ipk,ipl,ipf) ) 
149         ! when some processors of the north fold are suppressed,
150         ! values of ztab* arrays corresponding to these suppressed domain won't be defined
151         ! and we need a default definition to 0.
152         ! a better test should be: a testing if "suppressed land-processors" belongs to the north-pole folding
153         IF ( jpni*jpnj /= jpnij ) ztabr(:,:,:,:,:) = 0._wp
154         !
155         ! start waiting time measurement
156         IF( ln_timing ) CALL tic_tac(.TRUE.)
157         !
158         DO jr = 1, nsndto
159            IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN
160               CALL mppsend( 5, znorthloc, ibuffsize, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) )
161            ENDIF
162         END DO
163         !
164         DO jr = 1,nsndto
165            iproc = nfipproc(isendto(jr),jpnj)
166            IF(iproc /= -1) THEN
167               iilb = nimppt(iproc+1)
168               ilci = nlcit (iproc+1)
169               ildi = nldit (iproc+1)
170               ilei = nleit (iproc+1)
171               IF( iilb            ==      1 )   ildi = 1      ! e-w boundary already done -> force to take 1st column
172               IF( iilb + ilci - 1 == jpiglo )   ilei = ilci   ! e-w boundary already done -> force to take last column
173               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
174            ENDIF
175            IF( iproc /= narea-1 .AND. iproc /= -1 ) THEN
176               CALL mpprecv(5, zfoldwk, ibuffsize, iproc)
177               js = 0
178               DO jf = 1, ipf ; DO jj = 1, ipj_s(jf)
179                  js = js + 1
180                  DO jl = 1, ipl
181                     DO jk = 1, ipk
182                        DO ji = ildi, ilei
183                           ztabr(iilb+ji,jj,jk,jl,jf) = zfoldwk(ji,js,jk,jl,1)
184                        END DO
185                     END DO
186                  END DO
187               END DO; END DO
188            ELSE IF( iproc == narea-1 ) THEN
189               DO jf = 1, ipf ; DO jj = 1, ipj_s(jf)
190                  DO jl = 1, ipl
191                     DO jk = 1, ipk
192                        DO ji = ildi, ilei
193                           ztabr(iilb+ji,jj,jk,jl,jf) = ARRAY_IN(ji,jj_s(jf,jj),jk,jl,jf)
194                        END DO
195                     END DO
196                  END DO
197               END DO; END DO
198            ENDIF
199         END DO
200         IF( l_isend ) THEN
201            DO jr = 1,nsndto
202               IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN
203                  CALL mpi_wait( ml_req_nf(jr), ml_stat, ml_err )
204               ENDIF
205            END DO
206         ENDIF
207         !
208         IF( ln_timing ) CALL tic_tac(.FALSE.)
209         !
210         ! North fold boundary condition
211         !
212         DO jf = 1, ipf
213            CALL lbc_nfd_nogather(ARRAY_IN(:,:,:,:,jf), ztabr(:,1:ipj_s(jf),:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG )
214         END DO
215         !
216         DEALLOCATE( zfoldwk )
217         DEALLOCATE( ztabr ) 
218         DEALLOCATE( jj_s ) 
219         DEALLOCATE( ipj_s ) 
220      ELSE                             !==  ????  ==!
221         !
222         ipj   = 4            ! 2nd dimension of message transfers (last j-lines)
223         !
224         ALLOCATE( znorthloc(jpimax,ipj,ipk,ipl,ipf) )
225         !
226         DO jf = 1, ipf                ! put in znorthloc the last ipj j-lines of ptab
227            DO jl = 1, ipl
228               DO jk = 1, ipk
229                  DO jj = nlcj - ipj +1, nlcj
230                     ij = jj - nlcj + ipj
231                     znorthloc(1:jpi,ij,jk,jl,jf) = ARRAY_IN(1:jpi,jj,jk,jl,jf)
232                  END DO
233               END DO
234            END DO
235         END DO
236         !
237         ibuffsize = jpimax * ipj * ipk * ipl * ipf
238         !
239         ALLOCATE( ztab       (jpiglo,ipj,ipk,ipl,ipf     ) )
240         ALLOCATE( znorthgloio(jpimax,ipj,ipk,ipl,ipf,jpni) )
241         !
242         ! when some processors of the north fold are suppressed,
243         ! values of ztab* arrays corresponding to these suppressed domain won't be defined
244         ! and we need a default definition to 0.
245         ! a better test should be: a testing if "suppressed land-processors" belongs to the north-pole folding
246         IF ( jpni*jpnj /= jpnij ) ztab(:,:,:,:,:) = 0._wp
247         !
248         ! start waiting time measurement
249         IF( ln_timing ) CALL tic_tac(.TRUE.)
250         CALL MPI_ALLGATHER( znorthloc  , ibuffsize, MPI_DOUBLE_PRECISION,                &
251            &                znorthgloio, ibuffsize, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
252         !
253         ! stop waiting time measurement
254         IF( ln_timing ) CALL tic_tac(.FALSE.)
255         !
256         DO jr = 1, ndim_rank_north         ! recover the global north array
257            iproc = nrank_north(jr) + 1
258            iilb  = nimppt(iproc)
259            ilci  = nlcit (iproc)
260            ildi  = nldit (iproc)
261            ilei  = nleit (iproc)
262            IF( iilb            ==      1 )   ildi = 1      ! e-w boundary already done -> force to take 1st column
263            IF( iilb + ilci - 1 == jpiglo )   ilei = ilci   ! e-w boundary already done -> force to take last column
264            DO jf = 1, ipf
265               DO jl = 1, ipl
266                  DO jk = 1, ipk
267                     DO jj = 1, ipj
268                        DO ji = ildi, ilei
269                           ztab(ji+iilb-1,jj,jk,jl,jf) = znorthgloio(ji,jj,jk,jl,jf,jr)
270                        END DO
271                     END DO
272                  END DO
273               END DO
274            END DO
275         END DO
276         DO jf = 1, ipf
277            CALL lbc_nfd( ztab(:,:,:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG )   ! North fold boundary condition
278         END DO
279         !
280         DO jf = 1, ipf
281            DO jl = 1, ipl
282               DO jk = 1, ipk
283                  DO jj = nlcj-ipj+1, nlcj             ! Scatter back to ARRAY_IN
284                     ij = jj - nlcj + ipj
285                     DO ji= 1, nlci
286                        ARRAY_IN(ji,jj,jk,jl,jf) = ztab(ji+nimpp-1,ij,jk,jl,jf)
287                     END DO
288                  END DO
289               END DO
290            END DO
291         END DO
292         !
293      !
294         DEALLOCATE( ztab )
295         DEALLOCATE( znorthgloio )
296      ENDIF
297      !
298      DEALLOCATE( znorthloc )
299      !
300   END SUBROUTINE ROUTINE_NFD
301
302#undef ARRAY_TYPE
303#undef NAT_IN
304#undef SGN_IN
305#undef ARRAY_IN
306#undef K_SIZE
307#undef L_SIZE
308#undef F_SIZE
309#undef LBC_ARG
Note: See TracBrowser for help on using the repository browser.