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

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

REAL functions and a lot of REAL constants provided with KIND-attribute,
some small bugfixes

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