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