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