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

Last change on this file since 1435 was 1435, checked in by keck, 10 years ago

Bugfix: Added missing parameter coupling_mode_remote to ONLY-attribute. (init_pegrid)

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