-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpl_comm_mod.F90.withoutMPH
executable file
·432 lines (368 loc) · 16.7 KB
/
cpl_comm_mod.F90.withoutMPH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
!===============================================================================
! CVS: $Id: cpl_comm_mod.F90,v 1.2 2003/11/22 00:27:04 tcraig Exp $
! CVS: $Source: /fs/cgd/csm/models/CVS.REPOS/shared/csm_share/cpl/cpl_comm_mod.F90,v $
! CVS: $Name: ccsm3_0_rel04 $
!===============================================================================
!BOP ===========================================================================
!
! !MODULE: cpl_comm_mod -- "communicator module" defines comm groups and model ID's
!
! !DESCRIPTION:
! Sets up communicator groups and MPH component ID's (cid).
! Also declares and defines handy data wrt number of pe's, PID's, CID's
! relative to world and component communicator groups.
!
! !REVISION HISTORY:
! 2001-Aug-20 - B. Kauffman - new naming convention
! 2001-Mar-20 - T. Craig, B. Kauffman, R. Jacob - first prototype
!
! !INTERFACE: ------------------------------------------------------------------
module cpl_comm_mod
! !USES:
use cpl_kind_mod ! kinds
use shr_sys_mod ! system calls
use shr_mpi_mod ! mpi layer
implicit none
private ! except
! !PUBLIC TYPES:
! none
! !PUBLIC MEMBER FUNCTIONS:
public :: cpl_comm_init
! msteder
public :: cpl_comm_init_wo_mph
! !PUBLIC DATA MEMBERS:
integer(IN),public :: cpl_comm_wrld ! = MPI_COMM_WORLD, global comm grp
integer(IN),public :: cpl_comm_wrld_npe ! number of pe's in MPI_COMM_WORLD
integer(IN),public :: cpl_comm_wrld_pid ! this comp pid in MPI_COMM_WORLD
integer(IN),public :: cpl_comm_comp ! this comp communicator group
integer(IN),public :: cpl_comm_comp_npe ! number of pe's in comp comm group
integer(IN),public :: cpl_comm_comp_pid ! this comp's pid in comp comm group
integer(IN),public :: cpl_comm_mph_cid ! MPH component ID, this component
integer(IN),public :: cpl_comm_mph_cid_atm ! MPH component ID, atm
integer(IN),public :: cpl_comm_mph_cid_ice ! MPH component ID, ice
integer(IN),public :: cpl_comm_mph_cid_lnd ! MPH component ID, lnd
integer(IN),public :: cpl_comm_mph_cid_ocn ! MPH component ID, ocn
integer(IN),public :: cpl_comm_mph_cid_cpl ! MPH component ID, cpl
integer(IN),public :: cpl_comm_wrld_pe0 ! comm world pe0, this component
integer(IN),public :: cpl_comm_wrld_pe0_atm ! comm world pe0, atm
integer(IN),public :: cpl_comm_wrld_pe0_ice ! comm world pe0, ice
integer(IN),public :: cpl_comm_wrld_pe0_lnd ! comm world pe0, lnd
integer(IN),public :: cpl_comm_wrld_pe0_ocn ! comm world pe0, ocn
integer(IN),public :: cpl_comm_wrld_pe0_cpl ! comm world pe0, cpl
!EOP
save
character(*),parameter :: modName = 'cpl_comm_mod'
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
contains
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!===============================================================================
!BOP ===========================================================================
!
! !IROUTINE: cpl_comm_init -- initialize the coupling/mpi environment.
!
! !DESCRIPTION:
! This routine calls mpi\_init, establishes coupled component communicator
! groups, coupled component id's, and pid's relative to world and component
! communicator groups.
!
! !REMARKS:
!
! !REVISION HISTORY:
! 2001-Mar-20 - T. Craig, B. Kauffman, R. Jacob -- first prototype
! 2001-Dec-10 - R. Jacob -- switch arguments in cpl_mct_world_init to
! to match new version
!
! !INTERFACE: ------------------------------------------------------------------
subroutine cpl_comm_init(name,comm)
! !USES:
use cpl_fields_mod ! contains valid component name strings
use mph_module,only : mph_components
use mph_module,only : mph_global_proc_id
use mph_module,only : mph_local_proc_id
use mph_module,only : mph_total_components
use mph_module,only : mph_comp_id
use mph_module,only : mph_local_totprocs
use mph_module,only : mph_global_totprocs
use mph_module,only : mph_global_id
use mph_module,only : mph_comp_name
use mph_module,only : mph_global_world
use m_MCTWorld ,only : cpl_mct_world_init => init
implicit none
! !INPUT/OUTPUT PARAMETERS:
character(*),intent(in) :: name ! name of component name
integer(IN) ,intent(out) :: comm ! communicator group for component
!EOP
integer(IN) :: n ! generic loop index
!----- formats -----
character(*),parameter :: subname = "(cpl_comm_init) "
character(*),parameter :: F00 = "('(cpl_comm_init) ',4a)"
character(*),parameter :: F02 = "('(cpl_comm_init) ',a,6i4)"
!-------------------------------------------------------------------------------
!
!-------------------------------------------------------------------------------
write(6,F00) "setting up communicators, name = ",trim(name)
!--- initialize my local comm group via MPH ---
comm = mph_components(name1=name)
!--- query MPH for my local/global comm info, mph cid ---
cpl_comm_wrld = mph_global_world
cpl_comm_wrld_pid = mph_global_proc_id()
cpl_comm_wrld_npe = mph_global_totprocs()
cpl_comm_wrld_pe0 = mph_global_id(name,0)
cpl_comm_comp = comm
cpl_comm_mph_cid = mph_comp_id(name)
cpl_comm_comp_pid = mph_local_proc_id(cpl_comm_mph_cid)
cpl_comm_comp_npe = mph_local_totprocs(cpl_comm_mph_cid)
call shr_mpi_commsize(cpl_comm_comp,n,subName//" MPI comm size")
write(6,F02) "cpl_comm_comp, size:",cpl_comm_comp,n
!--- determine mph cid's and comm_world pe0's for all components ---
do n=1,mph_total_components()
if (mph_comp_name(n) == cpl_fields_atmname ) then
cpl_comm_mph_cid_atm = n
cpl_comm_wrld_pe0_atm = mph_global_id(cpl_fields_atmname,0)
elseif (mph_comp_name(n) == cpl_fields_icename ) then
cpl_comm_mph_cid_ice = n
cpl_comm_wrld_pe0_ice = mph_global_id(cpl_fields_icename,0)
elseif (mph_comp_name(n) == cpl_fields_lndname ) then
cpl_comm_mph_cid_lnd = n
cpl_comm_wrld_pe0_lnd = mph_global_id(cpl_fields_lndname,0)
elseif (mph_comp_name(n) == cpl_fields_ocnname ) then
cpl_comm_mph_cid_ocn = n
cpl_comm_wrld_pe0_ocn = mph_global_id(cpl_fields_ocnname,0)
elseif (mph_comp_name(n) == cpl_fields_cplname ) then
cpl_comm_mph_cid_cpl = n
cpl_comm_wrld_pe0_cpl = mph_global_id(cpl_fields_cplname,0)
else
write(6,*) subName,'mph_component_name error',n,mph_comp_name(n)
call shr_sys_abort(subName//'mph_component_name error')
endif
enddo
!--- initialize MCT ---
call cpl_mct_world_init(mph_total_components(),cpl_comm_wrld,cpl_comm_comp,cpl_comm_mph_cid)
!--- document comm groups, pe0's, mph component ids ---
write(6,F02) 'comm world : comm,npe,pid ', &
& cpl_comm_wrld,cpl_comm_wrld_npe,cpl_comm_wrld_pid
write(6,F02) 'comm component: comm,npe,pid ', &
& cpl_comm_comp,cpl_comm_comp_npe,cpl_comm_comp_pid
write(6,F02) 'comm world pe0: atm,ice,lnd,ocn,cpl,me ', &
& cpl_comm_wrld_pe0_atm,cpl_comm_wrld_pe0_ice,cpl_comm_wrld_pe0_lnd, &
& cpl_comm_wrld_pe0_ocn,cpl_comm_wrld_pe0_cpl,cpl_comm_wrld_pe0
write(6,F02) 'mph cid : atm,ice,lnd,ocn,cpl,me ', &
& cpl_comm_mph_cid_atm ,cpl_comm_mph_cid_ice ,cpl_comm_mph_cid_lnd , &
& cpl_comm_mph_cid_ocn ,cpl_comm_mph_cid_cpl ,cpl_comm_mph_cid
end subroutine cpl_comm_init
!===============================================================================
!===============================================================================
!===============================================================================
!BOP ===========================================================================
!
! !IROUTINE: cpl_comm_init -- initialize the coupling/mpi environment.
!
! !DESCRIPTION:
! This routine calls mpi\_init, establishes coupled component communicator
! groups, coupled component id's, and pid's relative to world and component
! communicator groups.
!
! !REMARKS:
!
! !REVISION HISTORY:
! 2001-Mar-20 - T. Craig, B. Kauffman, R. Jacob -- first prototype
! 2001-Dec-10 - R. Jacob -- switch arguments in cpl_mct_world_init to
! to match new version
!
! !INTERFACE: ------------------------------------------------------------------
subroutine cpl_comm_init_wo_mph(name,comm)
! !USES:
use shr_sys_mod,only : shr_sys_flush
use cpl_fields_mod ! contains valid component name strings
use mph_module,only : mph_components
use mph_module,only : mph_global_proc_id
use mph_module,only : mph_local_proc_id
use mph_module,only : mph_total_components
use mph_module,only : mph_comp_id
use mph_module,only : mph_local_totprocs
use mph_module,only : mph_global_totprocs
use mph_module,only : mph_global_id
use mph_module,only : mph_comp_name
use mph_module,only : mph_global_world
use m_MCTWorld ,only : cpl_mct_world_init => init
implicit none
! MPI INCLUDE:
#if ( ! defined HIDE_MPI )
#include <mpif.h>
#endif
! !INPUT/OUTPUT PARAMETERS:
character(*),intent(in) :: name ! name of component name
integer(IN) ,intent(out) :: comm ! communicator group for component
!EOP
integer(IN) :: n ! generic loop index
integer(IN) :: ierr ! error flag to pass to and from MPI routines
integer(IN) :: ncomponents ! number of components
integer(IN) :: local_rank, local_size,world_rank,world_size !
integer(IN) :: temp_rank, temp_size
integer(IN) :: cpl_comm_root_comm
!----- formats -----
character(*),parameter :: subname = "(cpl_comm_init) "
character(*),parameter :: F00 = "('(cpl_comm_init) ',4a)"
character(*),parameter :: F02 = "('(cpl_comm_init) ',a,6i4)"
!-------------------------------------------------------------------------------
!
!-------------------------------------------------------------------------------
call mpi_init(ierr)
write(6,F00) "setting up communicators, name = ",trim(name)
call shr_sys_flush(6)
!--- Initialize local comm groups using Comm Split:
write(6,F00) trim(name),": initializing comm groups..."
call shr_sys_flush(6)
name = trim(name)
ncomponents = 0
cpl_comm_mph_cid_cpl = 1
cpl_comm_mph_cid_atm = 2
cpl_comm_mph_cid_ocn = 3
cpl_comm_mph_cid_ice = 4
cpl_comm_mph_cid_lnd = 5
if ( name .eq. "cpl" ) then
cpl_comm_mph_cid = 1
call MPI_COMM_SPLIT( MPI_COMM_WORLD, 0, 0, comm, ierr )
elseif ( name .eq. "atm" ) then
cpl_comm_mph_cid = 2
call MPI_COMM_SPLIT( MPI_COMM_WORLD, 1, 0, comm, ierr )
elseif ( name .eq. "ocn" ) then
cpl_comm_mph_cid = 3
call MPI_COMM_SPLIT( MPI_COMM_WORLD, 2, 0, comm, ierr )
elseif ( name .eq. "ice" ) then
cpl_comm_mph_cid = 4
call MPI_COMM_SPLIT( MPI_COMM_WORLD, 3, 0, comm, ierr )
elseif ( name .eq. "lnd" ) then
cpl_comm_mph_cid = 5
call MPI_COMM_SPLIT( MPI_COMM_WORLD, 4, 0, comm, ierr )
end if
write(6,F00) trim(name), ": Comm groups initialized!"
call shr_sys_flush(6)
! Get local rank and size:
call MPI_COMM_RANK( comm, local_rank, ierr )
call MPI_COMM_SIZE( comm, local_size, ierr )
write(6,F00) trim(name), ": Creating Root Communicator..."
call shr_sys_flush(6)
if ( local_rank .eq. 0 ) then
call MPI_COMM_SPLIT( MPI_COMM_WORLD, 5, 0, cpl_comm_root_comm, ierr )
call MPI_COMM_SIZE( cpl_comm_root_comm, ncomponents, ierr )
else
call MPI_COMM_SPLIT( MPI_COMM_WORLD, 6, 0, cpl_comm_root_comm, ierr )
ncomponents = 0
end if
write(6,F00) trim(name), ": Distributing Root Communicator..."
call shr_sys_flush(6)
call MPI_BCAST( ncomponents, 1, MPI_INTEGER, 0, comm, ierr )
if( local_rank .eq. 0 ) then
! Verify cpl_comm_root_comm is okay:
call MPI_COMM_RANK( cpl_comm_root_comm, temp_rank, ierr )
call MPI_COMM_SIZE( cpl_comm_root_comm, temp_rank, ierr )
endif
!--- query MPH for my local/global comm info, mph cid ---
!cpl_comm_wrld = mph_global_world
cpl_comm_wrld = MPI_COMM_WORLD
!cpl_comm_wrld_pid = mph_global_proc_id()
call MPI_COMM_RANK( MPI_COMM_WORLD, cpl_comm_wrld_pid, ierr )
!cpl_comm_wrld_npe = mph_global_totprocs()
call MPI_COMM_SIZE( MPI_COMM_WORLD, cpl_comm_wrld_npe, ierr )
!cpl_comm_wrld_pe0 = mph_global_id(name,0)
write(6,*) "ncomponents =",ncomponents
! we've already broadcasted root_comm to all processors
! so after the above MPI_COMM_SIZE call we shouldn't have
! to broadcast ncomponents.
!call MPI_BCAST( ncomponents, 1, MPI_INTEGER, 0, comm, ierr )
write (6,*) "1 of",ncomponents,"components!"
cpl_comm_comp = comm
!cpl_comm_comp_pid = mph_local_proc_id(cpl_comm_mph_cid)
call MPI_COMM_RANK( comm, cpl_comm_comp_pid, ierr )
!cpl_comm_comp_npe = mph_local_totprocs(cpl_comm_mph_cid)
cpl_comm_comp_npe = local_size
!call shr_mpi_commsize(cpl_comm_comp,n,subName//" MPI comm size")
write(6,*) "rank:",local_rank
write(6,*) "cpl_comm_comp, size:",cpl_comm_comp,local_size
call shr_sys_flush(6)
!--- determine mph cid's and comm_world pe0's for all components
!--- Component ID's were simply hardcoded earlier when we created
!--- Local communicators for each component.
!--- comm_world pe0's still have to be assigned.
write(6,*) ": setting remaining Component values..."
cpl_comm_wrld_pe0_cpl = 0
cpl_comm_wrld_pe0_atm = 0
cpl_comm_wrld_pe0_ocn = 0
cpl_comm_wrld_pe0_ice = 0
cpl_comm_wrld_pe0_lnd = 0
cpl_comm_wrld_pe0 = 0
!--- If we do a global allreduce, the value left in each of these variables
!--- should be correct.
call MPI_COMM_SIZE( MPI_COMM_WORLD, world_size, ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, world_rank, ierr )
if( trim(name) .eq. "cpl" ) then
if ( local_rank .eq. 0 ) then
cpl_comm_wrld_pe0_cpl = world_rank
cpl_comm_wrld_pe0 = world_rank
end if
end if
if( trim(name) .eq. "atm" ) then
if ( local_rank .eq. 0 ) then
cpl_comm_wrld_pe0_atm = world_rank
cpl_comm_wrld_pe0 = world_rank
end if
end if
if( trim(name) .eq. "ocn" ) then
if ( local_rank .eq. 0 ) then
cpl_comm_wrld_pe0_ocn = world_rank
cpl_comm_wrld_pe0 = world_rank
end if
end if
if( trim(name) .eq. "ice" ) then
if ( local_rank .eq. 0 ) then
cpl_comm_wrld_pe0_ice = world_rank
cpl_comm_wrld_pe0 = world_rank
end if
end if
if( trim(name) .eq. "lnd" ) then
if ( local_rank .eq. 0 ) then
cpl_comm_wrld_pe0_lnd = world_rank
cpl_comm_wrld_pe0 = world_rank
end if
end if
write(6,F00) "Assigning Root Processors..."
call MPI_Allreduce( cpl_comm_wrld_pe0_cpl, cpl_comm_wrld_pe0_cpl, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, ierr )
call MPI_Allreduce( cpl_comm_wrld_pe0_atm, cpl_comm_wrld_pe0_atm, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, ierr )
call MPI_Allreduce( cpl_comm_wrld_pe0_ocn, cpl_comm_wrld_pe0_ocn, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, ierr )
call MPI_Allreduce( cpl_comm_wrld_pe0_ice, cpl_comm_wrld_pe0_ice, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, ierr )
call MPI_Allreduce( cpl_comm_wrld_pe0_lnd, cpl_comm_wrld_pe0_lnd, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, ierr )
! Assign this to all processors of a single component
call MPI_Allreduce( cpl_comm_wrld_pe0, cpl_comm_wrld_pe0, 1, MPI_INTEGER, MPI_SUM, cpl_comm_comp, ierr )
!--- initialize MCT ---
write(6,F00) "Initializing MCT World:"
call shr_sys_flush(6)
write(6,*) "ncomponents=",ncomponents
write(6,*) "cpl_comm_wrld=",cpl_comm_wrld
write(6,*) "cpl_comm_comp=",cpl_comm_comp
write(6,*) "cpl_comm_mph_cid=",cpl_comm_mph_cid
write(6,F00) "Getting size of cpl_comm_wrld(yes, wrld):"
call shr_sys_flush(6)
call MPI_COMM_SIZE( cpl_comm_wrld, temp_size, ierr )
write(6,F00) "Getting size of cpl_comm_comp:"
call shr_sys_flush(6)
call MPI_COMM_SIZE( cpl_comm_comp, temp_size, ierr )
write(6,F00) "Calling cpl_mct_world_init:"
call shr_sys_flush(6)
call cpl_mct_world_init(ncomponents,MPI_COMM_WORLD,comm,cpl_comm_mph_cid)
write(6,F00) "Initialized!"
call shr_sys_flush(6)
!--- document comm groups, pe0's, mph component ids ---
write(6,F02) 'comm world : comm,npe,pid ', &
& cpl_comm_wrld,cpl_comm_wrld_npe,cpl_comm_wrld_pid
write(6,F02) 'comm component: comm,npe,pid ', &
& cpl_comm_comp,cpl_comm_comp_npe,cpl_comm_comp_pid
write(6,F02) 'comm world pe0: atm,ice,lnd,ocn,cpl,me ', &
& cpl_comm_wrld_pe0_atm,cpl_comm_wrld_pe0_ice,cpl_comm_wrld_pe0_lnd, &
& cpl_comm_wrld_pe0_ocn,cpl_comm_wrld_pe0_cpl,cpl_comm_wrld_pe0
write(6,F02) 'mph cid : atm,ice,lnd,ocn,cpl,me ', &
& cpl_comm_mph_cid_atm ,cpl_comm_mph_cid_ice ,cpl_comm_mph_cid_lnd , &
& cpl_comm_mph_cid_ocn ,cpl_comm_mph_cid_cpl ,cpl_comm_mph_cid
call shr_sys_flush(6)
end subroutine cpl_comm_init_wo_mph
end module cpl_comm_mod