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

Last change on this file since 1384 was 1384, checked in by raasch, 10 years ago

output of location messages to stdout

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