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

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

last commit documented

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