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

Last change on this file since 1779 was 1779, checked in by raasch, 8 years ago

pmc array management changed from linked list to sequential loop; further small changes and cosmetics for the pmc

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