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

Last change on this file since 1922 was 1922, checked in by boeske, 8 years ago

Bugfix concerning array transposition checks

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