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