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