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