From 10fdb48d7bcd65c83b0f0af99a5641f12522a76e Mon Sep 17 00:00:00 2001 From: Benjamin Auer Date: Mon, 23 Dec 2024 11:52:37 -0500 Subject: [PATCH 1/4] fixes #3262 --- base/NCIO.F90 | 23 +++++++++++++++-------- generic/MAPL_Generic.F90 | 38 +++++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/base/NCIO.F90 b/base/NCIO.F90 index 928566cadc4e..e638d662a4b1 100644 --- a/base/NCIO.F90 +++ b/base/NCIO.F90 @@ -3512,11 +3512,12 @@ subroutine MAPL_ArrayReadNCpar_3d(varn,filename,farrayPtr,arrDes,rc) _RETURN(ESMF_SUCCESS) end subroutine MAPL_ArrayReadNCpar_3d - subroutine MAPL_BundleWriteNCPar(Bundle, arrdes, CLOCK, filename, oClients, rc) + subroutine MAPL_BundleWriteNCPar(Bundle, arrdes, CLOCK, filename, clobber, oClients, rc) type(ESMF_FieldBundle), intent(inout) :: Bundle type(ArrDescr), intent(inout) :: arrdes type(ESMF_Clock), intent(in) :: CLOCK character(len=*), intent(in ) :: filename + logical, intent(in) :: clobber type (ClientManager), optional, intent(inout) :: oClients integer, optional, intent(out) :: rc @@ -3582,6 +3583,8 @@ subroutine MAPL_BundleWriteNCPar(Bundle, arrdes, CLOCK, filename, oClients, rc) type(ESMF_Field) :: lons_field, lats_field logical :: isGridCapture, have_oclients real(kind=ESMF_KIND_R8), pointer :: grid_lons(:,:), grid_lats(:,:), lons_field_ptr(:,:), lats_field_ptr(:,:) + integer :: pfio_mode + have_oclients = present(oClients) call ESMF_FieldBundleGet(Bundle,FieldCount=nVars, name=BundleName, rc=STATUS) @@ -4174,9 +4177,11 @@ subroutine MAPL_BundleWriteNCPar(Bundle, arrdes, CLOCK, filename, oClients, rc) else + pfio_mode = PFIO_NOCLOBBER + if (clobber) pfio_mode = PFIO_CLOBBER if (arrdes%writers_comm /= mpi_comm_null) then if (arrdes%num_writers == 1) then - call formatter%create(trim(filename), rc=status) + call formatter%create(trim(filename), mode=pfio_mode, rc=status) _VERIFY(status) call formatter%write(cf,rc=status) _VERIFY(STATUS) @@ -4189,7 +4194,7 @@ subroutine MAPL_BundleWriteNCPar(Bundle, arrdes, CLOCK, filename, oClients, rc) _VERIFY(status) call cf%add_attribute("Split_Cubed_Sphere", writer_rank, _RC) else - call formatter%create_par(trim(filename),comm=arrdes%writers_comm,info=info,rc=status) + call formatter%create_par(trim(filename),mode=pfio_mode,comm=arrdes%writers_comm,info=info,rc=status) _VERIFY(status) endif call formatter%write(cf,rc=status) @@ -4307,13 +4312,14 @@ end subroutine add_fvar end subroutine MAPL_BundleWriteNCPar - subroutine MAPL_StateVarWriteNCPar(filename, STATE, ARRDES, CLOCK, NAME, forceWriteNoRestart, oClients, RC) + subroutine MAPL_StateVarWriteNCPar(filename, STATE, ARRDES, CLOCK, NAME, forceWriteNoRestart, clobber, oClients, RC) character(len=*) , intent(IN ) :: filename type (ESMF_State) , intent(IN ) :: STATE type(ArrDescr) , intent(INOUT) :: ARRDES type(ESMF_Clock) , intent(IN ) :: CLOCK character(len=*), optional, intent(IN ) :: NAME logical, optional, intent(IN ) :: forceWriteNoRestart + logical, optional, intent(in ) :: clobber type (ClientManager), optional, intent(inout) :: oClients integer, optional, intent( OUT) :: RC @@ -4339,6 +4345,7 @@ subroutine MAPL_StateVarWriteNCPar(filename, STATE, ARRDES, CLOCK, NAME, forceWr logical :: is_test_framework, isGridCapture integer :: fieldIsValid type(ESMF_Array) :: array + logical :: local_clobber call ESMF_StateGet(STATE,ITEMCOUNT=ITEMCOUNT,RC=STATUS) _VERIFY(STATUS) @@ -4358,9 +4365,9 @@ subroutine MAPL_StateVarWriteNCPar(filename, STATE, ARRDES, CLOCK, NAME, forceWr _VERIFY(STATUS) forceWriteNoRestart_ = .false. - if(present(forceWriteNoRestart)) then - forceWriteNoRestart_ = forceWriteNoRestart - endif + if(present(forceWriteNoRestart)) forceWriteNoRestart_ = forceWriteNoRestart + local_clobber = .false. + if (present(clobber)) local_clobber = clobber if(present(NAME)) then DOIT = ITEMNAMES==NAME @@ -4494,7 +4501,7 @@ subroutine MAPL_StateVarWriteNCPar(filename, STATE, ARRDES, CLOCK, NAME, forceWr call ESMF_AttributeSet(bundle_write, name="MAPL_GridCapture", value=isGridCapture, _RC) end if - call MAPL_BundleWriteNCPar(Bundle_Write, arrdes, CLOCK, filename, oClients=oClients, rc=status) + call MAPL_BundleWriteNCPar(Bundle_Write, arrdes, CLOCK, filename, clobber=local_clobber, oClients=oClients, rc=status) _VERIFY(STATUS) _RETURN(ESMF_SUCCESS) diff --git a/generic/MAPL_Generic.F90 b/generic/MAPL_Generic.F90 index 28c371198197..05fb9788400c 100644 --- a/generic/MAPL_Generic.F90 +++ b/generic/MAPL_Generic.F90 @@ -2247,6 +2247,7 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) type(ESMF_State), pointer :: child_import_state type(ESMF_State), pointer :: child_export_state type(ESMF_State), pointer :: internal_state + logical :: clobber_file !============================================================================= ! Begin... @@ -2264,6 +2265,8 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_InternalStateRetrieve(GC, STATE, RC=status) _VERIFY(status) + call MAPL_GetResource(state, clobber_file, LABEL="clobber_checkpoint:", default = .false., _RC) + ! Finalize the children ! --------------------- @@ -2365,7 +2368,8 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) _VERIFY(status) internal_state => state%get_internal_state() call MAPL_ESMFStateWriteToFile(internal_state,CLOCK,FILENAME, & - FILETYPE, STATE, hdr/=0, state%grid%write_restart_by_oserver, RC=status) + FILETYPE, STATE, hdr/=0, clobber=clobber_file, & + write_with_oserver=state%grid%write_restart_by_oserver, RC=status) _VERIFY(status) endif @@ -2389,7 +2393,8 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) endif #endif call MAPL_ESMFStateWriteToFile(IMPORT,CLOCK,FILENAME, & - FILETYPE, STATE, .FALSE., state%grid%write_restart_by_oserver, RC=status) + FILETYPE, STATE, .FALSE., clobber=clobber_file, & + write_with_oserver=state%grid%write_restart_by_oserver, RC=status) _VERIFY(status) endif @@ -2444,7 +2449,8 @@ subroutine checkpoint_export_state(rc) endif #endif call MAPL_ESMFStateWriteToFile(EXPORT,CLOCK,FILENAME, & - FILETYPE, STATE, .FALSE., state%grid%write_restart_by_oserver, RC=status) + FILETYPE, STATE, .FALSE., clobber=clobber_file, & + write_with_oserver=state%grid%write_restart_by_oserver, RC=status) _VERIFY(status) endif _RETURN(_SUCCESS) @@ -2700,6 +2706,7 @@ subroutine MAPL_StateRecord( GC, IMPORT, EXPORT, CLOCK, RC ) integer :: hdr character(len=ESMF_MAXSTR) :: FILETYPE type(ESMF_State), pointer :: internal_state + logical :: clobber_file !============================================================================= ! Begin... @@ -2718,6 +2725,7 @@ subroutine MAPL_StateRecord( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_InternalStateRetrieve(GC, STATE, RC=status) _VERIFY(status) + call MAPL_GetResource(state, clobber_file, LABEL="clobber_checkpoint:", default = .false., _RC) if (.not.associated(STATE%RECORD)) then _RETURN(ESMF_SUCCESS) end if @@ -2730,7 +2738,8 @@ subroutine MAPL_StateRecord( GC, IMPORT, EXPORT, CLOCK, RC ) end if call MAPL_ESMFStateWriteToFile(IMPORT, CLOCK, & STATE%RECORD%IMP_FNAME, & - FILETYPE, STATE, .FALSE., state%grid%write_restart_by_oserver, & + FILETYPE, STATE, .FALSE., clobber=clobber_file, & + write_with_oserver=state%grid%write_restart_by_oserver, & RC=status) _VERIFY(status) end if @@ -2747,7 +2756,8 @@ subroutine MAPL_StateRecord( GC, IMPORT, EXPORT, CLOCK, RC ) internal_state => STATE%get_internal_state() call MAPL_ESMFStateWriteToFile(internal_state, CLOCK, & STATE%RECORD%INT_FNAME, & - FILETYPE, STATE, hdr/=0, state%grid%write_restart_by_oserver, & + FILETYPE, STATE, hdr/=0, clobber=clobber_file, & + write_with_oserver=state%grid%write_restart_by_oserver, & RC=status) _VERIFY(status) end if @@ -5714,7 +5724,7 @@ end subroutine MAPL_GenericStateClockAdd !============================================================================= !============================================================================= - subroutine MAPL_ESMFStateWriteToFile(STATE,CLOCK,FILENAME,FILETYPE,MPL,HDR, write_with_oserver,RC) + subroutine MAPL_ESMFStateWriteToFile(STATE,CLOCK,FILENAME,FILETYPE,MPL,HDR, write_with_oserver,clobber,RC) type(ESMF_State), intent(INOUT) :: STATE type(ESMF_Clock), intent(IN ) :: CLOCK character(len=*), intent(IN ) :: FILENAME @@ -5722,6 +5732,7 @@ subroutine MAPL_ESMFStateWriteToFile(STATE,CLOCK,FILENAME,FILETYPE,MPL,HDR, writ type(MAPL_MetaComp), intent(INOUT) :: MPL logical, intent(IN ) :: HDR logical, optional, intent(in ) :: write_with_oserver + logical, optional, intent(in ) :: clobber integer, optional, intent( OUT) :: RC character(len=ESMF_MAXSTR), parameter :: IAm="MAPL_ESMFStateWriteToFile" @@ -5742,10 +5753,12 @@ subroutine MAPL_ESMFStateWriteToFile(STATE,CLOCK,FILENAME,FILETYPE,MPL,HDR, writ integer :: attr character(len=MPI_MAX_INFO_VAL ) :: romio_cb_write logical :: nwrgt1 - logical :: empty, local_write_with_oserver + logical :: empty, local_write_with_oserver, local_clobber local_write_with_oserver=.false. if (present(write_with_oserver)) local_write_with_oserver = write_with_oserver + local_clobber = .false. + if (present(clobber)) local_clobber = clobber ! Check if state is empty. If "yes", simply return empty = MAPL_IsStateEmpty(state, _RC) @@ -5926,9 +5939,9 @@ subroutine MAPL_ESMFStateWriteToFile(STATE,CLOCK,FILENAME,FILETYPE,MPL,HDR, writ elseif(filetype=='pnc4') then if (local_write_with_oserver) then - call MAPL_VarWriteNCPar(filename,STATE,ArrDes,CLOCK, oClients=o_clients, _RC) + call MAPL_VarWriteNCPar(filename,STATE,ArrDes,CLOCK, clobber=local_clobber, oClients=o_clients, _RC) else - call MAPL_VarWriteNCPar(filename,STATE,ArrDes,CLOCK, _RC) + call MAPL_VarWriteNCPar(filename,STATE,ArrDes,CLOCK, clobber=local_clobber, _RC) end if elseif(UNIT/=0) then @@ -10318,11 +10331,14 @@ recursive subroutine MAPL_GenericStateSave( GC, IMPORT, EXPORT, CLOCK, RC ) type(ESMF_State), pointer :: child_import_state type(ESMF_State), pointer :: child_export_state type (ESMF_State), pointer :: internal_state + logical :: clobber_file _UNUSED_DUMMY(EXPORT) call MAPL_InternalStateRetrieve(GC, STATE, RC=status) _VERIFY(status) + call MAPL_GetResource(state, clobber_file, LABEL="clobber_checkpoint:", default = .false., _RC) + call MAPL_GetResource( STATE, FILENAME, & LABEL="IMPORT_CHECKPOINT_FILE:", & RC=status) @@ -10406,7 +10422,7 @@ recursive subroutine MAPL_GenericStateSave( GC, IMPORT, EXPORT, CLOCK, RC ) end if call MAPL_ESMFStateWriteToFile(IMPORT, CLOCK, & STATE%initial_state%IMP_FNAME, & - CFILETYPE, STATE, .FALSE., write_with_oserver = state%grid%write_restart_by_oserver, & + CFILETYPE, STATE, .FALSE., clobber=clobber_file, write_with_oserver = state%grid%write_restart_by_oserver, & RC=status) _VERIFY(status) end if @@ -10422,7 +10438,7 @@ recursive subroutine MAPL_GenericStateSave( GC, IMPORT, EXPORT, CLOCK, RC ) internal_state => STATE%get_internal_state() call MAPL_ESMFStateWriteToFile(internal_state, CLOCK, & STATE%initial_state%INT_FNAME, & - CFILETYPE, STATE, hdr/=0, write_with_oserver = state%grid%write_restart_by_oserver, & + CFILETYPE, STATE, hdr/=0, clobber=clobber_file, write_with_oserver = state%grid%write_restart_by_oserver, & RC=status) _VERIFY(status) end if From 9c51eb82e25830a57d9a8cfbb9f9b47aab71d6eb Mon Sep 17 00:00:00 2001 From: Benjamin Auer Date: Mon, 23 Dec 2024 13:38:02 -0500 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ee9f07a22a0..aaab8097026d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added loggers when writing or reading weight files +- Added new option to AGCM.rc `clobber_checkpoint` to allow checkpoint files to be overwritten. By default still will not clobber checkpoints ### Changed From 5971a943e63105df390f33bed8f0b4ca3c67ede9 Mon Sep 17 00:00:00 2001 From: Benjamin Auer Date: Mon, 23 Dec 2024 13:56:13 -0500 Subject: [PATCH 3/4] change name of option --- generic/MAPL_Generic.F90 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/generic/MAPL_Generic.F90 b/generic/MAPL_Generic.F90 index 05fb9788400c..beaab3718010 100644 --- a/generic/MAPL_Generic.F90 +++ b/generic/MAPL_Generic.F90 @@ -1956,10 +1956,13 @@ subroutine capture(POS, PHASE, GC, IMPORT, EXPORT, CLOCK, RC) integer :: hdr type(ESMF_Time) :: start_time, curr_time, target_time character(len=1) :: phase_ + logical :: clobber_file + call ESMF_GridCompGet(GC, NAME=comp_name, _RC) call MAPL_InternalStateGet (GC, STATE, _RC) + call MAPL_GetResource(state, clobber_file, LABEL="overwrite_checkpoint:", default = .false., _RC) call ESMF_ClockGet(clock, startTime=start_time, currTime=curr_time, _RC) call MAPL_GetResource(STATE, time_label, label='TARGET_TIME:', default='') @@ -1979,12 +1982,15 @@ subroutine capture(POS, PHASE, GC, IMPORT, EXPORT, CLOCK, RC) write(phase_, '(i1)') phase call MAPL_ESMFStateWriteToFile(import, CLOCK, trim(FILENAME)//"import_"//trim(POS)//"_runPhase"//phase_, & - FILETYPE, STATE, .false., state%grid%write_restart_by_oserver, _RC) + FILETYPE, STATE, .false., clobber=clobber_file, & + write_with_oserver=state%grid%write_restart_by_oserver, _RC) call MAPL_ESMFStateWriteToFile(export, CLOCK, trim(FILENAME)//"export_"//trim(POS)//"_runPhase"//phase_, & - FILETYPE, STATE, .false., state%grid%write_restart_by_oserver, _RC) + FILETYPE, STATE, .false., clobber=clobber_file, & + write_with_oserver=state%grid%write_restart_by_oserver, _RC) call MAPL_GetResource(STATE, hdr, default=0, LABEL="INTERNAL_HEADER:", _RC) call MAPL_ESMFStateWriteToFile(internal, CLOCK, trim(FILENAME)//"internal_"//trim(POS)//"_runPhase"//phase_, & - FILETYPE, STATE, hdr/=0, state%grid%write_restart_by_oserver, _RC) + FILETYPE, STATE, hdr/=0, clobber=clobber_file, & + write_with_oserver=state%grid%write_restart_by_oserver, _RC) end if _RETURN(_SUCCESS) end subroutine capture @@ -2265,7 +2271,7 @@ recursive subroutine MAPL_GenericFinalize ( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_InternalStateRetrieve(GC, STATE, RC=status) _VERIFY(status) - call MAPL_GetResource(state, clobber_file, LABEL="clobber_checkpoint:", default = .false., _RC) + call MAPL_GetResource(state, clobber_file, LABEL="overwrite_checkpoint:", default = .false., _RC) ! Finalize the children ! --------------------- @@ -2725,7 +2731,7 @@ subroutine MAPL_StateRecord( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_InternalStateRetrieve(GC, STATE, RC=status) _VERIFY(status) - call MAPL_GetResource(state, clobber_file, LABEL="clobber_checkpoint:", default = .false., _RC) + call MAPL_GetResource(state, clobber_file, LABEL="overwrite_checkpoint:", default = .false., _RC) if (.not.associated(STATE%RECORD)) then _RETURN(ESMF_SUCCESS) end if @@ -10337,7 +10343,7 @@ recursive subroutine MAPL_GenericStateSave( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_InternalStateRetrieve(GC, STATE, RC=status) _VERIFY(status) - call MAPL_GetResource(state, clobber_file, LABEL="clobber_checkpoint:", default = .false., _RC) + call MAPL_GetResource(state, clobber_file, LABEL="overwrite_checkpoint:", default = .false., _RC) call MAPL_GetResource( STATE, FILENAME, & LABEL="IMPORT_CHECKPOINT_FILE:", & From fa140bbe89a43d4c706c0747050717f0b1b69d04 Mon Sep 17 00:00:00 2001 From: Benjamin Auer Date: Mon, 23 Dec 2024 13:56:44 -0500 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaab8097026d..1de3b647a206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added loggers when writing or reading weight files -- Added new option to AGCM.rc `clobber_checkpoint` to allow checkpoint files to be overwritten. By default still will not clobber checkpoints +- Added new option to AGCM.rc `overwrite_checkpoint` to allow checkpoint files to be overwritten. By default still will not overwrite checkpoints ### Changed