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

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

last commit documented

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