Skip to content

Commit 877e0d9

Browse files
committed
Output time averaged CASA fluxes and pools
Currently the MPI implementation does not output time-averaged pools and fluxes (#566). This change implements the time-averaging functionality which exists in the serial driver into the MPI master driver. This is required to restore bitwise reproducibility in the CASA netcdf output file across serial and MPI runs.
1 parent 43e0087 commit 877e0d9

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

src/offline/cable_mpimaster.F90

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME, CRU)
248248
ctime = 0, & ! day count for casacnp
249249
YYYY, & !
250250
LOY, & ! Length of Year
251-
maxdiff(2) ! location of maximum in convergence test
251+
maxdiff(2), & ! location of maximum in convergence test
252+
count_sum_casa ! number of time steps over which casa pools &
253+
!and fluxes are aggregated (for output)
252254

253255
CHARACTER :: dum*9, str1*9, str2*9, str3*9 ! dummy char for fileName generation
254256

@@ -602,8 +604,8 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME, CRU)
602604
CALL master_restart_types (comm, canopy, air, bgc)
603605
END IF
604606

605-
! CALL zero_sum_casa(sum_casapool, sum_casaflux)
606-
! count_sum_casa = 0
607+
CALL zero_sum_casa(sum_casapool, sum_casaflux)
608+
count_sum_casa = 0
607609

608610
! CALL master_sumcasa_types(comm, sum_casapool, sum_casaflux)
609611
IF( icycle>0 .AND. spincasa) THEN
@@ -766,6 +768,13 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME, CRU)
766768
! receive casa update from worker
767769
CALL master_receive (ocomm, oktau, casa_ts)
768770

771+
IF(MOD((oktau-kstart+1),ktauday)==0) THEN
772+
! update time-aggregates of casa pools and fluxes
773+
CALL update_sum_casa(sum_casapool, sum_casaflux, casapool, casaflux, &
774+
& .TRUE. , .FALSE., 1)
775+
count_sum_casa = count_sum_casa + 1
776+
END IF
777+
769778
CALL MPI_Waitall (wnp, recv_req, recv_stats, ierr)
770779
! receive casa dump requirements from worker
771780
IF ( ((.NOT.spinup).OR.(spinup.AND.spinConv)) .AND. &
@@ -835,11 +844,12 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME, CRU)
835844
IF ( IS_CASA_TIME("write", yyyy, oktau, kstart, &
836845
koffset, kend, ktauday, logn) ) THEN
837846
ctime = ctime +1
838-
839-
840-
CALL WRITE_CASA_OUTPUT_NC (veg, casamet, casapool, casabal, casaflux, &
841-
CASAONLY, ctime, &
842-
( ktau.EQ.kend .AND. YYYY .EQ.cable_user%YearEnd ) )
847+
CALL update_sum_casa(sum_casapool, sum_casaflux, casapool, casaflux, &
848+
.FALSE. , .TRUE. , count_sum_casa)
849+
CALL WRITE_CASA_OUTPUT_NC (veg, casamet, sum_casapool, casabal, sum_casaflux, &
850+
CASAONLY, ctime, ( oktau == kend .AND. YYYY == cable_user%YearEnd ) )
851+
count_sum_casa = 0
852+
CALL zero_sum_casa(sum_casapool, sum_casaflux)
843853
ENDIF
844854
ENDIF
845855

@@ -952,6 +962,13 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME, CRU)
952962

953963
CALL master_receive (ocomm, oktau, casa_ts)
954964

965+
IF(MOD((oktau-kstart+1),ktauday)==0) THEN
966+
! update time-aggregates of casa pools and fluxes
967+
CALL update_sum_casa(sum_casapool, sum_casaflux, casapool, casaflux, &
968+
& .TRUE. , .FALSE., 1)
969+
count_sum_casa = count_sum_casa + 1
970+
END IF
971+
955972
IF ( ((.NOT.spinup).OR.(spinup.AND.spinConv)) .AND. &
956973
( IS_CASA_TIME("dwrit", yyyy, oktau, kstart, &
957974
koffset, kend, ktauday, logn) ) ) THEN
@@ -1024,9 +1041,12 @@ SUBROUTINE mpidrv_master (comm, trunk_sumbal, dels, koffset, kend, PLUME, CRU)
10241041
IF((.NOT.spinup).OR.(spinup.AND.spinConv)) THEN
10251042
IF(icycle >0) THEN
10261043
ctime = ctime +1
1027-
CALL WRITE_CASA_OUTPUT_NC (veg, casamet, casapool, casabal, casaflux, &
1028-
CASAONLY, ctime, ( ktau.EQ.kend .AND. YYYY .EQ. &
1029-
cable_user%YearEnd ) )
1044+
CALL update_sum_casa(sum_casapool, sum_casaflux, casapool, casaflux, &
1045+
.FALSE. , .TRUE. , count_sum_casa)
1046+
CALL WRITE_CASA_OUTPUT_NC (veg, casamet, sum_casapool, casabal, sum_casaflux, &
1047+
CASAONLY, ctime, ( oktau == kend .AND. YYYY == cable_user%YearEnd ) )
1048+
count_sum_casa = 0
1049+
CALL zero_sum_casa(sum_casapool, sum_casaflux)
10301050
IF ( cable_user%CALL_POP ) THEN
10311051

10321052
! CALL master_receive_pop(POP, ocomm)

0 commit comments

Comments
 (0)