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

Last change on this file since 2014 was 2001, checked in by knoop, 8 years ago

last commit documented

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