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

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

output of location messages complemented, output of location bar added
(Makefile, check_parameters, cpulog, init_pegrid, init_3d_model, message, palm, parin, time_integration, new: progress_bar)
preprocessor switch intel_compiler added, -r8 compiler options removed
(.mrun.config.default, .mrun.config.imuk, .mrun.config.kiaps)

batch_job added to envpar-NAMELIST
(mrun, parin)

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