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