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