[1764] | 1 | MODULE PMC_handle_communicator |
---|
[1762] | 2 | |
---|
| 3 | !--------------------------------------------------------------------------------! |
---|
| 4 | ! This file is part of PALM. |
---|
| 5 | ! |
---|
| 6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 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 | ! |
---|
[1818] | 17 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
[1762] | 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
| 20 | ! Current revisions: |
---|
| 21 | ! ------------------ |
---|
[1851] | 22 | ! |
---|
[1883] | 23 | ! |
---|
[1792] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: pmc_handle_communicator_mod.f90 1883 2016-04-20 15:27:13Z raasch $ |
---|
| 27 | ! |
---|
[1883] | 28 | ! 1882 2016-04-20 15:24:46Z hellstea |
---|
| 29 | ! MPI_BCAST-calls to broadcast nesting_mode and nesting_datatransfer_mode |
---|
| 30 | ! are moved out from the DO i = 1, m_ncpl loop. |
---|
| 31 | ! |
---|
[1851] | 32 | ! 1850 2016-04-08 13:29:27Z maronga |
---|
| 33 | ! Module renamed |
---|
| 34 | ! |
---|
| 35 | ! |
---|
[1809] | 36 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
| 37 | ! MPI module used by default on all machines |
---|
| 38 | ! |
---|
[1798] | 39 | ! 1797 2016-03-21 16:50:28Z raasch |
---|
| 40 | ! introduction of different datatransfer modes, |
---|
| 41 | ! export of comm_world_nesting |
---|
| 42 | ! |
---|
[1792] | 43 | ! 1791 2016-03-11 10:41:25Z raasch |
---|
[1791] | 44 | ! m_nrofcpl renamed m_ncpl, |
---|
| 45 | ! pmc_get_local_model_info renamed pmc_get_model_info, some keywords also |
---|
| 46 | ! renamed and some added, |
---|
| 47 | ! debug write-statements commented out |
---|
[1765] | 48 | ! |
---|
[1787] | 49 | ! 1786 2016-03-08 05:49:27Z raasch |
---|
| 50 | ! Bugfix: nesting_mode is broadcast now |
---|
| 51 | ! |
---|
[1780] | 52 | ! 1779 2016-03-03 08:01:28Z raasch |
---|
| 53 | ! only the total number of PEs is given in the nestpar-NAMELIST, |
---|
| 54 | ! additional comments included |
---|
| 55 | ! |
---|
[1765] | 56 | ! 1764 2016-02-28 12:45:19Z raasch |
---|
[1764] | 57 | ! pmc_layout type: comm_cpl and comm_parent removed, character "name" moved at |
---|
| 58 | ! the beginning of the variable list, |
---|
| 59 | ! domain layout is read with new NAMELIST nestpar from standard file PARIN, |
---|
| 60 | ! MPI-datatype REAL8 replaced by REAL, kind=8 replaced by wp, |
---|
| 61 | ! variable domain_layouts instead of m_couplers introduced for this NAMELIST, |
---|
| 62 | ! general format changed to PALM style |
---|
[1762] | 63 | ! |
---|
[1763] | 64 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 65 | ! Initial revision by K. Ketelsen |
---|
| 66 | ! |
---|
[1762] | 67 | ! Description: |
---|
| 68 | ! ------------ |
---|
[1764] | 69 | ! Handle MPI communicator in PALM model coupler |
---|
[1762] | 70 | !------------------------------------------------------------------------------! |
---|
| 71 | |
---|
[1764] | 72 | #if defined( __parallel ) |
---|
| 73 | USE kinds |
---|
[1762] | 74 | |
---|
[1808] | 75 | #if defined( __mpifh ) |
---|
| 76 | INCLUDE "mpif.h" |
---|
| 77 | #else |
---|
[1764] | 78 | USE MPI |
---|
| 79 | #endif |
---|
[1762] | 80 | |
---|
[1764] | 81 | USE pmc_general, & |
---|
| 82 | ONLY: pmc_status_ok, pmc_status_error, pmc_max_modell |
---|
[1762] | 83 | |
---|
[1764] | 84 | IMPLICIT NONE |
---|
[1762] | 85 | |
---|
[1764] | 86 | TYPE pmc_layout |
---|
[1762] | 87 | |
---|
[1764] | 88 | CHARACTER(len=32) :: name |
---|
[1762] | 89 | |
---|
[1764] | 90 | INTEGER :: id |
---|
| 91 | INTEGER :: parent_id |
---|
[1779] | 92 | INTEGER :: npe_total |
---|
[1762] | 93 | |
---|
[1764] | 94 | REAL(wp) :: lower_left_x |
---|
| 95 | REAL(wp) :: lower_left_y |
---|
[1762] | 96 | |
---|
[1764] | 97 | END TYPE pmc_layout |
---|
| 98 | |
---|
| 99 | PUBLIC pmc_status_ok, pmc_status_error |
---|
| 100 | |
---|
| 101 | INTEGER, PARAMETER, PUBLIC :: pmc_error_npes = 1 ! illegal number of PEs |
---|
| 102 | INTEGER, PARAMETER, PUBLIC :: pmc_namelist_error = 2 ! error(s) in nestpar namelist |
---|
| 103 | INTEGER, PARAMETER, PUBLIC :: pmc_no_namelist_found = 3 ! No couple layout file found |
---|
| 104 | |
---|
[1762] | 105 | ! Coupler Setup |
---|
| 106 | |
---|
[1797] | 107 | INTEGER :: m_world_comm !global nesting communicator |
---|
[1762] | 108 | INTEGER :: m_my_CPL_id !Coupler id of this model |
---|
| 109 | INTEGER :: m_Parent_id !Coupler id of parent of this model |
---|
[1791] | 110 | INTEGER :: m_ncpl !Number of Couplers in layout file |
---|
[1762] | 111 | |
---|
[1791] | 112 | TYPE(PMC_layout),DIMENSION(PMC_MAX_MODELL) :: m_couplers !Information of all couplers |
---|
| 113 | |
---|
[1762] | 114 | ! MPI settings |
---|
| 115 | |
---|
| 116 | INTEGER,PUBLIC :: m_model_comm !Communicator of this model |
---|
| 117 | INTEGER,PUBLIC :: m_to_server_comm !Communicator to the server |
---|
| 118 | INTEGER,DIMENSION(PMC_MAX_MODELL) :: m_to_client_comm !Communicator to the client(s) |
---|
| 119 | INTEGER,PUBLIC :: m_world_rank |
---|
| 120 | INTEGER :: m_world_npes |
---|
| 121 | INTEGER,PUBLIC :: m_model_rank |
---|
| 122 | INTEGER,PUBLIC :: m_model_npes |
---|
| 123 | INTEGER :: m_server_remote_size !Number of Server PE's |
---|
| 124 | |
---|
| 125 | PUBLIC m_to_client_comm |
---|
| 126 | |
---|
| 127 | !Indicates this PE is server for Cleint NR |
---|
| 128 | |
---|
| 129 | INTEGER,DIMENSION(:),POINTER,PUBLIC :: PMC_Server_for_Client |
---|
| 130 | |
---|
[1764] | 131 | INTERFACE pmc_is_rootmodel |
---|
| 132 | MODULE PROCEDURE pmc_is_rootmodel |
---|
| 133 | END INTERFACE pmc_is_rootmodel |
---|
[1762] | 134 | |
---|
[1791] | 135 | INTERFACE pmc_get_model_info |
---|
| 136 | MODULE PROCEDURE pmc_get_model_info |
---|
| 137 | END INTERFACE pmc_get_model_info |
---|
[1762] | 138 | |
---|
[1791] | 139 | PUBLIC pmc_get_model_info, pmc_init_model, pmc_is_rootmodel |
---|
[1762] | 140 | |
---|
[1764] | 141 | CONTAINS |
---|
[1762] | 142 | |
---|
[1797] | 143 | SUBROUTINE pmc_init_model( comm, nesting_datatransfer_mode, nesting_mode, & |
---|
| 144 | pmc_status ) |
---|
[1762] | 145 | |
---|
[1764] | 146 | USE control_parameters, & |
---|
| 147 | ONLY: message_string |
---|
| 148 | |
---|
| 149 | USE pegrid, & |
---|
| 150 | ONLY: myid |
---|
| 151 | |
---|
| 152 | IMPLICIT NONE |
---|
| 153 | |
---|
| 154 | CHARACTER(LEN=7), INTENT(OUT) :: nesting_mode |
---|
[1797] | 155 | CHARACTER(LEN=7), INTENT(OUT) :: nesting_datatransfer_mode |
---|
[1764] | 156 | |
---|
| 157 | INTEGER, INTENT(OUT) :: comm |
---|
| 158 | INTEGER, INTENT(OUT) :: pmc_status |
---|
| 159 | |
---|
| 160 | INTEGER :: i, ierr, istat |
---|
| 161 | INTEGER,DIMENSION(pmc_max_modell+1) :: start_pe |
---|
| 162 | INTEGER :: m_my_cpl_rank |
---|
| 163 | INTEGER :: tag, clientcount |
---|
| 164 | INTEGER,DIMENSION(pmc_max_modell) :: activeserver ! I am active server for this client ID |
---|
| 165 | |
---|
| 166 | pmc_status = pmc_status_ok |
---|
[1762] | 167 | comm = -1 |
---|
[1797] | 168 | m_world_comm = MPI_COMM_WORLD |
---|
[1764] | 169 | m_my_cpl_id = -1 |
---|
| 170 | clientcount = 0 |
---|
| 171 | activeserver = -1 |
---|
| 172 | start_pe(:) = 0 |
---|
[1762] | 173 | |
---|
[1764] | 174 | CALL MPI_COMM_RANK( MPI_COMM_WORLD, m_world_rank, istat ) |
---|
| 175 | CALL MPI_COMM_SIZE( MPI_COMM_WORLD, m_world_npes, istat ) |
---|
| 176 | ! |
---|
| 177 | !-- Only PE 0 of root model reads |
---|
| 178 | IF ( m_world_rank == 0 ) THEN |
---|
[1762] | 179 | |
---|
[1797] | 180 | CALL read_coupling_layout( nesting_datatransfer_mode, nesting_mode, & |
---|
| 181 | pmc_status ) |
---|
[1762] | 182 | |
---|
[1764] | 183 | IF ( pmc_status /= pmc_no_namelist_found .AND. & |
---|
| 184 | pmc_status /= pmc_namelist_error ) & |
---|
| 185 | THEN |
---|
| 186 | ! |
---|
| 187 | !-- Calculate start PE of every model |
---|
| 188 | start_pe(1) = 0 |
---|
[1791] | 189 | DO i = 2, m_ncpl+1 |
---|
[1779] | 190 | start_pe(i) = start_pe(i-1) + m_couplers(i-1)%npe_total |
---|
[1764] | 191 | ENDDO |
---|
[1762] | 192 | |
---|
[1764] | 193 | ! |
---|
| 194 | !-- The number of cores provided with the run must be the same as the |
---|
| 195 | !-- total sum of cores required by all nest domains |
---|
[1791] | 196 | IF ( start_pe(m_ncpl+1) /= m_world_npes ) THEN |
---|
[1779] | 197 | WRITE ( message_string, '(A,I6,A,I6,A)' ) & |
---|
| 198 | 'nesting-setup requires more MPI procs (', & |
---|
[1791] | 199 | start_pe(m_ncpl+1), ') than provided (', & |
---|
[1779] | 200 | m_world_npes,')' |
---|
| 201 | CALL message( 'pmc_init_model', 'PA0229', 3, 2, 0, 6, 0 ) |
---|
[1764] | 202 | ENDIF |
---|
[1762] | 203 | |
---|
[1764] | 204 | ENDIF |
---|
[1762] | 205 | |
---|
[1764] | 206 | ENDIF |
---|
| 207 | ! |
---|
| 208 | !-- Broadcast the read status. This synchronises all other PEs with PE 0 of |
---|
| 209 | !-- the root model. Without synchronisation, they would not behave in the |
---|
| 210 | !-- correct way (e.g. they would not return in case of a missing NAMELIST) |
---|
| 211 | CALL MPI_BCAST( pmc_status, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1762] | 212 | |
---|
[1764] | 213 | IF ( pmc_status == pmc_no_namelist_found ) THEN |
---|
| 214 | ! |
---|
| 215 | !-- Not a nested run; return the MPI_WORLD communicator |
---|
| 216 | comm = MPI_COMM_WORLD |
---|
| 217 | RETURN |
---|
[1762] | 218 | |
---|
[1764] | 219 | ELSEIF ( pmc_status == pmc_namelist_error ) THEN |
---|
| 220 | ! |
---|
| 221 | !-- Only the root model gives the error message. Others are aborted by the |
---|
| 222 | !-- message-routine with MPI_ABORT. Must be done this way since myid and |
---|
| 223 | !-- comm2d have not yet been assigned at this point. |
---|
| 224 | IF ( m_world_rank == 0 ) THEN |
---|
| 225 | message_string = 'errors in \$nestpar' |
---|
| 226 | CALL message( 'pmc_init_model', 'PA0223', 3, 2, 0, 6, 0 ) |
---|
| 227 | ENDIF |
---|
[1762] | 228 | |
---|
[1764] | 229 | ENDIF |
---|
[1762] | 230 | |
---|
[1791] | 231 | CALL MPI_BCAST( m_ncpl, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat) |
---|
| 232 | CALL MPI_BCAST( start_pe, m_ncpl+1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat) |
---|
[1762] | 233 | |
---|
[1764] | 234 | ! |
---|
| 235 | !-- Broadcast coupling layout |
---|
[1791] | 236 | DO i = 1, m_ncpl |
---|
[1764] | 237 | CALL MPI_BCAST( m_couplers(i)%name, LEN( m_couplers(i)%name ), MPI_CHARACTER, 0, MPI_COMM_WORLD, istat ) |
---|
| 238 | CALL MPI_BCAST( m_couplers(i)%id, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
| 239 | CALL MPI_BCAST( m_couplers(i)%Parent_id, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1779] | 240 | CALL MPI_BCAST( m_couplers(i)%npe_total, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1764] | 241 | CALL MPI_BCAST( m_couplers(i)%lower_left_x, 1, MPI_REAL, 0, MPI_COMM_WORLD, istat ) |
---|
| 242 | CALL MPI_BCAST( m_couplers(i)%lower_left_y, 1, MPI_REAL, 0, MPI_COMM_WORLD, istat ) |
---|
| 243 | ENDDO |
---|
[1882] | 244 | CALL MPI_BCAST( nesting_mode, LEN( nesting_mode ), MPI_CHARACTER, 0, MPI_COMM_WORLD, istat ) |
---|
| 245 | CALL MPI_BCAST( nesting_datatransfer_mode, LEN(nesting_datatransfer_mode), MPI_CHARACTER, 0, MPI_COMM_WORLD, istat ) |
---|
[1762] | 246 | |
---|
[1764] | 247 | ! |
---|
| 248 | !-- Assign global MPI processes to individual models by setting the couple id |
---|
[1791] | 249 | DO i = 1, m_ncpl |
---|
[1764] | 250 | IF ( m_world_rank >= start_pe(i) .AND. m_world_rank < start_pe(i+1) ) & |
---|
| 251 | THEN |
---|
| 252 | m_my_cpl_id = i |
---|
| 253 | EXIT |
---|
| 254 | ENDIF |
---|
| 255 | ENDDO |
---|
| 256 | m_my_cpl_rank = m_world_rank - start_pe(i) |
---|
[1762] | 257 | |
---|
[1764] | 258 | ! |
---|
| 259 | !-- MPI_COMM_WORLD is the communicator for ALL models (MPI-1 approach). |
---|
| 260 | !-- The communictors for the individual models as created by MPI_COMM_SPLIT. |
---|
| 261 | !-- The color of the model is represented by the coupler id |
---|
| 262 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, m_my_cpl_id, m_my_cpl_rank, comm, & |
---|
| 263 | istat ) |
---|
| 264 | ! |
---|
| 265 | !-- Get size and rank of the model running on this PE |
---|
| 266 | CALL MPI_COMM_RANK( comm, m_model_rank, istat ) |
---|
| 267 | CALL MPI_COMM_SIZE( comm, m_model_npes, istat ) |
---|
[1762] | 268 | |
---|
[1764] | 269 | ! |
---|
| 270 | !-- Broadcast (from PE 0) the parent id and id of every model |
---|
[1791] | 271 | DO i = 1, m_ncpl |
---|
[1764] | 272 | CALL MPI_BCAST( m_couplers(i)%parent_id, 1, MPI_INTEGER, 0, & |
---|
| 273 | MPI_COMM_WORLD, istat ) |
---|
| 274 | CALL MPI_BCAST( m_couplers(i)%id, 1, MPI_INTEGER, 0, & |
---|
| 275 | MPI_COMM_WORLD, istat ) |
---|
| 276 | ENDDO |
---|
[1762] | 277 | |
---|
[1764] | 278 | ! |
---|
[1779] | 279 | !-- Save the current model communicator for PMC internal use |
---|
[1762] | 280 | m_model_comm = comm |
---|
| 281 | |
---|
[1764] | 282 | ! |
---|
| 283 | !-- Create intercommunicator between server and clients. |
---|
| 284 | !-- MPI_INTERCOMM_CREATE creates an intercommunicator between 2 groups of |
---|
| 285 | !-- different colors. |
---|
| 286 | !-- The grouping was done above with MPI_COMM_SPLIT |
---|
[1791] | 287 | DO i = 2, m_ncpl |
---|
[1762] | 288 | |
---|
[1764] | 289 | IF ( m_couplers(i)%parent_id == m_my_cpl_id ) THEN |
---|
| 290 | ! |
---|
[1779] | 291 | !-- Collect server PEs. |
---|
| 292 | !-- Every model exept the root model has a parent model which acts as |
---|
| 293 | !-- server model. Create an intercommunicator to connect current PE to |
---|
| 294 | !-- all client PEs |
---|
[1764] | 295 | tag = 500 + i |
---|
| 296 | CALL MPI_INTERCOMM_CREATE( comm, 0, MPI_COMM_WORLD, start_pe(i), & |
---|
| 297 | tag, m_to_client_comm(i), istat) |
---|
| 298 | clientcount = clientcount + 1 |
---|
| 299 | activeserver(i) = 1 |
---|
[1762] | 300 | |
---|
[1764] | 301 | ELSEIF ( i == m_my_cpl_id) THEN |
---|
| 302 | ! |
---|
[1779] | 303 | !-- Collect client PEs. |
---|
| 304 | !-- Every model exept the root model has a paremt model which acts as |
---|
| 305 | !-- server model. Create an intercommunicator to connect current PE to |
---|
| 306 | !-- all server PEs |
---|
[1764] | 307 | tag = 500 + i |
---|
| 308 | CALL MPI_INTERCOMM_CREATE( comm, 0, MPI_COMM_WORLD, & |
---|
| 309 | start_pe(m_couplers(i)%parent_id), & |
---|
| 310 | tag, m_to_server_comm, istat ) |
---|
| 311 | ENDIF |
---|
[1762] | 312 | |
---|
[1764] | 313 | ENDDO |
---|
[1762] | 314 | |
---|
[1764] | 315 | ! |
---|
| 316 | !-- If I am server, count the number of clients that I have |
---|
| 317 | !-- Although this loop is symmetric on all processes, the "activeserver" flag |
---|
| 318 | !-- is true (==1) on the respective individual PE only. |
---|
| 319 | ALLOCATE( pmc_server_for_client(clientcount+1) ) |
---|
[1762] | 320 | |
---|
[1764] | 321 | clientcount = 0 |
---|
[1791] | 322 | DO i = 2, m_ncpl |
---|
[1764] | 323 | IF ( activeserver(i) == 1 ) THEN |
---|
| 324 | clientcount = clientcount + 1 |
---|
| 325 | pmc_server_for_client(clientcount) = i |
---|
| 326 | ENDIF |
---|
| 327 | ENDDO |
---|
| 328 | ! |
---|
| 329 | !-- Get the size of the server model |
---|
| 330 | IF ( m_my_cpl_id > 1 ) THEN |
---|
| 331 | CALL MPI_COMM_REMOTE_SIZE( m_to_server_comm, m_server_remote_size, & |
---|
| 332 | istat) |
---|
| 333 | ELSE |
---|
| 334 | ! |
---|
| 335 | !-- The root model does not have a server |
---|
| 336 | m_server_remote_size = -1 ! |
---|
| 337 | ENDIF |
---|
| 338 | ! |
---|
| 339 | !-- Set myid to non-tero value except for the root domain. This is a setting |
---|
| 340 | !-- for the message routine which is called at the end of pmci_init. That |
---|
| 341 | !-- routine outputs messages for myid = 0, only. However, myid has not been |
---|
| 342 | !-- assigened so far, so that all PEs of the root model would output a |
---|
| 343 | !-- message. To avoid this, set myid to some other value except for PE0 of the |
---|
| 344 | !-- root domain. |
---|
| 345 | IF ( m_world_rank /= 0 ) myid = 1 |
---|
[1762] | 346 | |
---|
| 347 | END SUBROUTINE PMC_init_model |
---|
| 348 | |
---|
| 349 | |
---|
[1764] | 350 | ! |
---|
[1791] | 351 | !-- Provide module private variables of the pmc for PALM |
---|
[1797] | 352 | SUBROUTINE pmc_get_model_info( comm_world_nesting, cpl_id, cpl_name, & |
---|
| 353 | cpl_parent_id, lower_left_x, lower_left_y, & |
---|
| 354 | ncpl, npe_total, request_for_cpl_id ) |
---|
[1762] | 355 | |
---|
[1764] | 356 | USE kinds |
---|
[1762] | 357 | |
---|
[1764] | 358 | IMPLICIT NONE |
---|
[1762] | 359 | |
---|
[1764] | 360 | CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: cpl_name |
---|
[1762] | 361 | |
---|
[1791] | 362 | INTEGER, INTENT(IN), OPTIONAL :: request_for_cpl_id |
---|
[1762] | 363 | |
---|
[1797] | 364 | INTEGER, INTENT(OUT), OPTIONAL :: comm_world_nesting |
---|
[1791] | 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 | |
---|
[1791] | 370 | INTEGER :: requested_cpl_id |
---|
[1764] | 371 | |
---|
[1791] | 372 | REAL(wp), INTENT(OUT), OPTIONAL :: lower_left_x |
---|
| 373 | REAL(wp), INTENT(OUT), OPTIONAL :: lower_left_y |
---|
[1764] | 374 | |
---|
[1791] | 375 | ! |
---|
| 376 | !-- Set the requested coupler id |
---|
| 377 | IF ( PRESENT( request_for_cpl_id ) ) THEN |
---|
| 378 | requested_cpl_id = request_for_cpl_id |
---|
| 379 | ! |
---|
| 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 |
---|
| 385 | |
---|
| 386 | ! |
---|
| 387 | !-- Return the requested information |
---|
[1797] | 388 | IF ( PRESENT( comm_world_nesting ) ) THEN |
---|
| 389 | comm_world_nesting = m_world_comm |
---|
| 390 | ENDIF |
---|
[1791] | 391 | IF ( PRESENT( cpl_id ) ) THEN |
---|
[1797] | 392 | cpl_id = requested_cpl_id |
---|
[1791] | 393 | ENDIF |
---|
| 394 | IF ( PRESENT( cpl_parent_id ) ) THEN |
---|
| 395 | cpl_parent_id = m_couplers(requested_cpl_id)%parent_id |
---|
| 396 | ENDIF |
---|
| 397 | IF ( PRESENT( cpl_name ) ) THEN |
---|
[1797] | 398 | cpl_name = m_couplers(requested_cpl_id)%name |
---|
[1791] | 399 | ENDIF |
---|
| 400 | IF ( PRESENT( ncpl ) ) THEN |
---|
[1797] | 401 | ncpl = m_ncpl |
---|
[1791] | 402 | ENDIF |
---|
| 403 | IF ( PRESENT( npe_total ) ) THEN |
---|
[1797] | 404 | npe_total = m_couplers(requested_cpl_id)%npe_total |
---|
[1791] | 405 | ENDIF |
---|
| 406 | IF ( PRESENT( lower_left_x ) ) THEN |
---|
[1797] | 407 | lower_left_x = m_couplers(requested_cpl_id)%lower_left_x |
---|
[1791] | 408 | ENDIF |
---|
| 409 | IF ( PRESENT( lower_left_y ) ) THEN |
---|
[1797] | 410 | lower_left_y = m_couplers(requested_cpl_id)%lower_left_y |
---|
[1791] | 411 | ENDIF |
---|
| 412 | |
---|
| 413 | END SUBROUTINE pmc_get_model_info |
---|
| 414 | |
---|
| 415 | |
---|
| 416 | |
---|
[1764] | 417 | LOGICAL function pmc_is_rootmodel( ) |
---|
| 418 | |
---|
| 419 | IMPLICIT NONE |
---|
| 420 | |
---|
| 421 | pmc_is_rootmodel = ( m_my_cpl_id == 1 ) |
---|
| 422 | |
---|
| 423 | END FUNCTION pmc_is_rootmodel |
---|
| 424 | |
---|
| 425 | |
---|
| 426 | |
---|
[1797] | 427 | SUBROUTINE read_coupling_layout( nesting_datatransfer_mode, nesting_mode, & |
---|
| 428 | pmc_status ) |
---|
[1762] | 429 | |
---|
[1764] | 430 | IMPLICIT NONE |
---|
[1762] | 431 | |
---|
[1797] | 432 | CHARACTER(LEN=7), INTENT(INOUT) :: nesting_mode |
---|
| 433 | CHARACTER(LEN=7), INTENT(INOUT) :: nesting_datatransfer_mode |
---|
[1764] | 434 | |
---|
| 435 | INTEGER, INTENT(INOUT) :: pmc_status |
---|
[1791] | 436 | INTEGER :: i, istat |
---|
[1764] | 437 | |
---|
| 438 | TYPE(pmc_layout), DIMENSION(pmc_max_modell) :: domain_layouts |
---|
| 439 | |
---|
[1882] | 440 | !-- TO_DO: include anterp_relax_length_? into nestpar and communicate them. |
---|
[1797] | 441 | NAMELIST /nestpar/ domain_layouts, nesting_datatransfer_mode, nesting_mode |
---|
[1764] | 442 | |
---|
| 443 | ! |
---|
| 444 | !-- Initialize some coupling variables |
---|
| 445 | domain_layouts(1:pmc_max_modell)%id = -1 |
---|
[1791] | 446 | m_ncpl = 0 |
---|
[1762] | 447 | |
---|
[1764] | 448 | pmc_status = pmc_status_ok |
---|
| 449 | |
---|
| 450 | ! |
---|
| 451 | !-- Open the NAMELIST-file and read the nesting layout |
---|
| 452 | CALL check_open( 11 ) |
---|
| 453 | READ ( 11, nestpar, IOSTAT=istat ) |
---|
| 454 | |
---|
| 455 | IF ( istat < 0 ) THEN |
---|
| 456 | ! |
---|
| 457 | !-- No nestpar-NAMELIST found |
---|
| 458 | pmc_status = pmc_no_namelist_found |
---|
| 459 | ! |
---|
| 460 | !-- Set filepointer to the beginning of the file. Otherwise PE0 will later |
---|
| 461 | !-- be unable to read the inipar-NAMELIST |
---|
| 462 | REWIND ( 11 ) |
---|
[1762] | 463 | RETURN |
---|
| 464 | |
---|
[1764] | 465 | ELSEIF ( istat > 0 ) THEN |
---|
| 466 | ! |
---|
| 467 | !-- Errors in reading nestpar-NAMELIST |
---|
| 468 | pmc_status = pmc_namelist_error |
---|
| 469 | RETURN |
---|
[1762] | 470 | |
---|
[1764] | 471 | ENDIF |
---|
[1762] | 472 | |
---|
[1764] | 473 | ! |
---|
| 474 | !-- Output location message |
---|
| 475 | CALL location_message( 'initialize communicators for nesting', .FALSE. ) |
---|
| 476 | ! |
---|
| 477 | !-- Assign the layout to the internally used variable |
---|
| 478 | m_couplers = domain_layouts |
---|
[1762] | 479 | |
---|
[1764] | 480 | ! |
---|
| 481 | !-- Get the number of nested models given in the nestpar-NAMELIST |
---|
| 482 | DO i = 1, pmc_max_modell |
---|
| 483 | ! |
---|
[1791] | 484 | !-- When id=-1 is found for the first time, the list of domains is finished |
---|
| 485 | IF ( m_couplers(i)%id == -1 .OR. i == pmc_max_modell ) THEN |
---|
| 486 | IF ( m_couplers(i)%id == -1 ) THEN |
---|
| 487 | m_ncpl = i - 1 |
---|
| 488 | EXIT |
---|
| 489 | ELSE |
---|
| 490 | m_ncpl = pmc_max_modell |
---|
| 491 | ENDIF |
---|
[1764] | 492 | ENDIF |
---|
| 493 | |
---|
| 494 | ENDDO |
---|
| 495 | |
---|
| 496 | END SUBROUTINE read_coupling_layout |
---|
| 497 | |
---|
| 498 | #endif |
---|
| 499 | END MODULE pmc_handle_communicator |
---|