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