Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #3262 #3269

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `overwrite_checkpoint` to allow checkpoint files to be overwritten. By default still will not overwrite checkpoints

### Changed

Expand Down
23 changes: 15 additions & 8 deletions base/NCIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
50 changes: 36 additions & 14 deletions generic/MAPL_Generic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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='')
Expand All @@ -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
Expand Down Expand Up @@ -2247,6 +2253,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...
Expand All @@ -2264,6 +2271,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="overwrite_checkpoint:", default = .false., _RC)

! Finalize the children
! ---------------------

Expand Down Expand Up @@ -2365,7 +2374,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

Expand All @@ -2389,7 +2399,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

Expand Down Expand Up @@ -2444,7 +2455,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)
Expand Down Expand Up @@ -2700,6 +2712,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...
Expand All @@ -2718,6 +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="overwrite_checkpoint:", default = .false., _RC)
if (.not.associated(STATE%RECORD)) then
_RETURN(ESMF_SUCCESS)
end if
Expand All @@ -2730,7 +2744,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
Expand All @@ -2747,7 +2762,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
Expand Down Expand Up @@ -5714,14 +5730,15 @@ 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
character(LEN=*), intent(INout) :: FILETYPE
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"
Expand All @@ -5742,10 +5759,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)
Expand Down Expand Up @@ -5926,9 +5945,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
Expand Down Expand Up @@ -10318,11 +10337,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="overwrite_checkpoint:", default = .false., _RC)

call MAPL_GetResource( STATE, FILENAME, &
LABEL="IMPORT_CHECKPOINT_FILE:", &
RC=status)
Expand Down Expand Up @@ -10406,7 +10428,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
Expand All @@ -10422,7 +10444,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
Expand Down
Loading