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