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