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, itaille, 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 | REAL(wp), DIMENSION(:,:,:,:,:) , ALLOCATABLE :: ztab, ztabl, ztabr |
---|
65 | REAL(wp), DIMENSION(:,:,:,:,:) , ALLOCATABLE :: znorthloc, zfoldwk |
---|
66 | REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE :: znorthgloio |
---|
67 | !!---------------------------------------------------------------------- |
---|
68 | ! |
---|
69 | ipk = K_SIZE(ptab) ! 3rd dimension |
---|
70 | ipl = L_SIZE(ptab) ! 4th - |
---|
71 | ipf = F_SIZE(ptab) ! 5th - use in "multi" case (array of pointers) |
---|
72 | ! |
---|
73 | ipj = 4 ! 2nd dimension of message transfers (last j-lines) |
---|
74 | ! |
---|
75 | ALLOCATE( znorthloc(jpimax,4,ipk,ipl,ipf) ) |
---|
76 | ! |
---|
77 | znorthloc(:,:,:,:,:) = 0._wp |
---|
78 | ! |
---|
79 | DO jf = 1, ipf ! put in znorthloc the last ipj j-lines of ptab |
---|
80 | DO jl = 1, ipl |
---|
81 | DO jk = 1, ipk |
---|
82 | DO jj = nlcj - ipj +1, nlcj |
---|
83 | ij = jj - nlcj + ipj |
---|
84 | znorthloc(1:jpi,ij,jk,jl,jf) = ARRAY_IN(1:jpi,jj,jk,jl,jf) |
---|
85 | END DO |
---|
86 | END DO |
---|
87 | END DO |
---|
88 | END DO |
---|
89 | ! |
---|
90 | ! |
---|
91 | itaille = jpimax * ipj * ipk * ipl * ipf |
---|
92 | ! |
---|
93 | IF( l_north_nogather ) THEN !== ???? ==! |
---|
94 | ALLOCATE( zfoldwk(jpimax,4,ipk,ipl,ipf) ) |
---|
95 | ALLOCATE( ztabl(jpimax ,4,ipk,ipl,ipf) , ztabr(jpimax*jpmaxngh,4,ipk,ipl,ipf) ) |
---|
96 | ! |
---|
97 | ztabr(:,:,:,:,:) = 0._wp |
---|
98 | ztabl(:,:,:,:,:) = 0._wp |
---|
99 | ! |
---|
100 | DO jf = 1, ipf |
---|
101 | DO jl = 1, ipl |
---|
102 | DO jk = 1, ipk |
---|
103 | DO jj = nlcj-ipj+1, nlcj ! First put local values into the global array |
---|
104 | ij = jj - nlcj + ipj |
---|
105 | DO ji = nfsloop, nfeloop |
---|
106 | ztabl(ji,ij,jk,jl,jf) = ARRAY_IN(ji,jj,jk,jl,jf) |
---|
107 | END DO |
---|
108 | END DO |
---|
109 | END DO |
---|
110 | END DO |
---|
111 | END DO |
---|
112 | ! |
---|
113 | DO jr = 1, nsndto |
---|
114 | IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN |
---|
115 | CALL mppsend( 5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) ) |
---|
116 | ENDIF |
---|
117 | END DO |
---|
118 | DO jr = 1,nsndto |
---|
119 | iproc = nfipproc(isendto(jr),jpnj) |
---|
120 | IF(iproc /= -1) THEN |
---|
121 | iilb = nimppt(iproc+1) |
---|
122 | ilci = nlcit (iproc+1) |
---|
123 | ildi = nldit (iproc+1) |
---|
124 | ilei = nleit (iproc+1) |
---|
125 | IF( iilb == 1 ) ildi = 1 ! e-w boundary already done -> force to take 1st column |
---|
126 | IF( iilb + ilci - 1 == jpiglo ) ilei = ilci ! e-w boundary already done -> force to take last column |
---|
127 | iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj) |
---|
128 | ENDIF |
---|
129 | IF( iproc /= narea-1 .AND. iproc /= -1 ) THEN |
---|
130 | CALL mpprecv(5, zfoldwk, itaille, iproc) |
---|
131 | DO jf = 1, ipf |
---|
132 | DO jl = 1, ipl |
---|
133 | DO jk = 1, ipk |
---|
134 | DO jj = 1, ipj |
---|
135 | DO ji = ildi, ilei |
---|
136 | ztabr(iilb+ji,jj,jk,jl,jf) = zfoldwk(ji,jj,jk,jl,jf) |
---|
137 | END DO |
---|
138 | END DO |
---|
139 | END DO |
---|
140 | END DO |
---|
141 | END DO |
---|
142 | ELSE IF( iproc == narea-1 ) THEN |
---|
143 | DO jf = 1, ipf |
---|
144 | DO jl = 1, ipl |
---|
145 | DO jk = 1, ipk |
---|
146 | DO jj = 1, ipj |
---|
147 | DO ji = ildi, ilei |
---|
148 | ztabr(iilb+ji,jj,jk,jl,jf) = ARRAY_IN(ji,nlcj-ipj+jj,jk,jl,jf) |
---|
149 | END DO |
---|
150 | END DO |
---|
151 | END DO |
---|
152 | END DO |
---|
153 | END DO |
---|
154 | ENDIF |
---|
155 | END DO |
---|
156 | IF( l_isend ) THEN |
---|
157 | DO jr = 1,nsndto |
---|
158 | IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN |
---|
159 | CALL mpi_wait( ml_req_nf(jr), ml_stat, ml_err ) |
---|
160 | ENDIF |
---|
161 | END DO |
---|
162 | ENDIF |
---|
163 | DO jf = 1, ipf |
---|
164 | CALL lbc_nfd_nogather( ztabl(:,:,:,:,jf), ztabr(:,:,:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG ) ! North fold boundary condition |
---|
165 | END DO |
---|
166 | DO jf = 1, ipf |
---|
167 | DO jl = 1, ipl |
---|
168 | DO jk = 1, ipk |
---|
169 | DO jj = nlcj-ipj+1, nlcj ! Scatter back to ARRAY_IN |
---|
170 | ij = jj - nlcj + ipj |
---|
171 | DO ji= 1, nlci |
---|
172 | ARRAY_IN(ji,jj,jk,jl,jf) = ztabl(ji,ij,jk,jl,jf) |
---|
173 | END DO |
---|
174 | END DO |
---|
175 | END DO |
---|
176 | END DO |
---|
177 | END DO |
---|
178 | ! |
---|
179 | DEALLOCATE( zfoldwk ) |
---|
180 | DEALLOCATE( ztabl, ztabr ) |
---|
181 | ELSE !== ???? ==! |
---|
182 | ALLOCATE( ztab (jpiglo,4,ipk,ipl,ipf ) ) |
---|
183 | ALLOCATE( znorthgloio(jpimax,4,ipk,ipl,ipf,jpni) ) |
---|
184 | ! |
---|
185 | ztab(:,:,:,:,:)=0._wp |
---|
186 | ! |
---|
187 | CALL MPI_ALLGATHER( znorthloc , itaille, MPI_DOUBLE_PRECISION, & |
---|
188 | & znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr ) |
---|
189 | ! |
---|
190 | DO jr = 1, ndim_rank_north ! recover the global north array |
---|
191 | iproc = nrank_north(jr) + 1 |
---|
192 | iilb = nimppt(iproc) |
---|
193 | ilci = nlcit (iproc) |
---|
194 | ildi = nldit (iproc) |
---|
195 | ilei = nleit (iproc) |
---|
196 | IF( iilb == 1 ) ildi = 1 ! e-w boundary already done -> force to take 1st column |
---|
197 | IF( iilb + ilci - 1 == jpiglo ) ilei = ilci ! e-w boundary already done -> force to take last column |
---|
198 | DO jf = 1, ipf |
---|
199 | DO jl = 1, ipl |
---|
200 | DO jk = 1, ipk |
---|
201 | DO jj = 1, ipj |
---|
202 | DO ji = ildi, ilei |
---|
203 | ztab(ji+iilb-1,jj,jk,jl,jf) = znorthgloio(ji,jj,jk,jl,jf,jr) |
---|
204 | END DO |
---|
205 | END DO |
---|
206 | END DO |
---|
207 | END DO |
---|
208 | END DO |
---|
209 | END DO |
---|
210 | DO jf = 1, ipf |
---|
211 | CALL lbc_nfd( ztab(:,:,:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG ) ! North fold boundary condition |
---|
212 | END DO |
---|
213 | ! |
---|
214 | DO jf = 1, ipf |
---|
215 | DO jl = 1, ipl |
---|
216 | DO jk = 1, ipk |
---|
217 | DO jj = nlcj-ipj+1, nlcj ! Scatter back to ARRAY_IN |
---|
218 | ij = jj - nlcj + ipj |
---|
219 | DO ji= 1, nlci |
---|
220 | ARRAY_IN(ji,jj,jk,jl,jf) = ztab(ji+nimpp-1,ij,jk,jl,jf) |
---|
221 | END DO |
---|
222 | END DO |
---|
223 | END DO |
---|
224 | END DO |
---|
225 | END DO |
---|
226 | ! |
---|
227 | ! |
---|
228 | DEALLOCATE( ztab ) |
---|
229 | DEALLOCATE( znorthgloio ) |
---|
230 | ENDIF |
---|
231 | ! |
---|
232 | DEALLOCATE( znorthloc ) |
---|
233 | ! |
---|
234 | END SUBROUTINE ROUTINE_NFD |
---|
235 | |
---|
236 | #undef ARRAY_TYPE |
---|
237 | #undef NAT_IN |
---|
238 | #undef SGN_IN |
---|
239 | #undef ARRAY_IN |
---|
240 | #undef K_SIZE |
---|
241 | #undef L_SIZE |
---|
242 | #undef F_SIZE |
---|
243 | #undef LBC_ARG |
---|