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