Skip to content

Commit bad7c41

Browse files
committed
1st work version for scribeIO
1 parent 0a25e77 commit bad7c41

4 files changed

Lines changed: 142 additions & 22 deletions

File tree

schism_pdaf.F90

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ program main
3737

3838
use esmf
3939
use schism_esmf_cap, only: schismSetServices => SetServices
40-
use schism_msgp, only: nscribes !parallel_abort,myrank
40+
use schism_msgp, only: nscribes,task_id !parallel_abort,myrank
4141
! use schism_glbl, only: errmsg,tr_el
4242
! USE mod_assimilation, & ! Variables for assimilation
4343
! ONLY: filtertype
@@ -167,13 +167,14 @@ program main
167167
!Define mode (full_para o flex)
168168
if(concurrentCount==schismCount) then
169169
full_para=1
170-
if(nscribes<=0) then
170+
if(nscribes>=0) then
171171
write (message, '(A,I4)') 'Use scribe IO for full para mode:',nscribes
172172
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
173173
endif
174174
else !flex mode
175175
full_para=0
176176
if(nscribes/=0) then
177+
nscribes=0 !Force to reset 0
177178
write (message, '(A,I4)') 'Use OLDIO for flex mode:',nscribes
178179
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
179180
endif
@@ -401,11 +402,17 @@ program main
401402
! write(0, *) 'Before init_parelle_pdaf'
402403
call init_parallel_pdaf(0, 1, schismCount, petCountLocal, concurrentCount)
403404
! write(0, *) 'Before init_pdaf'
404-
call init_pdaf(schismCount, j)
405+
if (task_id==1) then
406+
call init_pdaf(schismCount, j) !Only on compute cores
407+
! write(0, *) 'After init_pdaf'
408+
end if
409+
!j=0 !test for multi-schism, turn off PDAF
405410
#endif
406-
if (j /= 0) then
407-
localrc = ESMF_RC_VAL_OUTOFRANGE
408-
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
411+
if (task_id==1) then !Only on compute cores
412+
if (j /= 0) then
413+
localrc = ESMF_RC_VAL_OUTOFRANGE
414+
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
415+
end if
409416
end if
410417

411418
! Loop over coupling timesteps until stopTime
@@ -537,7 +544,7 @@ program main
537544

538545
#ifdef USE_PDAF
539546
! PDAF finalize
540-
call finalize_pdaf()
547+
if (task_id==1) call finalize_pdaf() !Only on compute cores
541548
#endif
542549

543550
do i = 1, schismCount

schism_pdaf.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
schism_count: 8
77
concurrent_count: 4
88
# scribe counter for fully parallel mode
9-
scribe_count : 6
9+
scribe_count: 6

src/PDAF_bindings/init_parallel_pdaf.F90

Lines changed: 116 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SUBROUTINE init_parallel_pdaf(dim_ens, screen,schismCount,petCountLocal,concurre
6262
! Later revisions - see svn log
6363
!
6464
! !USES:
65-
USE schism_msgp, only: comm,parallel_init,myrank,nproc,parallel_abort
65+
USE schism_msgp, only: comm,parallel_init,myrank,nproc,parallel_abort,nscribes,task_id_schism=>task_id
6666
USE mod_parallel_pdaf, &
6767
ONLY: mype_world, npes_world, mype_model, npes_model, &
6868
COMM_model, mype_filter, npes_filter, COMM_filter, filterpe, &
@@ -98,8 +98,12 @@ SUBROUTINE init_parallel_pdaf(dim_ens, screen,schismCount,petCountLocal,concurre
9898
INTEGER :: mype_couple, npes_couple ! Rank and size in COMM_couple
9999
INTEGER :: pe_index ! Index of PE
100100
INTEGER :: my_color, color_couple ! Variables for communicator-splitting
101+
INTEGER :: world_group
101102
LOGICAL :: iniflag ! Flag whether MPI is initialized
102103
CHARACTER(len=32) :: handle ! handle for command line parser
104+
integer,allocatable :: group_ranks(:),group_ranks_final(:)
105+
integer :: group_a,group_b,union_group,comm_pdaf,ihalf_group
106+
integer :: send_burf(2),ic_comm,mype_world2,npes_world2
103107

104108

105109
! *** Initialize MPI if not yet initialized ***
@@ -149,10 +153,12 @@ SUBROUTINE init_parallel_pdaf(dim_ens, screen,schismCount,petCountLocal,concurre
149153
! *** only used to generate model communicators ***
150154
COMM_ensemble = MPI_COMM_WORLD
151155

156+
npes_world = npes_world - n_modeltasks*nscribes !# of PEs - ncribes cores
152157
npes_ens = npes_world !# of PEs
153158
mype_ens = mype_world !local rank
154159

155160

161+
156162
! *** Store # PEs per ensemble ***
157163
! *** used for info on PE 0 and for generation ***
158164
! *** of model communicators on other Pes ***
@@ -175,19 +181,80 @@ SUBROUTINE init_parallel_pdaf(dim_ens, screen,schismCount,petCountLocal,concurre
175181
pe_index = 0
176182
doens1: DO i = 1, n_modeltasks
177183
DO j = 1, local_npes_model(i)
178-
IF (mype_ens == pe_index) THEN
184+
IF ((mype_ens == pe_index).and.(task_id_schism == 1)) THEN
179185
task_id = i !similar to our sequence index (shared among multiple tasks)
180186
EXIT doens1
181187
END IF
182188
pe_index = pe_index + 1
183189
END DO !j
184190
END DO doens1
191+
local_npes_model=local_npes_model-nscribes !Reset to correct number for scribes
185192

186193
!Copy from SCHISM (init'ed under ESMF). May be shared among >1 task
187194
COMM_model=comm
188-
! call mpi_comm_dup(comm,COMM_model,MPIerr)
189195
npes_model=nproc
196+
!if (task_id_schism==1) mype_model=myrank
190197
mype_model=myrank
198+
!write(0,'(a,3i8)') "1. task_id_schism,myrank,mype_world=",task_id_schism,myrank,mype_world
199+
!write(0,'(a,4i8)') "id,nproc,petCountLocal,npes_world = ", mype_model,nproc,petCountLocal, npes_world
200+
201+
!Group comm for scribeIO
202+
if (schismCount.eq.concurrentCount) then !Only full-parallel mode
203+
call MPI_COMM_GROUP(MPI_COMM_WORLD, world_group, MPIerr)
204+
allocate(group_ranks(schismCount*petCountLocal*2)) !Local
205+
allocate(group_ranks_final(schismCount*(petCountLocal-nscribes))) !Local
206+
ihalf_group=schismCount*(petCountLocal-nscribes)/2
207+
group_ranks=0
208+
group_ranks_final=0
209+
send_burf=(/mype_ens,task_id_schism/)
210+
call MPI_ALLGATHER(send_burf, 2, MPI_INTEGER,group_ranks,2,MPI_INTEGER,MPI_COMM_WORLD, MPIerr)
211+
!if (mype_ens==0) write(*,'(a,80(2i4))') 'group_rank:',group_ranks
212+
ic_comm=0
213+
do i=1,schismCount*petCountLocal
214+
if (group_ranks(i*2).eq.1) then !task_id_schism=1
215+
ic_comm=ic_comm+1
216+
group_ranks_final(ic_comm)=group_ranks(i*2-1)
217+
end if
218+
end do
219+
!if (ic_comm.ne.ihalf_group*2) write(*,*) 'ic_comm=', ic_comm,ihalf_group
220+
!write(*,'(a,80(2i4))') 'group_rank_final:',group_ranks_final
221+
222+
!Split into 2 groups for later group_union
223+
!call MPI_GROUP_INCL(world_group, ihalf_group, group_ranks_final(1:ihalf_group), group_a, MPIerr)
224+
!call MPI_GROUP_INCL(world_group, ihalf_group, group_ranks_final(ihalf_group+1:ihalf_group*2), group_b, MPIerr)
225+
call MPI_GROUP_INCL(world_group, ihalf_group*2, group_ranks_final, union_group, MPIerr)
226+
227+
!Union & create new comm
228+
!call MPI_GROUP_UNION(group_a, group_b, union_group, MPIerr)
229+
230+
!Just create new comm with union_group
231+
call MPI_COMM_CREATE(MPI_COMM_WORLD, union_group, comm_pdaf, MPIerr)
232+
!if (MPIerr.eq.0) write(*,*) 'Success create new comm_pdaf!',mype_world
233+
!CALL MPI_Comm_Size(comm_pdaf, npes_world2, MPIerr)
234+
!if (MPIerr.eq.0) write(*,*) 'Success create new npe!',npes_world2,mype_world
235+
236+
!Free group to avoid memory leak
237+
!call MPI_GROUP_FREE(group_a, MPIerr)
238+
!call MPI_GROUP_FREE(group_b, MPIerr)
239+
call MPI_GROUP_FREE(union_group, MPIerr)
240+
call MPI_GROUP_FREE(world_group, MPIerr)
241+
242+
!Re-rank and overwrite original mype_world
243+
if (comm_pdaf /= MPI_COMM_NULL) then
244+
CALL MPI_Comm_rank(comm_pdaf, mype_world2, MPIerr)
245+
!if (MPIerr.eq.0) write(*,*) 'Success create new rank!',mype_world,mype_world2
246+
CALL MPI_Comm_Size(comm_pdaf, npes_world2, MPIerr)
247+
!if (MPIerr.eq.0) write(*,*) 'Success create new rank size!',mype_world,mype_world2,npes_world2
248+
mype_world=mype_world2
249+
CALL MPI_Barrier(comm_pdaf, MPIerr)
250+
else
251+
mype_world=-1 !Force to specify
252+
mype_world2=-1 !Force to specify
253+
end if
254+
255+
!set comm_pdaf for scribeIO
256+
call PDAF_set_comm_pdaf(comm_pdaf) !Set to new comm for all cores
257+
end if
191258

192259
! CALL MPI_Comm_split(COMM_ensemble, task_id, mype_ens, &
193260
! COMM_model, MPIerr)
@@ -216,13 +283,24 @@ SUBROUTINE init_parallel_pdaf(dim_ens, screen,schismCount,petCountLocal,concurre
216283
! *** For simplicity equal to COMM_couple (model?) ***
217284
my_color = task_id !same as model, but only PEs of Task 1 are really used?
218285

219-
CALL MPI_Comm_split(MPI_COMM_WORLD, my_color, mype_world, &
286+
if (schismCount.eq.concurrentCount) then !Only full-parallel mode, scribeIO
287+
if (comm_pdaf /= MPI_COMM_NULL) then !Only for compute cores
288+
CALL MPI_Comm_split(comm_pdaf, my_color, mype_world2, &
289+
COMM_filter, MPIerr)
290+
CALL MPI_Comm_Size(COMM_filter, npes_filter, MPIerr)
291+
CALL MPI_Comm_Rank(COMM_filter, mype_filter, MPIerr)
292+
!write(*,'(a,(3i4))') 'npes_filter, mype_filter:',npes_filter, mype_filter,mype_world2
293+
end if
294+
else
295+
CALL MPI_Comm_split(MPI_COMM_WORLD, my_color, mype_world, &
220296
COMM_filter, MPIerr)
221297

222298
! *** Initialize PE informations ***
223299
! *** according to coupling communicator ***
224-
CALL MPI_Comm_Size(COMM_filter, npes_filter, MPIerr)
225-
CALL MPI_Comm_Rank(COMM_filter, mype_filter, MPIerr)
300+
CALL MPI_Comm_Size(COMM_filter, npes_filter, MPIerr)
301+
CALL MPI_Comm_Rank(COMM_filter, mype_filter, MPIerr)
302+
303+
end if
226304

227305

228306
! *** COMM_COUPLE ***
@@ -232,24 +310,41 @@ SUBROUTINE init_parallel_pdaf(dim_ens, screen,schismCount,petCountLocal,concurre
232310

233311
color_couple = mype_filter + 1 !shift ranks by 1 (not sure why)
234312

235-
CALL MPI_Comm_split(MPI_COMM_WORLD, color_couple, mype_world, &
313+
if (schismCount.eq.concurrentCount) then !Only full-parallel mode, scribeIO
314+
if (comm_pdaf /= MPI_COMM_NULL) then !Only for compute cores
315+
CALL MPI_Comm_split(comm_pdaf, color_couple, mype_world2, &
316+
COMM_couple, MPIerr)
317+
CALL MPI_Comm_Size(COMM_couple, npes_couple, MPIerr)
318+
CALL MPI_Comm_Rank(COMM_couple, mype_couple, MPIerr)
319+
end if
320+
else
321+
CALL MPI_Comm_split(MPI_COMM_WORLD, color_couple, mype_world, &
236322
COMM_couple, MPIerr)
237323

238324
! *** Initialize PE informations ***
239325
! *** according to coupling communicator ***
240-
CALL MPI_Comm_Size(COMM_couple, npes_couple, MPIerr)
241-
CALL MPI_Comm_Rank(COMM_couple, mype_couple, MPIerr)
326+
CALL MPI_Comm_Size(COMM_couple, npes_couple, MPIerr)
327+
CALL MPI_Comm_Rank(COMM_couple, mype_couple, MPIerr)
328+
end if
242329

243330
IF (screen > 0) THEN
244-
CALL MPI_Barrier(MPI_COMM_WORLD, MPIerr)
331+
if (schismCount.eq.concurrentCount) then !Only full-parallel mode, scribeIO
332+
if (comm_pdaf /= MPI_COMM_NULL) CALL MPI_Barrier(comm_pdaf, MPIerr)
333+
else
334+
CALL MPI_Barrier(MPI_COMM_WORLD, MPIerr)
335+
end if
245336
IF (mype_world == 0) THEN
246337
WRITE (*, '(/18x, a)') 'PE configuration:'
247338
WRITE (*, '(2x, a6, a9, a10, a14, a13, /2x, a5, a9, a7, a7, a7, a7, a7, /2x, a)') &
248339
'world', 'filter', 'model', 'couple', 'filterPE', &
249340
'rank', 'rank', 'task', 'rank', 'task', 'rank', 'T/F', &
250341
'----------------------------------------------------------'
251342
END IF
252-
CALL MPI_Barrier(MPI_COMM_WORLD, MPIerr)
343+
if (schismCount.eq.concurrentCount) then !Only full-parallel mode, scribeIO
344+
if (comm_pdaf /= MPI_COMM_NULL) CALL MPI_Barrier(comm_pdaf, MPIerr)
345+
else
346+
CALL MPI_Barrier(MPI_COMM_WORLD, MPIerr)
347+
end if
253348
IF (task_id == 1) THEN
254349
WRITE (*, '(2x, i4, 4x, i4, 4x, i3, 4x, i3, 4x, i3, 4x, i3, 5x, l3)') &
255350
mype_world, mype_filter, task_id, mype_model, color_couple, &
@@ -259,12 +354,21 @@ SUBROUTINE init_parallel_pdaf(dim_ens, screen,schismCount,petCountLocal,concurre
259354
WRITE (*,'(2x, i4, 12x, i3, 4x, i3, 4x, i3, 4x, i3, 5x, l3)') &
260355
mype_world, task_id, mype_model, color_couple, mype_couple, filterpe
261356
END IF
262-
CALL MPI_Barrier(MPI_COMM_WORLD, MPIerr)
357+
if (schismCount.eq.concurrentCount) then !Only full-parallel mode, scribeIO
358+
if (comm_pdaf /= MPI_COMM_NULL) CALL MPI_Barrier(comm_pdaf, MPIerr)
359+
else
360+
CALL MPI_Barrier(MPI_COMM_WORLD, MPIerr)
361+
end if
263362

264363
IF (mype_world == 0) WRITE (*, '(/a)') ''
265364

266365
END IF
267366

367+
deallocate(group_ranks) !scribeIO
368+
deallocate(group_ranks_final) !scribeIO
369+
370+
!write(*,*) 'In init_parallel_pdaf chk, myrank=',mype_world,mype_world2
371+
CALL MPI_Barrier(MPI_COMM_WORLD, MPIerr)
268372

269373
! ******************************************************************************
270374
! *** Initialize model equivalents to COMM_model, npes_model, and mype_model ***

src/schism/schism_esmf_cap.F90

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ subroutine InitializeP1(comp, importState, exportState, clock, rc)
385385
! CWB2021-1 end
386386
#endif /*USE_PDAF*/
387387

388+
!feed from global.nml, for scribe cores
389+
!This is necessary for scribe cores to do the stepping
390+
if (task_id/=1) then
391+
rnday=real(runhours)/24.
392+
dt=real(schism_dt2)
393+
end if
388394
!Check consistency in inputs
389395
if(abs(runhours-rnday*24)>1.e-5.or.abs(schism_dt2-dt)>1.e-5) then
390396
!write(message,*) 'init_P1: Check rnday, dt;',runhours,rnday*24,schism_dt2,dt
@@ -405,6 +411,9 @@ subroutine InitializeP1(comp, importState, exportState, clock, rc)
405411
write(message, '(A)') trim(compName)//' initialized science model'
406412
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
407413

414+
! The following "schism_dt" & "schismClock" are required for scribe cores
415+
! otherwise, scribe cores won't do the stepping.
416+
408417
! Use schism time interval
409418
call ESMF_TimeIntervalSet(schism_dt, s_r8=dt, rc=localrc)
410419
_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)
@@ -691,7 +700,7 @@ subroutine Run(comp, importState, exportState, parentClock, rc)
691700

692701
#ifdef USE_PDAF
693702
! Put PDAF_get_state here
694-
call PDAF_get_state(steps,timenow, doexit, next_observation_pdaf, distribute_state_pdaf, prepoststep_pdaf, status_pdaf)
703+
if (task_id==1) call PDAF_get_state(steps,timenow, doexit, next_observation_pdaf, distribute_state_pdaf, prepoststep_pdaf, status_pdaf)
695704
#endif
696705

697706
!Rewind clock for forcing
@@ -822,7 +831,7 @@ subroutine Run(comp, importState, exportState, parentClock, rc)
822831
write(message,*)trim(compName)//' entering PDAF assimilate, ',it
823832
call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO)
824833
! Using assimilate PDAF interface
825-
call assimilate_pdaf() !
834+
if (task_id==1) call assimilate_pdaf() !
826835
! call assimilate_pdaf(pdaf_stat)
827836
! localrc=pdaf_stat !pdaf_stat is using i2, localrc is i4
828837
write(message,*)'Done PDAF assimilate'

0 commit comments

Comments
 (0)