[1] | 1 | SUBROUTINE init_pegrid |
---|
| 2 | |
---|
| 3 | !------------------------------------------------------------------------------! |
---|
[254] | 4 | ! Current revisions: |
---|
[1] | 5 | ! ----------------- |
---|
[623] | 6 | ! |
---|
[181] | 7 | ! ATTENTION: nnz_x undefined problem still has to be solved!!!!!!!! |
---|
[108] | 8 | ! TEST OUTPUT (TO BE REMOVED) logging mpi2 ierr values |
---|
[77] | 9 | ! |
---|
| 10 | ! Former revisions: |
---|
| 11 | ! ----------------- |
---|
| 12 | ! $Id: init_pegrid.f90 623 2010-12-10 08:52:17Z heinze $ |
---|
[623] | 13 | ! |
---|
| 14 | ! 622 2010-12-10 08:08:13Z raasch |
---|
| 15 | ! optional barriers included in order to speed up collective operations |
---|
| 16 | ! |
---|
[482] | 17 | ! 438 2010-02-01 04:32:43Z raasch |
---|
| 18 | ! 2d-decomposition is default for Cray-XT machines |
---|
[77] | 19 | ! |
---|
[392] | 20 | ! 274 2009-03-26 15:11:21Z heinze |
---|
| 21 | ! Output of messages replaced by message handling routine. |
---|
| 22 | ! |
---|
[226] | 23 | ! 206 2008-10-13 14:59:11Z raasch |
---|
| 24 | ! Implementation of a MPI-1 coupling: added __parallel within the __mpi2 part |
---|
| 25 | ! 2d-decomposition is default on SGI-ICE systems |
---|
| 26 | ! |
---|
[198] | 27 | ! 197 2008-09-16 15:29:03Z raasch |
---|
| 28 | ! multigrid levels are limited by subdomains if mg_switch_to_pe0_level = -1, |
---|
| 29 | ! nz is used instead nnz for calculating mg-levels |
---|
| 30 | ! Collect on PE0 horizontal index bounds from all other PEs, |
---|
| 31 | ! broadcast the id of the inflow PE (using the respective communicator) |
---|
| 32 | ! |
---|
[139] | 33 | ! 114 2007-10-10 00:03:15Z raasch |
---|
| 34 | ! Allocation of wall flag arrays for multigrid solver |
---|
| 35 | ! |
---|
[110] | 36 | ! 108 2007-08-24 15:10:38Z letzel |
---|
| 37 | ! Intercommunicator (comm_inter) and derived data type (type_xy) for |
---|
| 38 | ! coupled model runs created, assign coupling_mode_remote, |
---|
| 39 | ! indices nxlu and nysv are calculated (needed for non-cyclic boundary |
---|
| 40 | ! conditions) |
---|
| 41 | ! |
---|
[83] | 42 | ! 82 2007-04-16 15:40:52Z raasch |
---|
| 43 | ! Cpp-directive lcmuk changed to intel_openmp_bug, setting of host on lcmuk by |
---|
| 44 | ! cpp-directive removed |
---|
| 45 | ! |
---|
[77] | 46 | ! 75 2007-03-22 09:54:05Z raasch |
---|
[73] | 47 | ! uxrp, vynp eliminated, |
---|
[75] | 48 | ! dirichlet/neumann changed to dirichlet/radiation, etc., |
---|
| 49 | ! poisfft_init is only called if fft-solver is switched on |
---|
[1] | 50 | ! |
---|
[3] | 51 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 52 | ! |
---|
[1] | 53 | ! Revision 1.28 2006/04/26 13:23:32 raasch |
---|
| 54 | ! lcmuk does not understand the !$ comment so a cpp-directive is required |
---|
| 55 | ! |
---|
| 56 | ! Revision 1.1 1997/07/24 11:15:09 raasch |
---|
| 57 | ! Initial revision |
---|
| 58 | ! |
---|
| 59 | ! |
---|
| 60 | ! Description: |
---|
| 61 | ! ------------ |
---|
| 62 | ! Determination of the virtual processor topology (if not prescribed by the |
---|
| 63 | ! user)and computation of the grid point number and array bounds of the local |
---|
| 64 | ! domains. |
---|
| 65 | !------------------------------------------------------------------------------! |
---|
| 66 | |
---|
| 67 | USE control_parameters |
---|
| 68 | USE fft_xy |
---|
[163] | 69 | USE grid_variables |
---|
[1] | 70 | USE indices |
---|
| 71 | USE pegrid |
---|
| 72 | USE poisfft_mod |
---|
| 73 | USE poisfft_hybrid_mod |
---|
| 74 | USE statistics |
---|
| 75 | USE transpose_indices |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | IMPLICIT NONE |
---|
| 79 | |
---|
[163] | 80 | INTEGER :: gathered_size, i, id_inflow_l, id_recycling_l, ind(5), j, k, & |
---|
[151] | 81 | maximum_grid_level_l, mg_switch_to_pe0_level_l, mg_levels_x, & |
---|
| 82 | mg_levels_y, mg_levels_z, nnx_y, nnx_z, nny_x, nny_z, nnz_x, & |
---|
| 83 | nnz_y, numproc_sqr, nx_total, nxl_l, nxr_l, nyn_l, nys_l, & |
---|
| 84 | nzb_l, nzt_l, omp_get_num_threads, subdomain_size |
---|
[1] | 85 | |
---|
| 86 | INTEGER, DIMENSION(:), ALLOCATABLE :: ind_all, nxlf, nxrf, nynf, nysf |
---|
| 87 | |
---|
| 88 | LOGICAL :: found |
---|
| 89 | |
---|
| 90 | ! |
---|
| 91 | !-- Get the number of OpenMP threads |
---|
| 92 | !$OMP PARALLEL |
---|
[82] | 93 | #if defined( __intel_openmp_bug ) |
---|
[1] | 94 | threads_per_task = omp_get_num_threads() |
---|
| 95 | #else |
---|
| 96 | !$ threads_per_task = omp_get_num_threads() |
---|
| 97 | #endif |
---|
| 98 | !$OMP END PARALLEL |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | #if defined( __parallel ) |
---|
| 102 | ! |
---|
| 103 | !-- Determine the processor topology or check it, if prescribed by the user |
---|
| 104 | IF ( npex == -1 .AND. npey == -1 ) THEN |
---|
| 105 | |
---|
| 106 | ! |
---|
| 107 | !-- Automatic determination of the topology |
---|
| 108 | !-- The default on SMP- and cluster-hosts is a 1d-decomposition along x |
---|
[206] | 109 | IF ( host(1:3) == 'ibm' .OR. host(1:3) == 'nec' .OR. & |
---|
[438] | 110 | ( host(1:2) == 'lc' .AND. host(3:5) /= 'sgi' .AND. & |
---|
| 111 | host(3:4) /= 'xt' ) .OR. & |
---|
[206] | 112 | host(1:3) == 'dec' ) THEN |
---|
[1] | 113 | |
---|
| 114 | pdims(1) = numprocs |
---|
| 115 | pdims(2) = 1 |
---|
| 116 | |
---|
| 117 | ELSE |
---|
| 118 | |
---|
| 119 | numproc_sqr = SQRT( REAL( numprocs ) ) |
---|
| 120 | pdims(1) = MAX( numproc_sqr , 1 ) |
---|
| 121 | DO WHILE ( MOD( numprocs , pdims(1) ) /= 0 ) |
---|
| 122 | pdims(1) = pdims(1) - 1 |
---|
| 123 | ENDDO |
---|
| 124 | pdims(2) = numprocs / pdims(1) |
---|
| 125 | |
---|
| 126 | ENDIF |
---|
| 127 | |
---|
| 128 | ELSEIF ( npex /= -1 .AND. npey /= -1 ) THEN |
---|
| 129 | |
---|
| 130 | ! |
---|
| 131 | !-- Prescribed by user. Number of processors on the prescribed topology |
---|
| 132 | !-- must be equal to the number of PEs available to the job |
---|
| 133 | IF ( ( npex * npey ) /= numprocs ) THEN |
---|
[274] | 134 | WRITE( message_string, * ) 'number of PEs of the prescribed ', & |
---|
| 135 | 'topology (', npex*npey,') does not match & the number of ', & |
---|
| 136 | 'PEs available to the job (', numprocs, ')' |
---|
[254] | 137 | CALL message( 'init_pegrid', 'PA0221', 1, 2, 0, 6, 0 ) |
---|
[1] | 138 | ENDIF |
---|
| 139 | pdims(1) = npex |
---|
| 140 | pdims(2) = npey |
---|
| 141 | |
---|
| 142 | ELSE |
---|
| 143 | ! |
---|
| 144 | !-- If the processor topology is prescribed by the user, the number of |
---|
| 145 | !-- PEs must be given in both directions |
---|
[274] | 146 | message_string = 'if the processor topology is prescribed by the, ' // & |
---|
| 147 | ' user& both values of "npex" and "npey" must be given ' // & |
---|
| 148 | 'in the &NAMELIST-parameter file' |
---|
[254] | 149 | CALL message( 'init_pegrid', 'PA0222', 1, 2, 0, 6, 0 ) |
---|
[1] | 150 | |
---|
| 151 | ENDIF |
---|
| 152 | |
---|
| 153 | ! |
---|
| 154 | !-- The hybrid solver can only be used in case of a 1d-decomposition along x |
---|
| 155 | IF ( pdims(2) /= 1 .AND. psolver == 'poisfft_hybrid' ) THEN |
---|
[254] | 156 | message_string = 'psolver = "poisfft_hybrid" can only be' // & |
---|
| 157 | '& used in case of a 1d-decomposition along x' |
---|
| 158 | CALL message( 'init_pegrid', 'PA0223', 1, 2, 0, 6, 0 ) |
---|
[1] | 159 | ENDIF |
---|
| 160 | |
---|
| 161 | ! |
---|
[622] | 162 | !-- For communication speedup, set barriers in front of collective |
---|
| 163 | !-- communications by default on SGI-type systems |
---|
| 164 | IF ( host(3:5) == 'sgi' ) collective_wait = .TRUE. |
---|
| 165 | |
---|
| 166 | ! |
---|
[1] | 167 | !-- If necessary, set horizontal boundary conditions to non-cyclic |
---|
| 168 | IF ( bc_lr /= 'cyclic' ) cyclic(1) = .FALSE. |
---|
| 169 | IF ( bc_ns /= 'cyclic' ) cyclic(2) = .FALSE. |
---|
| 170 | |
---|
| 171 | ! |
---|
| 172 | !-- Create the virtual processor grid |
---|
| 173 | CALL MPI_CART_CREATE( comm_palm, ndim, pdims, cyclic, reorder, & |
---|
| 174 | comm2d, ierr ) |
---|
| 175 | CALL MPI_COMM_RANK( comm2d, myid, ierr ) |
---|
| 176 | WRITE (myid_char,'(''_'',I4.4)') myid |
---|
| 177 | |
---|
| 178 | CALL MPI_CART_COORDS( comm2d, myid, ndim, pcoord, ierr ) |
---|
| 179 | CALL MPI_CART_SHIFT( comm2d, 0, 1, pleft, pright, ierr ) |
---|
| 180 | CALL MPI_CART_SHIFT( comm2d, 1, 1, psouth, pnorth, ierr ) |
---|
| 181 | |
---|
| 182 | ! |
---|
| 183 | !-- Determine sub-topologies for transpositions |
---|
| 184 | !-- Transposition from z to x: |
---|
| 185 | remain_dims(1) = .TRUE. |
---|
| 186 | remain_dims(2) = .FALSE. |
---|
| 187 | CALL MPI_CART_SUB( comm2d, remain_dims, comm1dx, ierr ) |
---|
| 188 | CALL MPI_COMM_RANK( comm1dx, myidx, ierr ) |
---|
| 189 | ! |
---|
| 190 | !-- Transposition from x to y |
---|
| 191 | remain_dims(1) = .FALSE. |
---|
| 192 | remain_dims(2) = .TRUE. |
---|
| 193 | CALL MPI_CART_SUB( comm2d, remain_dims, comm1dy, ierr ) |
---|
| 194 | CALL MPI_COMM_RANK( comm1dy, myidy, ierr ) |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | ! |
---|
| 198 | !-- Find a grid (used for array d) which will match the transposition demands |
---|
| 199 | IF ( grid_matching == 'strict' ) THEN |
---|
| 200 | |
---|
| 201 | nxa = nx; nya = ny; nza = nz |
---|
| 202 | |
---|
| 203 | ELSE |
---|
| 204 | |
---|
| 205 | found = .FALSE. |
---|
| 206 | xn: DO nxa = nx, 2*nx |
---|
| 207 | ! |
---|
| 208 | !-- Meet conditions for nx |
---|
| 209 | IF ( MOD( nxa+1, pdims(1) ) /= 0 .OR. & |
---|
| 210 | MOD( nxa+1, pdims(2) ) /= 0 ) CYCLE xn |
---|
| 211 | |
---|
| 212 | yn: DO nya = ny, 2*ny |
---|
| 213 | ! |
---|
| 214 | !-- Meet conditions for ny |
---|
| 215 | IF ( MOD( nya+1, pdims(2) ) /= 0 .OR. & |
---|
| 216 | MOD( nya+1, pdims(1) ) /= 0 ) CYCLE yn |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | zn: DO nza = nz, 2*nz |
---|
| 220 | ! |
---|
| 221 | !-- Meet conditions for nz |
---|
| 222 | IF ( ( MOD( nza, pdims(1) ) /= 0 .AND. pdims(1) /= 1 .AND. & |
---|
| 223 | pdims(2) /= 1 ) .OR. & |
---|
| 224 | ( MOD( nza, pdims(2) ) /= 0 .AND. dt_dosp /= 9999999.9 & |
---|
| 225 | ) ) THEN |
---|
| 226 | CYCLE zn |
---|
| 227 | ELSE |
---|
| 228 | found = .TRUE. |
---|
| 229 | EXIT xn |
---|
| 230 | ENDIF |
---|
| 231 | |
---|
| 232 | ENDDO zn |
---|
| 233 | |
---|
| 234 | ENDDO yn |
---|
| 235 | |
---|
| 236 | ENDDO xn |
---|
| 237 | |
---|
| 238 | IF ( .NOT. found ) THEN |
---|
[254] | 239 | message_string = 'no matching grid for transpositions found' |
---|
| 240 | CALL message( 'init_pegrid', 'PA0224', 1, 2, 0, 6, 0 ) |
---|
[1] | 241 | ENDIF |
---|
| 242 | |
---|
| 243 | ENDIF |
---|
| 244 | |
---|
| 245 | ! |
---|
| 246 | !-- Calculate array bounds in x-direction for every PE. |
---|
| 247 | !-- The last PE along x may get less grid points than the others |
---|
| 248 | ALLOCATE( nxlf(0:pdims(1)-1), nxrf(0:pdims(1)-1), nynf(0:pdims(2)-1), & |
---|
| 249 | nysf(0:pdims(2)-1), nnx_pe(0:pdims(1)-1), nny_pe(0:pdims(2)-1) ) |
---|
| 250 | |
---|
| 251 | IF ( MOD( nxa+1 , pdims(1) ) /= 0 ) THEN |
---|
[274] | 252 | WRITE( message_string, * ) 'x-direction: gridpoint number (',nx+1,') ',& |
---|
| 253 | 'is not an& integral divisor of the number ', & |
---|
| 254 | 'processors (', pdims(1),')' |
---|
[254] | 255 | CALL message( 'init_pegrid', 'PA0225', 1, 2, 0, 6, 0 ) |
---|
[1] | 256 | ELSE |
---|
| 257 | nnx = ( nxa + 1 ) / pdims(1) |
---|
| 258 | IF ( nnx*pdims(1) - ( nx + 1) > nnx ) THEN |
---|
[274] | 259 | WRITE( message_string, * ) 'x-direction: nx does not match the', & |
---|
| 260 | 'requirements given by the number of PEs &used', & |
---|
| 261 | '& please use nx = ', nx - ( pdims(1) - ( nnx*pdims(1) & |
---|
| 262 | - ( nx + 1 ) ) ), ' instead of nx =', nx |
---|
[254] | 263 | CALL message( 'init_pegrid', 'PA0226', 1, 2, 0, 6, 0 ) |
---|
[1] | 264 | ENDIF |
---|
| 265 | ENDIF |
---|
| 266 | |
---|
| 267 | ! |
---|
| 268 | !-- Left and right array bounds, number of gridpoints |
---|
| 269 | DO i = 0, pdims(1)-1 |
---|
| 270 | nxlf(i) = i * nnx |
---|
| 271 | nxrf(i) = ( i + 1 ) * nnx - 1 |
---|
| 272 | nnx_pe(i) = MIN( nx, nxrf(i) ) - nxlf(i) + 1 |
---|
| 273 | ENDDO |
---|
| 274 | |
---|
| 275 | ! |
---|
| 276 | !-- Calculate array bounds in y-direction for every PE. |
---|
| 277 | IF ( MOD( nya+1 , pdims(2) ) /= 0 ) THEN |
---|
[274] | 278 | WRITE( message_string, * ) 'y-direction: gridpoint number (',ny+1,') ', & |
---|
| 279 | 'is not an& integral divisor of the number of', & |
---|
| 280 | 'processors (', pdims(2),')' |
---|
[254] | 281 | CALL message( 'init_pegrid', 'PA0227', 1, 2, 0, 6, 0 ) |
---|
[1] | 282 | ELSE |
---|
| 283 | nny = ( nya + 1 ) / pdims(2) |
---|
| 284 | IF ( nny*pdims(2) - ( ny + 1) > nny ) THEN |
---|
[274] | 285 | WRITE( message_string, * ) 'y-direction: ny does not match the', & |
---|
| 286 | 'requirements given by the number of PEs &used ', & |
---|
| 287 | '& please use ny = ', ny - ( pdims(2) - ( nnx*pdims(2) & |
---|
[254] | 288 | - ( ny + 1 ) ) ), ' instead of ny =', ny |
---|
| 289 | CALL message( 'init_pegrid', 'PA0228', 1, 2, 0, 6, 0 ) |
---|
[1] | 290 | ENDIF |
---|
| 291 | ENDIF |
---|
| 292 | |
---|
| 293 | ! |
---|
| 294 | !-- South and north array bounds |
---|
| 295 | DO j = 0, pdims(2)-1 |
---|
| 296 | nysf(j) = j * nny |
---|
| 297 | nynf(j) = ( j + 1 ) * nny - 1 |
---|
| 298 | nny_pe(j) = MIN( ny, nynf(j) ) - nysf(j) + 1 |
---|
| 299 | ENDDO |
---|
| 300 | |
---|
| 301 | ! |
---|
| 302 | !-- Local array bounds of the respective PEs |
---|
| 303 | nxl = nxlf(pcoord(1)) |
---|
| 304 | nxra = nxrf(pcoord(1)) |
---|
| 305 | nxr = MIN( nx, nxra ) |
---|
| 306 | nys = nysf(pcoord(2)) |
---|
| 307 | nyna = nynf(pcoord(2)) |
---|
| 308 | nyn = MIN( ny, nyna ) |
---|
| 309 | nzb = 0 |
---|
| 310 | nzta = nza |
---|
| 311 | nzt = MIN( nz, nzta ) |
---|
| 312 | nnz = nza |
---|
| 313 | |
---|
| 314 | ! |
---|
| 315 | !-- Calculate array bounds and gridpoint numbers for the transposed arrays |
---|
| 316 | !-- (needed in the pressure solver) |
---|
| 317 | !-- For the transposed arrays, cyclic boundaries as well as top and bottom |
---|
| 318 | !-- boundaries are omitted, because they are obstructive to the transposition |
---|
| 319 | |
---|
| 320 | ! |
---|
| 321 | !-- 1. transposition z --> x |
---|
| 322 | !-- This transposition is not neccessary in case of a 1d-decomposition along x, |
---|
| 323 | !-- except that the uptream-spline method is switched on |
---|
| 324 | IF ( pdims(2) /= 1 .OR. momentum_advec == 'ups-scheme' .OR. & |
---|
| 325 | scalar_advec == 'ups-scheme' ) THEN |
---|
| 326 | |
---|
| 327 | IF ( pdims(2) == 1 .AND. ( momentum_advec == 'ups-scheme' .OR. & |
---|
| 328 | scalar_advec == 'ups-scheme' ) ) THEN |
---|
[254] | 329 | message_string = '1d-decomposition along x ' // & |
---|
| 330 | 'chosen but nz restrictions may occur' // & |
---|
| 331 | '& since ups-scheme is activated' |
---|
| 332 | CALL message( 'init_pegrid', 'PA0229', 0, 1, 0, 6, 0 ) |
---|
[1] | 333 | ENDIF |
---|
| 334 | nys_x = nys |
---|
| 335 | nyn_xa = nyna |
---|
| 336 | nyn_x = nyn |
---|
| 337 | nny_x = nny |
---|
| 338 | IF ( MOD( nza , pdims(1) ) /= 0 ) THEN |
---|
[274] | 339 | WRITE( message_string, * ) 'transposition z --> x:', & |
---|
| 340 | '&nz=',nz,' is not an integral divisior of pdims(1)=', & |
---|
| 341 | pdims(1) |
---|
[254] | 342 | CALL message( 'init_pegrid', 'PA0230', 1, 2, 0, 6, 0 ) |
---|
[1] | 343 | ENDIF |
---|
| 344 | nnz_x = nza / pdims(1) |
---|
| 345 | nzb_x = 1 + myidx * nnz_x |
---|
| 346 | nzt_xa = ( myidx + 1 ) * nnz_x |
---|
| 347 | nzt_x = MIN( nzt, nzt_xa ) |
---|
| 348 | |
---|
| 349 | sendrecvcount_zx = nnx * nny * nnz_x |
---|
| 350 | |
---|
[181] | 351 | ELSE |
---|
| 352 | ! |
---|
| 353 | !--- Setting of dummy values because otherwise variables are undefined in |
---|
| 354 | !--- the next step x --> y |
---|
| 355 | !--- WARNING: This case has still to be clarified!!!!!!!!!!!! |
---|
| 356 | nnz_x = 1 |
---|
| 357 | nzb_x = 1 |
---|
| 358 | nzt_xa = 1 |
---|
| 359 | nzt_x = 1 |
---|
| 360 | nny_x = nny |
---|
| 361 | |
---|
[1] | 362 | ENDIF |
---|
| 363 | |
---|
| 364 | ! |
---|
| 365 | !-- 2. transposition x --> y |
---|
| 366 | nnz_y = nnz_x |
---|
| 367 | nzb_y = nzb_x |
---|
| 368 | nzt_ya = nzt_xa |
---|
| 369 | nzt_y = nzt_x |
---|
| 370 | IF ( MOD( nxa+1 , pdims(2) ) /= 0 ) THEN |
---|
[274] | 371 | WRITE( message_string, * ) 'transposition x --> y:', & |
---|
| 372 | '&nx+1=',nx+1,' is not an integral divisor of ',& |
---|
| 373 | 'pdims(2)=',pdims(2) |
---|
[254] | 374 | CALL message( 'init_pegrid', 'PA0231', 1, 2, 0, 6, 0 ) |
---|
[1] | 375 | ENDIF |
---|
| 376 | nnx_y = (nxa+1) / pdims(2) |
---|
| 377 | nxl_y = myidy * nnx_y |
---|
| 378 | nxr_ya = ( myidy + 1 ) * nnx_y - 1 |
---|
| 379 | nxr_y = MIN( nx, nxr_ya ) |
---|
| 380 | |
---|
| 381 | sendrecvcount_xy = nnx_y * nny_x * nnz_y |
---|
| 382 | |
---|
| 383 | ! |
---|
| 384 | !-- 3. transposition y --> z (ELSE: x --> y in case of 1D-decomposition |
---|
| 385 | !-- along x) |
---|
| 386 | IF ( pdims(2) /= 1 .OR. momentum_advec == 'ups-scheme' .OR. & |
---|
| 387 | scalar_advec == 'ups-scheme' ) THEN |
---|
| 388 | ! |
---|
| 389 | !-- y --> z |
---|
| 390 | !-- This transposition is not neccessary in case of a 1d-decomposition |
---|
| 391 | !-- along x, except that the uptream-spline method is switched on |
---|
| 392 | nnx_z = nnx_y |
---|
| 393 | nxl_z = nxl_y |
---|
| 394 | nxr_za = nxr_ya |
---|
| 395 | nxr_z = nxr_y |
---|
| 396 | IF ( MOD( nya+1 , pdims(1) ) /= 0 ) THEN |
---|
[274] | 397 | WRITE( message_string, * ) 'transposition y --> z:', & |
---|
| 398 | '& ny+1=',ny+1,' is not an integral divisor of ',& |
---|
| 399 | 'pdims(1)=',pdims(1) |
---|
[254] | 400 | CALL message( 'init_pegrid', 'PA0232', 1, 2, 0, 6, 0 ) |
---|
[1] | 401 | ENDIF |
---|
| 402 | nny_z = (nya+1) / pdims(1) |
---|
| 403 | nys_z = myidx * nny_z |
---|
| 404 | nyn_za = ( myidx + 1 ) * nny_z - 1 |
---|
| 405 | nyn_z = MIN( ny, nyn_za ) |
---|
| 406 | |
---|
| 407 | sendrecvcount_yz = nnx_y * nny_z * nnz_y |
---|
| 408 | |
---|
| 409 | ELSE |
---|
| 410 | ! |
---|
| 411 | !-- x --> y. This condition must be fulfilled for a 1D-decomposition along x |
---|
| 412 | IF ( MOD( nya+1 , pdims(1) ) /= 0 ) THEN |
---|
[274] | 413 | WRITE( message_string, * ) 'transposition x --> y:', & |
---|
| 414 | '& ny+1=',ny+1,' is not an integral divisor of ',& |
---|
| 415 | 'pdims(1)=',pdims(1) |
---|
[254] | 416 | CALL message( 'init_pegrid', 'PA0233', 1, 2, 0, 6, 0 ) |
---|
[1] | 417 | ENDIF |
---|
| 418 | |
---|
| 419 | ENDIF |
---|
| 420 | |
---|
| 421 | ! |
---|
| 422 | !-- Indices for direct transpositions z --> y (used for calculating spectra) |
---|
| 423 | IF ( dt_dosp /= 9999999.9 ) THEN |
---|
| 424 | IF ( MOD( nza, pdims(2) ) /= 0 ) THEN |
---|
[274] | 425 | WRITE( message_string, * ) 'direct transposition z --> y (needed ', & |
---|
| 426 | 'for spectra):& nz=',nz,' is not an integral divisor of ',& |
---|
| 427 | 'pdims(2)=',pdims(2) |
---|
[254] | 428 | CALL message( 'init_pegrid', 'PA0234', 1, 2, 0, 6, 0 ) |
---|
[1] | 429 | ELSE |
---|
| 430 | nxl_yd = nxl |
---|
| 431 | nxr_yda = nxra |
---|
| 432 | nxr_yd = nxr |
---|
| 433 | nzb_yd = 1 + myidy * ( nza / pdims(2) ) |
---|
| 434 | nzt_yda = ( myidy + 1 ) * ( nza / pdims(2) ) |
---|
| 435 | nzt_yd = MIN( nzt, nzt_yda ) |
---|
| 436 | |
---|
| 437 | sendrecvcount_zyd = nnx * nny * ( nza / pdims(2) ) |
---|
| 438 | ENDIF |
---|
| 439 | ENDIF |
---|
| 440 | |
---|
| 441 | ! |
---|
| 442 | !-- Indices for direct transpositions y --> x (they are only possible in case |
---|
| 443 | !-- of a 1d-decomposition along x) |
---|
| 444 | IF ( pdims(2) == 1 ) THEN |
---|
| 445 | nny_x = nny / pdims(1) |
---|
| 446 | nys_x = myid * nny_x |
---|
| 447 | nyn_xa = ( myid + 1 ) * nny_x - 1 |
---|
| 448 | nyn_x = MIN( ny, nyn_xa ) |
---|
| 449 | nzb_x = 1 |
---|
| 450 | nzt_xa = nza |
---|
| 451 | nzt_x = nz |
---|
| 452 | sendrecvcount_xy = nnx * nny_x * nza |
---|
| 453 | ENDIF |
---|
| 454 | |
---|
| 455 | ! |
---|
| 456 | !-- Indices for direct transpositions x --> y (they are only possible in case |
---|
| 457 | !-- of a 1d-decomposition along y) |
---|
| 458 | IF ( pdims(1) == 1 ) THEN |
---|
| 459 | nnx_y = nnx / pdims(2) |
---|
| 460 | nxl_y = myid * nnx_y |
---|
| 461 | nxr_ya = ( myid + 1 ) * nnx_y - 1 |
---|
| 462 | nxr_y = MIN( nx, nxr_ya ) |
---|
| 463 | nzb_y = 1 |
---|
| 464 | nzt_ya = nza |
---|
| 465 | nzt_y = nz |
---|
| 466 | sendrecvcount_xy = nnx_y * nny * nza |
---|
| 467 | ENDIF |
---|
| 468 | |
---|
| 469 | ! |
---|
| 470 | !-- Arrays for storing the array bounds are needed any more |
---|
| 471 | DEALLOCATE( nxlf , nxrf , nynf , nysf ) |
---|
| 472 | |
---|
[145] | 473 | ! |
---|
| 474 | !-- Collect index bounds from other PEs (to be written to restart file later) |
---|
| 475 | ALLOCATE( hor_index_bounds(4,0:numprocs-1) ) |
---|
| 476 | |
---|
| 477 | IF ( myid == 0 ) THEN |
---|
| 478 | |
---|
| 479 | hor_index_bounds(1,0) = nxl |
---|
| 480 | hor_index_bounds(2,0) = nxr |
---|
| 481 | hor_index_bounds(3,0) = nys |
---|
| 482 | hor_index_bounds(4,0) = nyn |
---|
| 483 | |
---|
| 484 | ! |
---|
| 485 | !-- Receive data from all other PEs |
---|
| 486 | DO i = 1, numprocs-1 |
---|
| 487 | CALL MPI_RECV( ibuf, 4, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, & |
---|
| 488 | ierr ) |
---|
| 489 | hor_index_bounds(:,i) = ibuf(1:4) |
---|
| 490 | ENDDO |
---|
| 491 | |
---|
| 492 | ELSE |
---|
| 493 | ! |
---|
| 494 | !-- Send index bounds to PE0 |
---|
| 495 | ibuf(1) = nxl |
---|
| 496 | ibuf(2) = nxr |
---|
| 497 | ibuf(3) = nys |
---|
| 498 | ibuf(4) = nyn |
---|
| 499 | CALL MPI_SEND( ibuf, 4, MPI_INTEGER, 0, myid, comm2d, ierr ) |
---|
| 500 | |
---|
| 501 | ENDIF |
---|
| 502 | |
---|
[1] | 503 | #if defined( __print ) |
---|
| 504 | ! |
---|
| 505 | !-- Control output |
---|
| 506 | IF ( myid == 0 ) THEN |
---|
| 507 | PRINT*, '*** processor topology ***' |
---|
| 508 | PRINT*, ' ' |
---|
| 509 | PRINT*, 'myid pcoord left right south north idx idy nxl: nxr',& |
---|
| 510 | &' nys: nyn' |
---|
| 511 | PRINT*, '------------------------------------------------------------',& |
---|
| 512 | &'-----------' |
---|
| 513 | WRITE (*,1000) 0, pcoord(1), pcoord(2), pleft, pright, psouth, pnorth, & |
---|
| 514 | myidx, myidy, nxl, nxr, nys, nyn |
---|
| 515 | 1000 FORMAT (I4,2X,'(',I3,',',I3,')',3X,I4,2X,I4,3X,I4,2X,I4,2X,I3,1X,I3, & |
---|
| 516 | 2(2X,I4,':',I4)) |
---|
| 517 | |
---|
| 518 | ! |
---|
[108] | 519 | !-- Receive data from the other PEs |
---|
[1] | 520 | DO i = 1,numprocs-1 |
---|
| 521 | CALL MPI_RECV( ibuf, 12, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, & |
---|
| 522 | ierr ) |
---|
| 523 | WRITE (*,1000) i, ( ibuf(j) , j = 1,12 ) |
---|
| 524 | ENDDO |
---|
| 525 | ELSE |
---|
| 526 | |
---|
| 527 | ! |
---|
| 528 | !-- Send data to PE0 |
---|
| 529 | ibuf(1) = pcoord(1); ibuf(2) = pcoord(2); ibuf(3) = pleft |
---|
| 530 | ibuf(4) = pright; ibuf(5) = psouth; ibuf(6) = pnorth; ibuf(7) = myidx |
---|
| 531 | ibuf(8) = myidy; ibuf(9) = nxl; ibuf(10) = nxr; ibuf(11) = nys |
---|
| 532 | ibuf(12) = nyn |
---|
| 533 | CALL MPI_SEND( ibuf, 12, MPI_INTEGER, 0, myid, comm2d, ierr ) |
---|
| 534 | ENDIF |
---|
| 535 | #endif |
---|
| 536 | |
---|
[206] | 537 | #if defined( __parallel ) |
---|
[102] | 538 | #if defined( __mpi2 ) |
---|
| 539 | ! |
---|
| 540 | !-- In case of coupled runs, get the port name on PE0 of the atmosphere model |
---|
| 541 | !-- and pass it to PE0 of the ocean model |
---|
| 542 | IF ( myid == 0 ) THEN |
---|
| 543 | |
---|
| 544 | IF ( coupling_mode == 'atmosphere_to_ocean' ) THEN |
---|
| 545 | |
---|
| 546 | CALL MPI_OPEN_PORT( MPI_INFO_NULL, port_name, ierr ) |
---|
[108] | 547 | ! |
---|
| 548 | !-- TEST OUTPUT (TO BE REMOVED) |
---|
| 549 | WRITE(9,*) TRIM( coupling_mode ), & |
---|
| 550 | ', ierr after MPI_OPEN_PORT: ', ierr |
---|
| 551 | CALL LOCAL_FLUSH( 9 ) |
---|
| 552 | |
---|
[102] | 553 | CALL MPI_PUBLISH_NAME( 'palm_coupler', MPI_INFO_NULL, port_name, & |
---|
| 554 | ierr ) |
---|
[104] | 555 | ! |
---|
[108] | 556 | !-- TEST OUTPUT (TO BE REMOVED) |
---|
| 557 | WRITE(9,*) TRIM( coupling_mode ), & |
---|
| 558 | ', ierr after MPI_PUBLISH_NAME: ', ierr |
---|
| 559 | CALL LOCAL_FLUSH( 9 ) |
---|
| 560 | |
---|
| 561 | ! |
---|
[104] | 562 | !-- Write a flag file for the ocean model and the other atmosphere |
---|
| 563 | !-- processes. |
---|
| 564 | !-- There seems to be a bug in MPICH2 which causes hanging processes |
---|
| 565 | !-- in case that execution of LOOKUP_NAME is continued too early |
---|
| 566 | !-- (i.e. before the port has been created) |
---|
| 567 | OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) |
---|
| 568 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 569 | CLOSE ( 90 ) |
---|
[102] | 570 | |
---|
| 571 | ELSEIF ( coupling_mode == 'ocean_to_atmosphere' ) THEN |
---|
| 572 | |
---|
[104] | 573 | ! |
---|
| 574 | !-- Continue only if the atmosphere model has created the port. |
---|
| 575 | !-- There seems to be a bug in MPICH2 which causes hanging processes |
---|
| 576 | !-- in case that execution of LOOKUP_NAME is continued too early |
---|
| 577 | !-- (i.e. before the port has been created) |
---|
| 578 | INQUIRE( FILE='COUPLING_PORT_OPENED', EXIST=found ) |
---|
| 579 | DO WHILE ( .NOT. found ) |
---|
| 580 | INQUIRE( FILE='COUPLING_PORT_OPENED', EXIST=found ) |
---|
| 581 | ENDDO |
---|
| 582 | |
---|
[102] | 583 | CALL MPI_LOOKUP_NAME( 'palm_coupler', MPI_INFO_NULL, port_name, ierr ) |
---|
[108] | 584 | ! |
---|
| 585 | !-- TEST OUTPUT (TO BE REMOVED) |
---|
| 586 | WRITE(9,*) TRIM( coupling_mode ), & |
---|
| 587 | ', ierr after MPI_LOOKUP_NAME: ', ierr |
---|
| 588 | CALL LOCAL_FLUSH( 9 ) |
---|
[102] | 589 | |
---|
[108] | 590 | |
---|
[102] | 591 | ENDIF |
---|
| 592 | |
---|
| 593 | ENDIF |
---|
| 594 | |
---|
| 595 | ! |
---|
| 596 | !-- In case of coupled runs, establish the connection between the atmosphere |
---|
| 597 | !-- and the ocean model and define the intercommunicator (comm_inter) |
---|
| 598 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 599 | IF ( coupling_mode == 'atmosphere_to_ocean' ) THEN |
---|
| 600 | |
---|
[254] | 601 | PRINT*, '... before COMM_ACCEPT' |
---|
[102] | 602 | CALL MPI_COMM_ACCEPT( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, & |
---|
| 603 | comm_inter, ierr ) |
---|
[254] | 604 | PRINT*, '--- ierr = ', ierr |
---|
| 605 | PRINT*, '--- comm_inter atmosphere = ', comm_inter |
---|
[102] | 606 | |
---|
[108] | 607 | coupling_mode_remote = 'ocean_to_atmosphere' |
---|
| 608 | |
---|
[102] | 609 | ELSEIF ( coupling_mode == 'ocean_to_atmosphere' ) THEN |
---|
| 610 | |
---|
| 611 | IF ( myid == 0 ) PRINT*, '*** read: ', port_name, ' ierr = ', ierr |
---|
[254] | 612 | PRINT*, '... before COMM_CONNECT' |
---|
[102] | 613 | CALL MPI_COMM_CONNECT( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, & |
---|
| 614 | comm_inter, ierr ) |
---|
[254] | 615 | PRINT*, '--- ierr = ', ierr |
---|
| 616 | PRINT*, '--- comm_inter ocean = ', comm_inter |
---|
[102] | 617 | |
---|
[108] | 618 | coupling_mode_remote = 'atmosphere_to_ocean' |
---|
| 619 | |
---|
[102] | 620 | ENDIF |
---|
[206] | 621 | #endif |
---|
[102] | 622 | |
---|
| 623 | ! |
---|
| 624 | !-- In case of coupled runs, create a new MPI derived datatype for the |
---|
| 625 | !-- exchange of surface (xy) data . |
---|
| 626 | !-- Gridpoint number for the exchange of ghost points (xy-plane) |
---|
| 627 | ngp_xy = ( nxr - nxl + 3 ) * ( nyn - nys + 3 ) |
---|
| 628 | |
---|
| 629 | ! |
---|
| 630 | !-- Define a new MPI derived datatype for the exchange of ghost points in |
---|
| 631 | !-- y-direction for 2D-arrays (line) |
---|
| 632 | CALL MPI_TYPE_VECTOR( ngp_xy, 1, nzt-nzb+2, MPI_REAL, type_xy, ierr ) |
---|
| 633 | CALL MPI_TYPE_COMMIT( type_xy, ierr ) |
---|
| 634 | #endif |
---|
| 635 | |
---|
[1] | 636 | #else |
---|
| 637 | |
---|
| 638 | ! |
---|
| 639 | !-- Array bounds when running on a single PE (respectively a non-parallel |
---|
| 640 | !-- machine) |
---|
| 641 | nxl = 0 |
---|
| 642 | nxr = nx |
---|
| 643 | nxra = nx |
---|
| 644 | nnx = nxr - nxl + 1 |
---|
| 645 | nys = 0 |
---|
| 646 | nyn = ny |
---|
| 647 | nyna = ny |
---|
| 648 | nny = nyn - nys + 1 |
---|
| 649 | nzb = 0 |
---|
| 650 | nzt = nz |
---|
| 651 | nzta = nz |
---|
| 652 | nnz = nz |
---|
| 653 | |
---|
[145] | 654 | ALLOCATE( hor_index_bounds(4,0:0) ) |
---|
| 655 | hor_index_bounds(1,0) = nxl |
---|
| 656 | hor_index_bounds(2,0) = nxr |
---|
| 657 | hor_index_bounds(3,0) = nys |
---|
| 658 | hor_index_bounds(4,0) = nyn |
---|
| 659 | |
---|
[1] | 660 | ! |
---|
| 661 | !-- Array bounds for the pressure solver (in the parallel code, these bounds |
---|
| 662 | !-- are the ones for the transposed arrays) |
---|
| 663 | nys_x = nys |
---|
| 664 | nyn_x = nyn |
---|
| 665 | nyn_xa = nyn |
---|
| 666 | nzb_x = nzb + 1 |
---|
| 667 | nzt_x = nzt |
---|
| 668 | nzt_xa = nzt |
---|
| 669 | |
---|
| 670 | nxl_y = nxl |
---|
| 671 | nxr_y = nxr |
---|
| 672 | nxr_ya = nxr |
---|
| 673 | nzb_y = nzb + 1 |
---|
| 674 | nzt_y = nzt |
---|
| 675 | nzt_ya = nzt |
---|
| 676 | |
---|
| 677 | nxl_z = nxl |
---|
| 678 | nxr_z = nxr |
---|
| 679 | nxr_za = nxr |
---|
| 680 | nys_z = nys |
---|
| 681 | nyn_z = nyn |
---|
| 682 | nyn_za = nyn |
---|
| 683 | |
---|
| 684 | #endif |
---|
| 685 | |
---|
| 686 | ! |
---|
| 687 | !-- Calculate number of grid levels necessary for the multigrid poisson solver |
---|
| 688 | !-- as well as the gridpoint indices on each level |
---|
| 689 | IF ( psolver == 'multigrid' ) THEN |
---|
| 690 | |
---|
| 691 | ! |
---|
| 692 | !-- First calculate number of possible grid levels for the subdomains |
---|
| 693 | mg_levels_x = 1 |
---|
| 694 | mg_levels_y = 1 |
---|
| 695 | mg_levels_z = 1 |
---|
| 696 | |
---|
| 697 | i = nnx |
---|
| 698 | DO WHILE ( MOD( i, 2 ) == 0 .AND. i /= 2 ) |
---|
| 699 | i = i / 2 |
---|
| 700 | mg_levels_x = mg_levels_x + 1 |
---|
| 701 | ENDDO |
---|
| 702 | |
---|
| 703 | j = nny |
---|
| 704 | DO WHILE ( MOD( j, 2 ) == 0 .AND. j /= 2 ) |
---|
| 705 | j = j / 2 |
---|
| 706 | mg_levels_y = mg_levels_y + 1 |
---|
| 707 | ENDDO |
---|
| 708 | |
---|
[181] | 709 | k = nz ! do not use nnz because it might be > nz due to transposition |
---|
| 710 | ! requirements |
---|
[1] | 711 | DO WHILE ( MOD( k, 2 ) == 0 .AND. k /= 2 ) |
---|
| 712 | k = k / 2 |
---|
| 713 | mg_levels_z = mg_levels_z + 1 |
---|
| 714 | ENDDO |
---|
| 715 | |
---|
| 716 | maximum_grid_level = MIN( mg_levels_x, mg_levels_y, mg_levels_z ) |
---|
| 717 | |
---|
| 718 | ! |
---|
| 719 | !-- Find out, if the total domain allows more levels. These additional |
---|
| 720 | !-- levels are processed on PE0 only. |
---|
[197] | 721 | IF ( numprocs > 1 .AND. mg_switch_to_pe0_level /= -1 ) THEN |
---|
[1] | 722 | IF ( mg_levels_z > MIN( mg_levels_x, mg_levels_y ) ) THEN |
---|
| 723 | mg_switch_to_pe0_level_l = maximum_grid_level |
---|
| 724 | |
---|
| 725 | mg_levels_x = 1 |
---|
| 726 | mg_levels_y = 1 |
---|
| 727 | |
---|
| 728 | i = nx+1 |
---|
| 729 | DO WHILE ( MOD( i, 2 ) == 0 .AND. i /= 2 ) |
---|
| 730 | i = i / 2 |
---|
| 731 | mg_levels_x = mg_levels_x + 1 |
---|
| 732 | ENDDO |
---|
| 733 | |
---|
| 734 | j = ny+1 |
---|
| 735 | DO WHILE ( MOD( j, 2 ) == 0 .AND. j /= 2 ) |
---|
| 736 | j = j / 2 |
---|
| 737 | mg_levels_y = mg_levels_y + 1 |
---|
| 738 | ENDDO |
---|
| 739 | |
---|
| 740 | maximum_grid_level_l = MIN( mg_levels_x, mg_levels_y, mg_levels_z ) |
---|
| 741 | |
---|
| 742 | IF ( maximum_grid_level_l > mg_switch_to_pe0_level_l ) THEN |
---|
| 743 | mg_switch_to_pe0_level_l = maximum_grid_level_l - & |
---|
| 744 | mg_switch_to_pe0_level_l + 1 |
---|
| 745 | ELSE |
---|
| 746 | mg_switch_to_pe0_level_l = 0 |
---|
| 747 | ENDIF |
---|
| 748 | ELSE |
---|
| 749 | mg_switch_to_pe0_level_l = 0 |
---|
| 750 | maximum_grid_level_l = maximum_grid_level |
---|
| 751 | ENDIF |
---|
| 752 | |
---|
| 753 | ! |
---|
| 754 | !-- Use switch level calculated above only if it is not pre-defined |
---|
| 755 | !-- by user |
---|
| 756 | IF ( mg_switch_to_pe0_level == 0 ) THEN |
---|
| 757 | |
---|
| 758 | IF ( mg_switch_to_pe0_level_l /= 0 ) THEN |
---|
| 759 | mg_switch_to_pe0_level = mg_switch_to_pe0_level_l |
---|
| 760 | maximum_grid_level = maximum_grid_level_l |
---|
| 761 | ENDIF |
---|
| 762 | |
---|
| 763 | ELSE |
---|
| 764 | ! |
---|
| 765 | !-- Check pre-defined value and reset to default, if neccessary |
---|
| 766 | IF ( mg_switch_to_pe0_level < mg_switch_to_pe0_level_l .OR. & |
---|
| 767 | mg_switch_to_pe0_level >= maximum_grid_level_l ) THEN |
---|
[254] | 768 | message_string = 'mg_switch_to_pe0_level ' // & |
---|
| 769 | 'out of range and reset to default (=0)' |
---|
| 770 | CALL message( 'init_pegrid', 'PA0235', 0, 1, 0, 6, 0 ) |
---|
[1] | 771 | mg_switch_to_pe0_level = 0 |
---|
| 772 | ELSE |
---|
| 773 | ! |
---|
| 774 | !-- Use the largest number of possible levels anyway and recalculate |
---|
| 775 | !-- the switch level to this largest number of possible values |
---|
| 776 | maximum_grid_level = maximum_grid_level_l |
---|
| 777 | |
---|
| 778 | ENDIF |
---|
| 779 | ENDIF |
---|
| 780 | |
---|
| 781 | ENDIF |
---|
| 782 | |
---|
| 783 | ALLOCATE( grid_level_count(maximum_grid_level), & |
---|
| 784 | nxl_mg(maximum_grid_level), nxr_mg(maximum_grid_level), & |
---|
| 785 | nyn_mg(maximum_grid_level), nys_mg(maximum_grid_level), & |
---|
| 786 | nzt_mg(maximum_grid_level) ) |
---|
| 787 | |
---|
| 788 | grid_level_count = 0 |
---|
| 789 | nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzt_l = nzt |
---|
| 790 | |
---|
| 791 | DO i = maximum_grid_level, 1 , -1 |
---|
| 792 | |
---|
| 793 | IF ( i == mg_switch_to_pe0_level ) THEN |
---|
| 794 | #if defined( __parallel ) |
---|
| 795 | ! |
---|
| 796 | !-- Save the grid size of the subdomain at the switch level, because |
---|
| 797 | !-- it is needed in poismg. |
---|
| 798 | !-- Array bounds of the local subdomain grids are gathered on PE0 |
---|
| 799 | ind(1) = nxl_l; ind(2) = nxr_l |
---|
| 800 | ind(3) = nys_l; ind(4) = nyn_l |
---|
| 801 | ind(5) = nzt_l |
---|
| 802 | ALLOCATE( ind_all(5*numprocs), mg_loc_ind(5,0:numprocs-1) ) |
---|
| 803 | CALL MPI_ALLGATHER( ind, 5, MPI_INTEGER, ind_all, 5, & |
---|
| 804 | MPI_INTEGER, comm2d, ierr ) |
---|
| 805 | DO j = 0, numprocs-1 |
---|
| 806 | DO k = 1, 5 |
---|
| 807 | mg_loc_ind(k,j) = ind_all(k+j*5) |
---|
| 808 | ENDDO |
---|
| 809 | ENDDO |
---|
| 810 | DEALLOCATE( ind_all ) |
---|
| 811 | ! |
---|
| 812 | !-- Calculate the grid size of the total domain gathered on PE0 |
---|
| 813 | nxr_l = ( nxr_l-nxl_l+1 ) * pdims(1) - 1 |
---|
| 814 | nxl_l = 0 |
---|
| 815 | nyn_l = ( nyn_l-nys_l+1 ) * pdims(2) - 1 |
---|
| 816 | nys_l = 0 |
---|
| 817 | ! |
---|
| 818 | !-- The size of this gathered array must not be larger than the |
---|
| 819 | !-- array tend, which is used in the multigrid scheme as a temporary |
---|
| 820 | !-- array |
---|
| 821 | subdomain_size = ( nxr - nxl + 3 ) * ( nyn - nys + 3 ) * & |
---|
| 822 | ( nzt - nzb + 2 ) |
---|
| 823 | gathered_size = ( nxr_l - nxl_l + 3 ) * ( nyn_l - nys_l + 3 ) * & |
---|
| 824 | ( nzt_l - nzb + 2 ) |
---|
| 825 | |
---|
| 826 | IF ( gathered_size > subdomain_size ) THEN |
---|
[254] | 827 | message_string = 'not enough memory for storing ' // & |
---|
| 828 | 'gathered multigrid data on PE0' |
---|
| 829 | CALL message( 'init_pegrid', 'PA0236', 1, 2, 0, 6, 0 ) |
---|
[1] | 830 | ENDIF |
---|
| 831 | #else |
---|
[254] | 832 | message_string = 'multigrid gather/scatter impossible ' // & |
---|
[1] | 833 | 'in non parallel mode' |
---|
[254] | 834 | CALL message( 'init_pegrid', 'PA0237', 1, 2, 0, 6, 0 ) |
---|
[1] | 835 | #endif |
---|
| 836 | ENDIF |
---|
| 837 | |
---|
| 838 | nxl_mg(i) = nxl_l |
---|
| 839 | nxr_mg(i) = nxr_l |
---|
| 840 | nys_mg(i) = nys_l |
---|
| 841 | nyn_mg(i) = nyn_l |
---|
| 842 | nzt_mg(i) = nzt_l |
---|
| 843 | |
---|
| 844 | nxl_l = nxl_l / 2 |
---|
| 845 | nxr_l = nxr_l / 2 |
---|
| 846 | nys_l = nys_l / 2 |
---|
| 847 | nyn_l = nyn_l / 2 |
---|
| 848 | nzt_l = nzt_l / 2 |
---|
| 849 | ENDDO |
---|
| 850 | |
---|
| 851 | ELSE |
---|
| 852 | |
---|
| 853 | maximum_grid_level = 1 |
---|
| 854 | |
---|
| 855 | ENDIF |
---|
| 856 | |
---|
| 857 | grid_level = maximum_grid_level |
---|
| 858 | |
---|
| 859 | #if defined( __parallel ) |
---|
| 860 | ! |
---|
| 861 | !-- Gridpoint number for the exchange of ghost points (y-line for 2D-arrays) |
---|
| 862 | ngp_y = nyn - nys + 1 |
---|
| 863 | |
---|
| 864 | ! |
---|
| 865 | !-- Define a new MPI derived datatype for the exchange of ghost points in |
---|
| 866 | !-- y-direction for 2D-arrays (line) |
---|
| 867 | CALL MPI_TYPE_VECTOR( nxr-nxl+3, 1, ngp_y+2, MPI_REAL, type_x, ierr ) |
---|
| 868 | CALL MPI_TYPE_COMMIT( type_x, ierr ) |
---|
| 869 | CALL MPI_TYPE_VECTOR( nxr-nxl+3, 1, ngp_y+2, MPI_INTEGER, type_x_int, ierr ) |
---|
| 870 | CALL MPI_TYPE_COMMIT( type_x_int, ierr ) |
---|
| 871 | |
---|
| 872 | ! |
---|
| 873 | !-- Calculate gridpoint numbers for the exchange of ghost points along x |
---|
| 874 | !-- (yz-plane for 3D-arrays) and define MPI derived data type(s) for the |
---|
| 875 | !-- exchange of ghost points in y-direction (xz-plane). |
---|
| 876 | !-- Do these calculations for the model grid and (if necessary) also |
---|
| 877 | !-- for the coarser grid levels used in the multigrid method |
---|
| 878 | ALLOCATE ( ngp_yz(maximum_grid_level), type_xz(maximum_grid_level) ) |
---|
| 879 | |
---|
| 880 | nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzb_l = nzb; nzt_l = nzt |
---|
| 881 | |
---|
| 882 | DO i = maximum_grid_level, 1 , -1 |
---|
| 883 | ngp_yz(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3) |
---|
| 884 | |
---|
| 885 | CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz(i), & |
---|
| 886 | MPI_REAL, type_xz(i), ierr ) |
---|
| 887 | CALL MPI_TYPE_COMMIT( type_xz(i), ierr ) |
---|
| 888 | |
---|
| 889 | nxl_l = nxl_l / 2 |
---|
| 890 | nxr_l = nxr_l / 2 |
---|
| 891 | nys_l = nys_l / 2 |
---|
| 892 | nyn_l = nyn_l / 2 |
---|
| 893 | nzt_l = nzt_l / 2 |
---|
| 894 | ENDDO |
---|
| 895 | #endif |
---|
| 896 | |
---|
| 897 | #if defined( __parallel ) |
---|
| 898 | ! |
---|
| 899 | !-- Setting of flags for inflow/outflow conditions in case of non-cyclic |
---|
[106] | 900 | !-- horizontal boundary conditions. |
---|
[1] | 901 | IF ( pleft == MPI_PROC_NULL ) THEN |
---|
[73] | 902 | IF ( bc_lr == 'dirichlet/radiation' ) THEN |
---|
[1] | 903 | inflow_l = .TRUE. |
---|
[73] | 904 | ELSEIF ( bc_lr == 'radiation/dirichlet' ) THEN |
---|
[1] | 905 | outflow_l = .TRUE. |
---|
| 906 | ENDIF |
---|
| 907 | ENDIF |
---|
| 908 | |
---|
| 909 | IF ( pright == MPI_PROC_NULL ) THEN |
---|
[73] | 910 | IF ( bc_lr == 'dirichlet/radiation' ) THEN |
---|
[1] | 911 | outflow_r = .TRUE. |
---|
[73] | 912 | ELSEIF ( bc_lr == 'radiation/dirichlet' ) THEN |
---|
[1] | 913 | inflow_r = .TRUE. |
---|
| 914 | ENDIF |
---|
| 915 | ENDIF |
---|
| 916 | |
---|
| 917 | IF ( psouth == MPI_PROC_NULL ) THEN |
---|
[73] | 918 | IF ( bc_ns == 'dirichlet/radiation' ) THEN |
---|
[1] | 919 | outflow_s = .TRUE. |
---|
[73] | 920 | ELSEIF ( bc_ns == 'radiation/dirichlet' ) THEN |
---|
[1] | 921 | inflow_s = .TRUE. |
---|
| 922 | ENDIF |
---|
| 923 | ENDIF |
---|
| 924 | |
---|
| 925 | IF ( pnorth == MPI_PROC_NULL ) THEN |
---|
[73] | 926 | IF ( bc_ns == 'dirichlet/radiation' ) THEN |
---|
[1] | 927 | inflow_n = .TRUE. |
---|
[73] | 928 | ELSEIF ( bc_ns == 'radiation/dirichlet' ) THEN |
---|
[1] | 929 | outflow_n = .TRUE. |
---|
| 930 | ENDIF |
---|
| 931 | ENDIF |
---|
| 932 | |
---|
[151] | 933 | ! |
---|
| 934 | !-- Broadcast the id of the inflow PE |
---|
| 935 | IF ( inflow_l ) THEN |
---|
[163] | 936 | id_inflow_l = myidx |
---|
[151] | 937 | ELSE |
---|
| 938 | id_inflow_l = 0 |
---|
| 939 | ENDIF |
---|
[622] | 940 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[151] | 941 | CALL MPI_ALLREDUCE( id_inflow_l, id_inflow, 1, MPI_INTEGER, MPI_SUM, & |
---|
| 942 | comm1dx, ierr ) |
---|
| 943 | |
---|
[163] | 944 | ! |
---|
| 945 | !-- Broadcast the id of the recycling plane |
---|
| 946 | !-- WARNING: needs to be adjusted in case of inflows other than from left side! |
---|
[622] | 947 | IF ( ( recycling_width / dx ) >= nxl .AND. & |
---|
| 948 | ( recycling_width / dx ) <= nxr ) THEN |
---|
[163] | 949 | id_recycling_l = myidx |
---|
| 950 | ELSE |
---|
| 951 | id_recycling_l = 0 |
---|
| 952 | ENDIF |
---|
[622] | 953 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[163] | 954 | CALL MPI_ALLREDUCE( id_recycling_l, id_recycling, 1, MPI_INTEGER, MPI_SUM, & |
---|
| 955 | comm1dx, ierr ) |
---|
| 956 | |
---|
[1] | 957 | #else |
---|
[73] | 958 | IF ( bc_lr == 'dirichlet/radiation' ) THEN |
---|
[1] | 959 | inflow_l = .TRUE. |
---|
| 960 | outflow_r = .TRUE. |
---|
[73] | 961 | ELSEIF ( bc_lr == 'radiation/dirichlet' ) THEN |
---|
[1] | 962 | outflow_l = .TRUE. |
---|
| 963 | inflow_r = .TRUE. |
---|
| 964 | ENDIF |
---|
| 965 | |
---|
[73] | 966 | IF ( bc_ns == 'dirichlet/radiation' ) THEN |
---|
[1] | 967 | inflow_n = .TRUE. |
---|
| 968 | outflow_s = .TRUE. |
---|
[73] | 969 | ELSEIF ( bc_ns == 'radiation/dirichlet' ) THEN |
---|
[1] | 970 | outflow_n = .TRUE. |
---|
| 971 | inflow_s = .TRUE. |
---|
| 972 | ENDIF |
---|
| 973 | #endif |
---|
[106] | 974 | ! |
---|
[110] | 975 | !-- At the outflow, u or v, respectively, have to be calculated for one more |
---|
| 976 | !-- grid point. |
---|
[106] | 977 | IF ( outflow_l ) THEN |
---|
| 978 | nxlu = nxl + 1 |
---|
| 979 | ELSE |
---|
| 980 | nxlu = nxl |
---|
| 981 | ENDIF |
---|
| 982 | IF ( outflow_s ) THEN |
---|
| 983 | nysv = nys + 1 |
---|
| 984 | ELSE |
---|
| 985 | nysv = nys |
---|
| 986 | ENDIF |
---|
[1] | 987 | |
---|
| 988 | IF ( psolver == 'poisfft_hybrid' ) THEN |
---|
| 989 | CALL poisfft_hybrid_ini |
---|
[75] | 990 | ELSEIF ( psolver == 'poisfft' ) THEN |
---|
[1] | 991 | CALL poisfft_init |
---|
| 992 | ENDIF |
---|
| 993 | |
---|
[114] | 994 | ! |
---|
| 995 | !-- Allocate wall flag arrays used in the multigrid solver |
---|
| 996 | IF ( psolver == 'multigrid' ) THEN |
---|
| 997 | |
---|
| 998 | DO i = maximum_grid_level, 1, -1 |
---|
| 999 | |
---|
| 1000 | SELECT CASE ( i ) |
---|
| 1001 | |
---|
| 1002 | CASE ( 1 ) |
---|
| 1003 | ALLOCATE( wall_flags_1(nzb:nzt_mg(i)+1, & |
---|
| 1004 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1005 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1006 | |
---|
| 1007 | CASE ( 2 ) |
---|
| 1008 | ALLOCATE( wall_flags_2(nzb:nzt_mg(i)+1, & |
---|
| 1009 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1010 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1011 | |
---|
| 1012 | CASE ( 3 ) |
---|
| 1013 | ALLOCATE( wall_flags_3(nzb:nzt_mg(i)+1, & |
---|
| 1014 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1015 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1016 | |
---|
| 1017 | CASE ( 4 ) |
---|
| 1018 | ALLOCATE( wall_flags_4(nzb:nzt_mg(i)+1, & |
---|
| 1019 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1020 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1021 | |
---|
| 1022 | CASE ( 5 ) |
---|
| 1023 | ALLOCATE( wall_flags_5(nzb:nzt_mg(i)+1, & |
---|
| 1024 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1025 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1026 | |
---|
| 1027 | CASE ( 6 ) |
---|
| 1028 | ALLOCATE( wall_flags_6(nzb:nzt_mg(i)+1, & |
---|
| 1029 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1030 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1031 | |
---|
| 1032 | CASE ( 7 ) |
---|
| 1033 | ALLOCATE( wall_flags_7(nzb:nzt_mg(i)+1, & |
---|
| 1034 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1035 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1036 | |
---|
| 1037 | CASE ( 8 ) |
---|
| 1038 | ALLOCATE( wall_flags_8(nzb:nzt_mg(i)+1, & |
---|
| 1039 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1040 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1041 | |
---|
| 1042 | CASE ( 9 ) |
---|
| 1043 | ALLOCATE( wall_flags_9(nzb:nzt_mg(i)+1, & |
---|
| 1044 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1045 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1046 | |
---|
| 1047 | CASE ( 10 ) |
---|
| 1048 | ALLOCATE( wall_flags_10(nzb:nzt_mg(i)+1, & |
---|
| 1049 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1050 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1051 | |
---|
| 1052 | CASE DEFAULT |
---|
[254] | 1053 | message_string = 'more than 10 multigrid levels' |
---|
| 1054 | CALL message( 'init_pegrid', 'PA0238', 1, 2, 0, 6, 0 ) |
---|
[114] | 1055 | |
---|
| 1056 | END SELECT |
---|
| 1057 | |
---|
| 1058 | ENDDO |
---|
| 1059 | |
---|
| 1060 | ENDIF |
---|
| 1061 | |
---|
[1] | 1062 | END SUBROUTINE init_pegrid |
---|