source: palm/trunk/SOURCE/init_pegrid.f90 @ 2180

Last change on this file since 2180 was 2180, checked in by hellstea, 7 years ago

Checks to ensure (2178) that pdims match the grid dimensions in the

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