[2696] | 1 | !> @file pmc_handle_communicator_mod.f90 |
---|
[4649] | 2 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1762] | 4 | ! |
---|
[4649] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General |
---|
| 6 | ! Public License as published by the Free Software Foundation, either version 3 of the License, or |
---|
| 7 | ! (at your option) any later version. |
---|
[1762] | 8 | ! |
---|
[4649] | 9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
---|
| 10 | ! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 11 | ! Public License for more details. |
---|
[1762] | 12 | ! |
---|
[4649] | 13 | ! You should have received a copy of the GNU General Public License along with PALM. If not, see |
---|
| 14 | ! <http://www.gnu.org/licenses/>. |
---|
[1762] | 15 | ! |
---|
[4360] | 16 | ! Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
[4649] | 17 | !--------------------------------------------------------------------------------------------------! |
---|
[1762] | 18 | ! |
---|
[4649] | 19 | ! |
---|
[1762] | 20 | ! Current revisions: |
---|
[4649] | 21 | ! ----------------- |
---|
[4629] | 22 | ! |
---|
| 23 | ! |
---|
[1792] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: pmc_handle_communicator_mod.f90 4771 2020-11-04 13:12:46Z suehring $ |
---|
[4771] | 27 | ! Canopy-restricted anterpolation introduced. New namelist parameter anterpolation_starting_height |
---|
| 28 | ! introduced for controlling canopy-restricted anterpolation. |
---|
| 29 | ! |
---|
| 30 | ! 4650 2020-08-25 14:35:50Z raasch |
---|
[4650] | 31 | ! bugfix for r4649 |
---|
| 32 | ! |
---|
| 33 | ! 4649 2020-08-25 12:11:17Z raasch |
---|
[4649] | 34 | ! File re-formatted to follow the PALM coding standard |
---|
| 35 | ! |
---|
| 36 | ! |
---|
| 37 | ! 4629 2020-07-29 09:37:56Z raasch |
---|
| 38 | ! Support for MPI Fortran77 interface (mpif.h) removed |
---|
| 39 | ! |
---|
[4629] | 40 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4182] | 41 | ! Corrected "Former revisions" section |
---|
[4649] | 42 | ! |
---|
[4182] | 43 | ! 3888 2019-04-12 09:18:10Z hellstea |
---|
[3888] | 44 | ! Missing MPI_BCAST of anterpolation_buffer_width added. |
---|
[4649] | 45 | ! |
---|
[3888] | 46 | ! 3885 2019-04-11 11:29:34Z kanani |
---|
[4649] | 47 | ! Changes related to global restructuring of location messages and introduction of additional debug |
---|
| 48 | ! messages |
---|
| 49 | ! |
---|
[3885] | 50 | ! 3819 2019-03-27 11:01:36Z hellstea |
---|
[4649] | 51 | ! Adjustable anterpolation buffer introduced on all nest boundaries, it is controlled by the new |
---|
| 52 | ! nesting_parameters parameter anterpolation_buffer_width. |
---|
| 53 | ! |
---|
[3819] | 54 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[2932] | 55 | ! nestpar renamed to nesting_parameters |
---|
[4649] | 56 | ! |
---|
[4182] | 57 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 58 | ! Initial revision by K. Ketelsen |
---|
[1792] | 59 | ! |
---|
[1762] | 60 | ! Description: |
---|
| 61 | ! ------------ |
---|
[1764] | 62 | ! Handle MPI communicator in PALM model coupler |
---|
[4649] | 63 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 64 | MODULE PMC_handle_communicator |
---|
[1764] | 65 | #if defined( __parallel ) |
---|
| 66 | USE kinds |
---|
[1762] | 67 | |
---|
[1764] | 68 | USE MPI |
---|
[1762] | 69 | |
---|
[4649] | 70 | USE pmc_general, & |
---|
| 71 | ONLY: pmc_max_models, & |
---|
| 72 | pmc_status_error, & |
---|
| 73 | pmc_status_ok |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | USE control_parameters, & |
---|
[1933] | 77 | ONLY: message_string |
---|
[1762] | 78 | |
---|
[1900] | 79 | IMPLICIT NONE |
---|
[1762] | 80 | |
---|
[4650] | 81 | ! |
---|
| 82 | !-- ATTENTION: Do not change the order of variable declarations in the following TYPE definition, |
---|
| 83 | !-- because the order must follow the order in which the layout data is given in the NAMELIST file. |
---|
[1900] | 84 | TYPE pmc_layout |
---|
[1762] | 85 | |
---|
[4649] | 86 | CHARACTER(LEN=32) :: name !< |
---|
[1762] | 87 | |
---|
[4649] | 88 | INTEGER :: id !< |
---|
[4650] | 89 | INTEGER :: parent_id !< |
---|
[4649] | 90 | INTEGER :: npe_total !< |
---|
[1762] | 91 | |
---|
[1900] | 92 | REAL(wp) :: lower_left_x !< |
---|
| 93 | REAL(wp) :: lower_left_y !< |
---|
[1762] | 94 | |
---|
[1900] | 95 | END TYPE pmc_layout |
---|
[1764] | 96 | |
---|
[4649] | 97 | PUBLIC pmc_status_ok, pmc_status_error !< |
---|
[1764] | 98 | |
---|
[2599] | 99 | INTEGER, PARAMETER, PUBLIC :: pmc_error_npes = 1 !< illegal number of processes |
---|
[2932] | 100 | INTEGER, PARAMETER, PUBLIC :: pmc_namelist_error = 2 !< error(s) in nesting_parameters namelist |
---|
[1900] | 101 | INTEGER, PARAMETER, PUBLIC :: pmc_no_namelist_found = 3 !< no couple layout namelist found |
---|
[1764] | 102 | |
---|
[2801] | 103 | INTEGER :: m_my_cpl_id !< coupler id of this model |
---|
[4649] | 104 | INTEGER :: m_ncpl !< number of couplers given in nesting_parameters namelist |
---|
[1900] | 105 | INTEGER :: m_parent_id !< coupler id of parent of this model |
---|
[4649] | 106 | INTEGER :: m_world_comm !< global nesting communicator |
---|
[1762] | 107 | |
---|
[2801] | 108 | TYPE(pmc_layout), PUBLIC, DIMENSION(pmc_max_models) :: m_couplers !< information of all couplers |
---|
[1762] | 109 | |
---|
[1900] | 110 | INTEGER, PUBLIC :: m_model_comm !< communicator of this model |
---|
[4649] | 111 | INTEGER, PUBLIC :: m_model_npes !< |
---|
| 112 | INTEGER, PUBLIC :: m_model_rank !< |
---|
[1933] | 113 | INTEGER, PUBLIC :: m_to_parent_comm !< communicator to the parent |
---|
[1900] | 114 | INTEGER, PUBLIC :: m_world_rank !< |
---|
[4649] | 115 | INTEGER :: m_parent_remote_size !< number of processes in the parent model |
---|
[1900] | 116 | INTEGER :: m_world_npes !< |
---|
[2599] | 117 | INTEGER :: peer_comm !< peer_communicator for inter communicators |
---|
[1791] | 118 | |
---|
[4649] | 119 | INTEGER, DIMENSION(pmc_max_models), PUBLIC :: m_to_child_comm !< communicator to the child(ren) |
---|
| 120 | INTEGER, DIMENSION(:), POINTER, PUBLIC :: pmc_parent_for_child !< |
---|
[1762] | 121 | |
---|
| 122 | |
---|
[4649] | 123 | INTERFACE pmc_get_model_info |
---|
| 124 | MODULE PROCEDURE pmc_get_model_info |
---|
| 125 | END INTERFACE pmc_get_model_info |
---|
| 126 | |
---|
[1900] | 127 | INTERFACE pmc_is_rootmodel |
---|
| 128 | MODULE PROCEDURE pmc_is_rootmodel |
---|
| 129 | END INTERFACE pmc_is_rootmodel |
---|
[1762] | 130 | |
---|
[4649] | 131 | PUBLIC pmc_get_model_info, pmc_init_model, pmc_is_rootmodel !< |
---|
[1762] | 132 | |
---|
| 133 | |
---|
[4649] | 134 | |
---|
[1764] | 135 | CONTAINS |
---|
[1762] | 136 | |
---|
[4649] | 137 | |
---|
| 138 | !--------------------------------------------------------------------------------------------------! |
---|
| 139 | ! Description: |
---|
| 140 | ! ------------ |
---|
| 141 | !> @Todo: Missing subroutine description. |
---|
| 142 | !--------------------------------------------------------------------------------------------------! |
---|
| 143 | SUBROUTINE pmc_init_model( comm, nesting_datatransfer_mode, nesting_mode, & |
---|
[4771] | 144 | anterpolation_buffer_width, anterpolation_starting_height, pmc_status ) |
---|
[1762] | 145 | |
---|
[4649] | 146 | USE control_parameters, & |
---|
[1900] | 147 | ONLY: message_string |
---|
[1764] | 148 | |
---|
[4649] | 149 | USE pegrid, & |
---|
[1900] | 150 | ONLY: myid |
---|
[1764] | 151 | |
---|
| 152 | IMPLICIT NONE |
---|
| 153 | |
---|
[4649] | 154 | CHARACTER(LEN=7), INTENT(INOUT) :: nesting_datatransfer_mode !< |
---|
[2696] | 155 | CHARACTER(LEN=8), INTENT(INOUT) :: nesting_mode !< |
---|
[1764] | 156 | |
---|
[4649] | 157 | INTEGER, INTENT(INOUT) :: anterpolation_buffer_width !< Boundary buffer width for anterpolation |
---|
| 158 | INTEGER, INTENT(INOUT) :: comm !< |
---|
| 159 | INTEGER, INTENT(INOUT) :: pmc_status !< |
---|
[1764] | 160 | |
---|
[4771] | 161 | REAL(wp), INTENT(INOUT) :: anterpolation_starting_height !< steering parameter for canopy restricted anterpolation |
---|
| 162 | |
---|
[1933] | 163 | INTEGER :: childcount !< |
---|
[1900] | 164 | INTEGER :: i !< |
---|
| 165 | INTEGER :: ierr !< |
---|
| 166 | INTEGER :: istat !< |
---|
| 167 | INTEGER :: m_my_cpl_rank !< |
---|
| 168 | INTEGER :: tag !< |
---|
[1764] | 169 | |
---|
[4649] | 170 | INTEGER, DIMENSION(pmc_max_models) :: activeparent !< I am active parent for this child ID |
---|
| 171 | INTEGER, DIMENSION(pmc_max_models+1) :: start_pe !< |
---|
[1762] | 172 | |
---|
[1900] | 173 | pmc_status = pmc_status_ok |
---|
| 174 | comm = -1 |
---|
| 175 | m_world_comm = MPI_COMM_WORLD |
---|
| 176 | m_my_cpl_id = -1 |
---|
[1933] | 177 | childcount = 0 |
---|
| 178 | activeparent = -1 |
---|
[1900] | 179 | start_pe(:) = 0 |
---|
| 180 | |
---|
| 181 | CALL MPI_COMM_RANK( MPI_COMM_WORLD, m_world_rank, istat ) |
---|
| 182 | CALL MPI_COMM_SIZE( MPI_COMM_WORLD, m_world_npes, istat ) |
---|
[1764] | 183 | ! |
---|
[2599] | 184 | !-- Only process 0 of root model reads |
---|
[1900] | 185 | IF ( m_world_rank == 0 ) THEN |
---|
[1762] | 186 | |
---|
[4649] | 187 | CALL read_coupling_layout( nesting_datatransfer_mode, nesting_mode, & |
---|
[4771] | 188 | anterpolation_buffer_width, anterpolation_starting_height, & |
---|
| 189 | pmc_status ) |
---|
[1762] | 190 | |
---|
[4649] | 191 | IF ( pmc_status /= pmc_no_namelist_found .AND. & |
---|
| 192 | pmc_status /= pmc_namelist_error ) & |
---|
[1900] | 193 | THEN |
---|
[1764] | 194 | ! |
---|
[2801] | 195 | !-- Calculate start PE of every model |
---|
[1900] | 196 | start_pe(1) = 0 |
---|
| 197 | DO i = 2, m_ncpl+1 |
---|
| 198 | start_pe(i) = start_pe(i-1) + m_couplers(i-1)%npe_total |
---|
| 199 | ENDDO |
---|
[1762] | 200 | |
---|
[1764] | 201 | ! |
---|
[4649] | 202 | !-- The sum of numbers of processes requested by all the domains must be equal to the total |
---|
| 203 | !-- number of processes of the run |
---|
[1900] | 204 | IF ( start_pe(m_ncpl+1) /= m_world_npes ) THEN |
---|
[4649] | 205 | WRITE( message_string, '(2A,I6,2A,I6,A)' ) & |
---|
| 206 | 'nesting-setup requires different number of ', & |
---|
| 207 | 'MPI procs (', start_pe(m_ncpl+1), ') than ', & |
---|
| 208 | 'provided (', m_world_npes,')' |
---|
[1900] | 209 | CALL message( 'pmc_init_model', 'PA0229', 3, 2, 0, 6, 0 ) |
---|
| 210 | ENDIF |
---|
[1762] | 211 | |
---|
[1900] | 212 | ENDIF |
---|
[1762] | 213 | |
---|
[1900] | 214 | ENDIF |
---|
[1764] | 215 | ! |
---|
[4649] | 216 | !-- Broadcast the read status. This synchronises all other processes with process 0 of the root |
---|
| 217 | !-- model. Without synchronisation, they would not behave in the correct way (e.g. they would not |
---|
| 218 | !-- return in case of a missing NAMELIST). |
---|
[1900] | 219 | CALL MPI_BCAST( pmc_status, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1762] | 220 | |
---|
[1900] | 221 | IF ( pmc_status == pmc_no_namelist_found ) THEN |
---|
[1764] | 222 | ! |
---|
[1900] | 223 | !-- Not a nested run; return the MPI_WORLD communicator |
---|
| 224 | comm = MPI_COMM_WORLD |
---|
| 225 | RETURN |
---|
[1762] | 226 | |
---|
[1900] | 227 | ELSEIF ( pmc_status == pmc_namelist_error ) THEN |
---|
[1764] | 228 | ! |
---|
[4649] | 229 | !-- Only the root model gives the error message. Others are aborted by the message-routine with |
---|
| 230 | !-- MPI_ABORT. Must be done this way since myid and comm2d have not yet been assigned at this |
---|
| 231 | !-- point. |
---|
[1900] | 232 | IF ( m_world_rank == 0 ) THEN |
---|
[2932] | 233 | message_string = 'errors in \$nesting_parameters' |
---|
[1900] | 234 | CALL message( 'pmc_init_model', 'PA0223', 3, 2, 0, 6, 0 ) |
---|
| 235 | ENDIF |
---|
[1762] | 236 | |
---|
[1900] | 237 | ENDIF |
---|
[1762] | 238 | |
---|
[2599] | 239 | CALL MPI_BCAST( m_ncpl, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
| 240 | CALL MPI_BCAST( start_pe, m_ncpl+1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1764] | 241 | ! |
---|
[1900] | 242 | !-- Broadcast coupling layout |
---|
| 243 | DO i = 1, m_ncpl |
---|
[4649] | 244 | CALL MPI_BCAST( m_couplers(i)%name, LEN( m_couplers(i)%name ), & |
---|
[1900] | 245 | MPI_CHARACTER, 0, MPI_COMM_WORLD, istat ) |
---|
[4649] | 246 | CALL MPI_BCAST( m_couplers(i)%id, 1, MPI_INTEGER, 0, & |
---|
[1900] | 247 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 248 | CALL MPI_BCAST( m_couplers(i)%Parent_id, 1, MPI_INTEGER, 0, & |
---|
[1900] | 249 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 250 | CALL MPI_BCAST( m_couplers(i)%npe_total, 1, MPI_INTEGER, 0, & |
---|
[1900] | 251 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 252 | CALL MPI_BCAST( m_couplers(i)%lower_left_x, 1, MPI_REAL, 0, & |
---|
[1900] | 253 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 254 | CALL MPI_BCAST( m_couplers(i)%lower_left_y, 1, MPI_REAL, 0, & |
---|
[1900] | 255 | MPI_COMM_WORLD, istat ) |
---|
| 256 | ENDDO |
---|
[4649] | 257 | CALL MPI_BCAST( nesting_mode, LEN( nesting_mode ), MPI_CHARACTER, 0, MPI_COMM_WORLD, istat ) |
---|
| 258 | CALL MPI_BCAST( nesting_datatransfer_mode, LEN(nesting_datatransfer_mode), MPI_CHARACTER, 0, & |
---|
[1900] | 259 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 260 | CALL MPI_BCAST( anterpolation_buffer_width, 1, MPI_INT, 0, MPI_COMM_WORLD, istat ) |
---|
[4771] | 261 | CALL MPI_BCAST( anterpolation_starting_height, 1, MPI_REAL, 0, MPI_COMM_WORLD, istat ) |
---|
[1764] | 262 | ! |
---|
[1900] | 263 | !-- Assign global MPI processes to individual models by setting the couple id |
---|
| 264 | DO i = 1, m_ncpl |
---|
[4649] | 265 | IF ( m_world_rank >= start_pe(i) .AND. m_world_rank < start_pe(i+1) ) THEN |
---|
[1900] | 266 | m_my_cpl_id = i |
---|
| 267 | EXIT |
---|
| 268 | ENDIF |
---|
| 269 | ENDDO |
---|
| 270 | m_my_cpl_rank = m_world_rank - start_pe(i) |
---|
[1764] | 271 | ! |
---|
[4649] | 272 | !-- MPI_COMM_WORLD is the communicator for ALL models (MPI-1 approach). The communictors for the |
---|
| 273 | !-- individual models as created by MPI_COMM_SPLIT. The color of the model is represented by the |
---|
| 274 | !-- coupler id |
---|
| 275 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, m_my_cpl_id, m_my_cpl_rank, comm, istat ) |
---|
[1764] | 276 | ! |
---|
[2599] | 277 | !-- Get size and rank of the model running on this process |
---|
[1900] | 278 | CALL MPI_COMM_RANK( comm, m_model_rank, istat ) |
---|
| 279 | CALL MPI_COMM_SIZE( comm, m_model_npes, istat ) |
---|
[1764] | 280 | ! |
---|
[2599] | 281 | !-- Broadcast (from process 0) the parent id and id of every model |
---|
[1900] | 282 | DO i = 1, m_ncpl |
---|
[4649] | 283 | CALL MPI_BCAST( m_couplers(i)%parent_id, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
| 284 | CALL MPI_BCAST( m_couplers(i)%id, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1900] | 285 | ENDDO |
---|
[1764] | 286 | ! |
---|
[1900] | 287 | !-- Save the current model communicator for pmc internal use |
---|
| 288 | m_model_comm = comm |
---|
[1762] | 289 | |
---|
[1764] | 290 | ! |
---|
[2599] | 291 | !-- Create intercommunicator between the parent and children. |
---|
[4649] | 292 | !-- MPI_INTERCOMM_CREATE creates an intercommunicator between 2 groups of different colors. The |
---|
| 293 | !-- grouping was done above with MPI_COMM_SPLIT. A duplicate of MPI_COMM_WORLD is created and used |
---|
| 294 | !-- as peer communicator (peer_comm) for MPI_INTERCOMM_CREATE. |
---|
| 295 | CALL MPI_COMM_DUP( MPI_COMM_WORLD, peer_comm, ierr ) |
---|
[1900] | 296 | DO i = 2, m_ncpl |
---|
| 297 | IF ( m_couplers(i)%parent_id == m_my_cpl_id ) THEN |
---|
[1764] | 298 | ! |
---|
[4649] | 299 | !-- Identify all children models of the current model and create inter-communicators to |
---|
| 300 | !-- connect between the current model and its children models. |
---|
[1900] | 301 | tag = 500 + i |
---|
[4649] | 302 | CALL MPI_INTERCOMM_CREATE( comm, 0, peer_comm, start_pe(i), tag, m_to_child_comm(i), & |
---|
| 303 | istat ) |
---|
[1933] | 304 | childcount = childcount + 1 |
---|
| 305 | activeparent(i) = 1 |
---|
[1900] | 306 | ELSEIF ( i == m_my_cpl_id) THEN |
---|
[1764] | 307 | ! |
---|
[4649] | 308 | !-- Create an inter-communicator to connect between the current model and its parent model. |
---|
[1900] | 309 | tag = 500 + i |
---|
[4649] | 310 | CALL MPI_INTERCOMM_CREATE( comm, 0, peer_comm, start_pe(m_couplers(i)%parent_id), tag, & |
---|
| 311 | m_to_parent_comm, istat ) |
---|
[1900] | 312 | ENDIF |
---|
| 313 | ENDDO |
---|
[1764] | 314 | ! |
---|
[4649] | 315 | !-- If I am a parent, count the number of children I have. Although this loop is symmetric on all |
---|
| 316 | !-- processes, the "activeparent" flag is true (==1) on the respective individual process only. |
---|
[1933] | 317 | ALLOCATE( pmc_parent_for_child(childcount+1) ) |
---|
[1762] | 318 | |
---|
[1933] | 319 | childcount = 0 |
---|
[1900] | 320 | DO i = 2, m_ncpl |
---|
[1933] | 321 | IF ( activeparent(i) == 1 ) THEN |
---|
| 322 | childcount = childcount + 1 |
---|
| 323 | pmc_parent_for_child(childcount) = i |
---|
[1900] | 324 | ENDIF |
---|
| 325 | ENDDO |
---|
[1764] | 326 | ! |
---|
[1933] | 327 | !-- Get the size of the parent model |
---|
[1900] | 328 | IF ( m_my_cpl_id > 1 ) THEN |
---|
[4649] | 329 | CALL MPI_COMM_REMOTE_SIZE( m_to_parent_comm, m_parent_remote_size, istat ) |
---|
[1900] | 330 | ELSE |
---|
[1764] | 331 | ! |
---|
[1933] | 332 | !-- The root model does not have a parent |
---|
| 333 | m_parent_remote_size = -1 |
---|
[1900] | 334 | ENDIF |
---|
[1764] | 335 | ! |
---|
[4649] | 336 | !-- Set myid to non-zero value except for the root domain. This is a setting for the message routine |
---|
| 337 | !-- which is called at the end of pmci_init. That routine outputs messages for myid = 0, only. |
---|
| 338 | !-- However, myid has not been assigened so far, so that all processes of the root model would |
---|
| 339 | !-- output a message. To avoid this, set myid to some other value except for process 0 of the root |
---|
| 340 | !-- domain. |
---|
[1900] | 341 | IF ( m_world_rank /= 0 ) myid = 1 |
---|
[1762] | 342 | |
---|
[1900] | 343 | END SUBROUTINE PMC_init_model |
---|
[1762] | 344 | |
---|
| 345 | |
---|
[4649] | 346 | !--------------------------------------------------------------------------------------------------! |
---|
| 347 | ! Description: |
---|
| 348 | ! ------------ |
---|
| 349 | !> @Todo: Missing subroutine description. |
---|
| 350 | !--------------------------------------------------------------------------------------------------! |
---|
| 351 | SUBROUTINE pmc_get_model_info( comm_world_nesting, cpl_id, cpl_name, cpl_parent_id, lower_left_x, & |
---|
| 352 | lower_left_y, ncpl, npe_total, request_for_cpl_id ) |
---|
[1764] | 353 | ! |
---|
[1791] | 354 | !-- Provide module private variables of the pmc for PALM |
---|
[1762] | 355 | |
---|
[1900] | 356 | USE kinds |
---|
[1762] | 357 | |
---|
[1900] | 358 | IMPLICIT NONE |
---|
[1762] | 359 | |
---|
[1933] | 360 | CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: cpl_name !< |
---|
[1762] | 361 | |
---|
[1933] | 362 | INTEGER, INTENT(IN), OPTIONAL :: request_for_cpl_id !< |
---|
[1762] | 363 | |
---|
[1900] | 364 | INTEGER, INTENT(OUT), OPTIONAL :: comm_world_nesting !< |
---|
| 365 | INTEGER, INTENT(OUT), OPTIONAL :: cpl_id !< |
---|
| 366 | INTEGER, INTENT(OUT), OPTIONAL :: cpl_parent_id !< |
---|
| 367 | INTEGER, INTENT(OUT), OPTIONAL :: ncpl !< |
---|
| 368 | INTEGER, INTENT(OUT), OPTIONAL :: npe_total !< |
---|
[1762] | 369 | |
---|
[2599] | 370 | INTEGER :: requested_cpl_id !< |
---|
[1764] | 371 | |
---|
[2599] | 372 | REAL(wp), INTENT(OUT), OPTIONAL :: lower_left_x !< |
---|
| 373 | REAL(wp), INTENT(OUT), OPTIONAL :: lower_left_y !< |
---|
[1764] | 374 | |
---|
[1791] | 375 | ! |
---|
[1900] | 376 | !-- Set the requested coupler id |
---|
| 377 | IF ( PRESENT( request_for_cpl_id ) ) THEN |
---|
| 378 | requested_cpl_id = request_for_cpl_id |
---|
[1791] | 379 | ! |
---|
[1900] | 380 | !-- Check for allowed range of values |
---|
| 381 | IF ( requested_cpl_id < 1 .OR. requested_cpl_id > m_ncpl ) RETURN |
---|
| 382 | ELSE |
---|
| 383 | requested_cpl_id = m_my_cpl_id |
---|
| 384 | ENDIF |
---|
[1791] | 385 | ! |
---|
[1900] | 386 | !-- Return the requested information |
---|
| 387 | IF ( PRESENT( comm_world_nesting ) ) THEN |
---|
| 388 | comm_world_nesting = m_world_comm |
---|
| 389 | ENDIF |
---|
| 390 | IF ( PRESENT( cpl_id ) ) THEN |
---|
| 391 | cpl_id = requested_cpl_id |
---|
| 392 | ENDIF |
---|
| 393 | IF ( PRESENT( cpl_parent_id ) ) THEN |
---|
| 394 | cpl_parent_id = m_couplers(requested_cpl_id)%parent_id |
---|
| 395 | ENDIF |
---|
| 396 | IF ( PRESENT( cpl_name ) ) THEN |
---|
| 397 | cpl_name = m_couplers(requested_cpl_id)%name |
---|
| 398 | ENDIF |
---|
| 399 | IF ( PRESENT( ncpl ) ) THEN |
---|
| 400 | ncpl = m_ncpl |
---|
| 401 | ENDIF |
---|
| 402 | IF ( PRESENT( npe_total ) ) THEN |
---|
| 403 | npe_total = m_couplers(requested_cpl_id)%npe_total |
---|
| 404 | ENDIF |
---|
| 405 | IF ( PRESENT( lower_left_x ) ) THEN |
---|
| 406 | lower_left_x = m_couplers(requested_cpl_id)%lower_left_x |
---|
| 407 | ENDIF |
---|
| 408 | IF ( PRESENT( lower_left_y ) ) THEN |
---|
| 409 | lower_left_y = m_couplers(requested_cpl_id)%lower_left_y |
---|
| 410 | ENDIF |
---|
[1791] | 411 | |
---|
[1900] | 412 | END SUBROUTINE pmc_get_model_info |
---|
[1791] | 413 | |
---|
| 414 | |
---|
| 415 | |
---|
[1900] | 416 | LOGICAL function pmc_is_rootmodel( ) |
---|
[1764] | 417 | |
---|
[1900] | 418 | IMPLICIT NONE |
---|
[1764] | 419 | |
---|
[1900] | 420 | pmc_is_rootmodel = ( m_my_cpl_id == 1 ) |
---|
[1764] | 421 | |
---|
[1900] | 422 | END FUNCTION pmc_is_rootmodel |
---|
[1764] | 423 | |
---|
| 424 | |
---|
| 425 | |
---|
[4649] | 426 | !--------------------------------------------------------------------------------------------------! |
---|
| 427 | ! Description: |
---|
| 428 | ! ------------ |
---|
| 429 | !> @Todo: Missing subroutine description. |
---|
| 430 | !--------------------------------------------------------------------------------------------------! |
---|
| 431 | SUBROUTINE read_coupling_layout( nesting_datatransfer_mode, nesting_mode, & |
---|
[4771] | 432 | anterpolation_buffer_width, anterpolation_starting_height, & |
---|
| 433 | pmc_status ) |
---|
[1762] | 434 | |
---|
[1764] | 435 | IMPLICIT NONE |
---|
[1762] | 436 | |
---|
[4649] | 437 | CHARACTER(LEN=7), INTENT(INOUT) :: nesting_datatransfer_mode !< |
---|
| 438 | CHARACTER(LEN=8), INTENT(INOUT) :: nesting_mode !< |
---|
[1764] | 439 | |
---|
[4649] | 440 | INTEGER, INTENT(INOUT) :: anterpolation_buffer_width !< Boundary buffer width for anterpolation |
---|
| 441 | INTEGER(iwp), INTENT(INOUT) :: pmc_status !< |
---|
[1764] | 442 | |
---|
[4771] | 443 | REAL(wp), INTENT(INOUT) :: anterpolation_starting_height !< steering parameter for canopy restricted anterpolation |
---|
| 444 | |
---|
[4649] | 445 | INTEGER(iwp) :: bad_llcorner !< |
---|
| 446 | INTEGER(iwp) :: i !< |
---|
| 447 | INTEGER(iwp) :: istat !< |
---|
| 448 | |
---|
| 449 | TYPE(pmc_layout), DIMENSION(pmc_max_models) :: domain_layouts !< |
---|
| 450 | |
---|
| 451 | NAMELIST /nesting_parameters/ domain_layouts, & |
---|
| 452 | nesting_datatransfer_mode, & |
---|
| 453 | nesting_mode, & |
---|
[4771] | 454 | anterpolation_buffer_width, & |
---|
| 455 | anterpolation_starting_height |
---|
[4649] | 456 | |
---|
[1764] | 457 | ! |
---|
| 458 | !-- Initialize some coupling variables |
---|
[1900] | 459 | domain_layouts(1:pmc_max_models)%id = -1 |
---|
[1791] | 460 | m_ncpl = 0 |
---|
[1762] | 461 | |
---|
[1764] | 462 | pmc_status = pmc_status_ok |
---|
| 463 | ! |
---|
| 464 | !-- Open the NAMELIST-file and read the nesting layout |
---|
| 465 | CALL check_open( 11 ) |
---|
[4649] | 466 | READ ( 11, nesting_parameters, IOSTAT = istat ) |
---|
[2279] | 467 | ! |
---|
[4649] | 468 | !-- Set filepointer to the beginning of the file. Otherwise process 0 will later be unable to read |
---|
| 469 | !-- the inipar-NAMELIST |
---|
[2279] | 470 | REWIND ( 11 ) |
---|
[1764] | 471 | |
---|
| 472 | IF ( istat < 0 ) THEN |
---|
| 473 | ! |
---|
[2932] | 474 | !-- No nesting_parameters-NAMELIST found |
---|
[1764] | 475 | pmc_status = pmc_no_namelist_found |
---|
[1762] | 476 | RETURN |
---|
[1764] | 477 | ELSEIF ( istat > 0 ) THEN |
---|
| 478 | ! |
---|
[2932] | 479 | !-- Errors in reading nesting_parameters-NAMELIST |
---|
[1764] | 480 | pmc_status = pmc_namelist_error |
---|
| 481 | RETURN |
---|
| 482 | ENDIF |
---|
| 483 | ! |
---|
| 484 | !-- Output location message |
---|
[3885] | 485 | CALL location_message( 'initialize communicators for nesting', 'start' ) |
---|
[1764] | 486 | ! |
---|
[2599] | 487 | !-- Assign the layout to the corresponding internally used variable m_couplers |
---|
[1764] | 488 | m_couplers = domain_layouts |
---|
| 489 | ! |
---|
[2932] | 490 | !-- Get the number of nested models given in the nesting_parameters-NAMELIST |
---|
[1900] | 491 | DO i = 1, pmc_max_models |
---|
[1764] | 492 | ! |
---|
[1791] | 493 | !-- When id=-1 is found for the first time, the list of domains is finished |
---|
[2599] | 494 | IF ( m_couplers(i)%id == -1 .OR. i == pmc_max_models ) THEN |
---|
[1791] | 495 | IF ( m_couplers(i)%id == -1 ) THEN |
---|
| 496 | m_ncpl = i - 1 |
---|
| 497 | EXIT |
---|
| 498 | ELSE |
---|
[1900] | 499 | m_ncpl = pmc_max_models |
---|
[1791] | 500 | ENDIF |
---|
[1764] | 501 | ENDIF |
---|
| 502 | ENDDO |
---|
[1933] | 503 | ! |
---|
[4649] | 504 | !-- Make sure that all domains have equal lower left corner in case of vertical nesting |
---|
[1933] | 505 | IF ( nesting_mode == 'vertical' ) THEN |
---|
| 506 | bad_llcorner = 0 |
---|
| 507 | DO i = 1, m_ncpl |
---|
[4649] | 508 | IF ( domain_layouts(i)%lower_left_x /= 0.0_wp .OR. & |
---|
[1933] | 509 | domain_layouts(i)%lower_left_y /= 0.0_wp ) THEN |
---|
| 510 | bad_llcorner = bad_llcorner + 1 |
---|
| 511 | domain_layouts(i)%lower_left_x = 0.0_wp |
---|
| 512 | domain_layouts(i)%lower_left_y = 0.0_wp |
---|
| 513 | ENDIF |
---|
| 514 | ENDDO |
---|
| 515 | IF ( bad_llcorner /= 0) THEN |
---|
[4649] | 516 | WRITE( message_string, *) 'at least one dimension of lower ', & |
---|
| 517 | 'left corner of one domain is not 0. ', & |
---|
| 518 | 'All lower left corners were set to (0, 0)' |
---|
[1933] | 519 | CALL message( 'read_coupling_layout', 'PA0427', 0, 0, 0, 6, 0 ) |
---|
| 520 | ENDIF |
---|
| 521 | ENDIF |
---|
| 522 | |
---|
[3885] | 523 | CALL location_message( 'initialize communicators for nesting', 'finished' ) |
---|
| 524 | |
---|
[1764] | 525 | END SUBROUTINE read_coupling_layout |
---|
| 526 | |
---|
| 527 | #endif |
---|
| 528 | END MODULE pmc_handle_communicator |
---|