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