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