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