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