[10727] | 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 | !!!!!!!!! needed to get the same results without agrif and with agrif and no zoom !!!!!!!! |
---|
| 94 | !!!!!!!!! I don't know why we must do that... !!!!!!!! |
---|
| 95 | l_full_nf_update = .TRUE. |
---|
| 96 | |
---|
[13145] | 97 | ipj_s(:) = 2 |
---|
[10727] | 98 | |
---|
| 99 | ! Index of modifying lines in input |
---|
| 100 | DO jf = 1, ipf ! Loop over the number of arrays to be processed |
---|
| 101 | ! |
---|
| 102 | SELECT CASE ( npolj ) |
---|
| 103 | ! |
---|
| 104 | CASE ( 3, 4 ) ! * North fold T-point pivot |
---|
| 105 | ! |
---|
| 106 | SELECT CASE ( NAT_IN(jf) ) |
---|
| 107 | ! |
---|
| 108 | CASE ( 'T' , 'W' ,'U' ) ! T-, U-, W-point |
---|
| 109 | jj_s(jf,1) = nlcj - 2 ; jj_s(jf,2) = nlcj - 1 |
---|
| 110 | CASE ( 'V' , 'F' ) ! V-, F-point |
---|
| 111 | jj_s(jf,1) = nlcj - 3 ; jj_s(jf,2) = nlcj - 2 |
---|
| 112 | END SELECT |
---|
| 113 | ! |
---|
| 114 | CASE ( 5, 6 ) ! * North fold F-point pivot |
---|
| 115 | SELECT CASE ( NAT_IN(jf) ) |
---|
| 116 | ! |
---|
| 117 | CASE ( 'T' , 'W' ,'U' ) ! T-, U-, W-point |
---|
| 118 | jj_s(jf,1) = nlcj - 1 |
---|
| 119 | ipj_s(jf) = 1 ! need only one line anyway |
---|
| 120 | CASE ( 'V' , 'F' ) ! V-, F-point |
---|
| 121 | jj_s(jf,1) = nlcj - 2 ; jj_s(jf,2) = nlcj - 1 |
---|
| 122 | END SELECT |
---|
| 123 | ! |
---|
| 124 | END SELECT |
---|
| 125 | ! |
---|
| 126 | ENDDO |
---|
| 127 | ! |
---|
| 128 | ipf_j = sum (ipj_s(:)) ! Total number of lines to be exchanged |
---|
| 129 | ! |
---|
| 130 | ALLOCATE( znorthloc(jpimax,ipf_j,ipk,ipl,1) ) |
---|
| 131 | ! |
---|
| 132 | js = 0 |
---|
| 133 | DO jf = 1, ipf ! Loop over the number of arrays to be processed |
---|
| 134 | DO jj = 1, ipj_s(jf) |
---|
| 135 | js = js + 1 |
---|
| 136 | DO jl = 1, ipl |
---|
| 137 | DO jk = 1, ipk |
---|
| 138 | znorthloc(1:jpi,js,jk,jl,1) = ARRAY_IN(1:jpi,jj_s(jf,jj),jk,jl,jf) |
---|
| 139 | END DO |
---|
| 140 | END DO |
---|
| 141 | END DO |
---|
| 142 | END DO |
---|
| 143 | ! |
---|
| 144 | ibuffsize = jpimax * ipf_j * ipk * ipl |
---|
| 145 | ! |
---|
| 146 | ALLOCATE( zfoldwk(jpimax,ipf_j,ipk,ipl,1) ) |
---|
| 147 | ALLOCATE( ztabr(jpimax*jpmaxngh,ipj,ipk,ipl,ipf) ) |
---|
| 148 | ! when some processors of the north fold are suppressed, |
---|
| 149 | ! values of ztab* arrays corresponding to these suppressed domain won't be defined |
---|
| 150 | ! and we need a default definition to 0. |
---|
| 151 | ! a better test should be: a testing if "suppressed land-processors" belongs to the north-pole folding |
---|
| 152 | IF ( jpni*jpnj /= jpnij ) ztabr(:,:,:,:,:) = 0._wp |
---|
| 153 | ! |
---|
| 154 | DO jr = 1, nsndto |
---|
| 155 | IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN |
---|
| 156 | CALL mppsend( 5, znorthloc, ibuffsize, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) ) |
---|
| 157 | ENDIF |
---|
| 158 | END DO |
---|
| 159 | ! |
---|
| 160 | DO jr = 1,nsndto |
---|
| 161 | iproc = nfipproc(isendto(jr),jpnj) |
---|
| 162 | IF(iproc /= -1) THEN |
---|
| 163 | iilb = nimppt(iproc+1) |
---|
| 164 | ilci = nlcit (iproc+1) |
---|
| 165 | ildi = nldit (iproc+1) |
---|
| 166 | ilei = nleit (iproc+1) |
---|
| 167 | IF( iilb == 1 ) ildi = 1 ! e-w boundary already done -> force to take 1st column |
---|
| 168 | IF( iilb + ilci - 1 == jpiglo ) ilei = ilci ! e-w boundary already done -> force to take last column |
---|
| 169 | iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj) |
---|
| 170 | ENDIF |
---|
| 171 | IF( iproc /= narea-1 .AND. iproc /= -1 ) THEN |
---|
| 172 | CALL mpprecv(5, zfoldwk, ibuffsize, iproc) |
---|
| 173 | js = 0 |
---|
| 174 | DO jf = 1, ipf ; DO jj = 1, ipj_s(jf) |
---|
| 175 | js = js + 1 |
---|
| 176 | DO jl = 1, ipl |
---|
| 177 | DO jk = 1, ipk |
---|
| 178 | DO ji = ildi, ilei |
---|
| 179 | ztabr(iilb+ji,jj,jk,jl,jf) = zfoldwk(ji,js,jk,jl,1) |
---|
| 180 | END DO |
---|
| 181 | END DO |
---|
| 182 | END DO |
---|
| 183 | END DO; END DO |
---|
| 184 | ELSE IF( iproc == narea-1 ) THEN |
---|
| 185 | DO jf = 1, ipf ; DO jj = 1, ipj_s(jf) |
---|
| 186 | DO jl = 1, ipl |
---|
| 187 | DO jk = 1, ipk |
---|
| 188 | DO ji = ildi, ilei |
---|
| 189 | ztabr(iilb+ji,jj,jk,jl,jf) = ARRAY_IN(ji,jj_s(jf,jj),jk,jl,jf) |
---|
| 190 | END DO |
---|
| 191 | END DO |
---|
| 192 | END DO |
---|
| 193 | END DO; END DO |
---|
| 194 | ENDIF |
---|
| 195 | END DO |
---|
| 196 | IF( l_isend ) THEN |
---|
| 197 | DO jr = 1,nsndto |
---|
| 198 | IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN |
---|
| 199 | CALL mpi_wait( ml_req_nf(jr), ml_stat, ml_err ) |
---|
| 200 | ENDIF |
---|
| 201 | END DO |
---|
| 202 | ENDIF |
---|
| 203 | ! |
---|
| 204 | ! North fold boundary condition |
---|
| 205 | ! |
---|
| 206 | DO jf = 1, ipf |
---|
| 207 | CALL lbc_nfd_nogather(ARRAY_IN(:,:,:,:,jf), ztabr(:,1:ipj_s(jf),:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG ) |
---|
| 208 | END DO |
---|
| 209 | ! |
---|
| 210 | DEALLOCATE( zfoldwk ) |
---|
| 211 | DEALLOCATE( ztabr ) |
---|
| 212 | DEALLOCATE( jj_s ) |
---|
| 213 | DEALLOCATE( ipj_s ) |
---|
| 214 | ELSE !== ???? ==! |
---|
| 215 | ! |
---|
| 216 | ipj = 4 ! 2nd dimension of message transfers (last j-lines) |
---|
| 217 | ! |
---|
| 218 | ALLOCATE( znorthloc(jpimax,ipj,ipk,ipl,ipf) ) |
---|
| 219 | ! |
---|
| 220 | DO jf = 1, ipf ! put in znorthloc the last ipj j-lines of ptab |
---|
| 221 | DO jl = 1, ipl |
---|
| 222 | DO jk = 1, ipk |
---|
| 223 | DO jj = nlcj - ipj +1, nlcj |
---|
| 224 | ij = jj - nlcj + ipj |
---|
| 225 | znorthloc(1:jpi,ij,jk,jl,jf) = ARRAY_IN(1:jpi,jj,jk,jl,jf) |
---|
| 226 | END DO |
---|
| 227 | END DO |
---|
| 228 | END DO |
---|
| 229 | END DO |
---|
| 230 | ! |
---|
| 231 | ibuffsize = jpimax * ipj * ipk * ipl * ipf |
---|
| 232 | ! |
---|
| 233 | ALLOCATE( ztab (jpiglo,ipj,ipk,ipl,ipf ) ) |
---|
| 234 | ALLOCATE( znorthgloio(jpimax,ipj,ipk,ipl,ipf,jpni) ) |
---|
| 235 | ! |
---|
| 236 | ! when some processors of the north fold are suppressed, |
---|
| 237 | ! values of ztab* arrays corresponding to these suppressed domain won't be defined |
---|
| 238 | ! and we need a default definition to 0. |
---|
| 239 | ! a better test should be: a testing if "suppressed land-processors" belongs to the north-pole folding |
---|
| 240 | IF ( jpni*jpnj /= jpnij ) ztab(:,:,:,:,:) = 0._wp |
---|
| 241 | ! |
---|
| 242 | CALL MPI_ALLGATHER( znorthloc , ibuffsize, MPI_DOUBLE_PRECISION, & |
---|
| 243 | & znorthgloio, ibuffsize, MPI_DOUBLE_PRECISION, ncomm_north, ierr ) |
---|
| 244 | ! |
---|
| 245 | ! |
---|
| 246 | DO jr = 1, ndim_rank_north ! recover the global north array |
---|
| 247 | iproc = nrank_north(jr) + 1 |
---|
| 248 | iilb = nimppt(iproc) |
---|
| 249 | ilci = nlcit (iproc) |
---|
| 250 | ildi = nldit (iproc) |
---|
| 251 | ilei = nleit (iproc) |
---|
| 252 | IF( iilb == 1 ) ildi = 1 ! e-w boundary already done -> force to take 1st column |
---|
| 253 | IF( iilb + ilci - 1 == jpiglo ) ilei = ilci ! e-w boundary already done -> force to take last column |
---|
| 254 | DO jf = 1, ipf |
---|
| 255 | DO jl = 1, ipl |
---|
| 256 | DO jk = 1, ipk |
---|
| 257 | DO jj = 1, ipj |
---|
| 258 | DO ji = ildi, ilei |
---|
| 259 | ztab(ji+iilb-1,jj,jk,jl,jf) = znorthgloio(ji,jj,jk,jl,jf,jr) |
---|
| 260 | END DO |
---|
| 261 | END DO |
---|
| 262 | END DO |
---|
| 263 | END DO |
---|
| 264 | END DO |
---|
| 265 | END DO |
---|
| 266 | DO jf = 1, ipf |
---|
| 267 | CALL lbc_nfd( ztab(:,:,:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG ) ! North fold boundary condition |
---|
| 268 | END DO |
---|
| 269 | ! |
---|
| 270 | DO jf = 1, ipf |
---|
| 271 | DO jl = 1, ipl |
---|
| 272 | DO jk = 1, ipk |
---|
| 273 | DO jj = nlcj-ipj+1, nlcj ! Scatter back to ARRAY_IN |
---|
| 274 | ij = jj - nlcj + ipj |
---|
| 275 | DO ji= 1, nlci |
---|
| 276 | ARRAY_IN(ji,jj,jk,jl,jf) = ztab(ji+nimpp-1,ij,jk,jl,jf) |
---|
| 277 | END DO |
---|
| 278 | END DO |
---|
| 279 | END DO |
---|
| 280 | END DO |
---|
| 281 | END DO |
---|
| 282 | ! |
---|
| 283 | ! |
---|
| 284 | DEALLOCATE( ztab ) |
---|
| 285 | DEALLOCATE( znorthgloio ) |
---|
| 286 | ENDIF |
---|
| 287 | ! |
---|
| 288 | DEALLOCATE( znorthloc ) |
---|
| 289 | ! |
---|
| 290 | END SUBROUTINE ROUTINE_NFD |
---|
| 291 | |
---|
| 292 | #undef ARRAY_TYPE |
---|
| 293 | #undef NAT_IN |
---|
| 294 | #undef SGN_IN |
---|
| 295 | #undef ARRAY_IN |
---|
| 296 | #undef K_SIZE |
---|
| 297 | #undef L_SIZE |
---|
| 298 | #undef F_SIZE |
---|
| 299 | #undef LBC_ARG |
---|