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