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

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

last commit documented

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