Skip to content

Commit

Permalink
Merge branch 'develop' into release/MAPL-v3
Browse files Browse the repository at this point in the history
# Conflicts:
#	generic/MAPL_Generic.F90
  • Loading branch information
mathomp4 committed Dec 23, 2024
2 parents a69894f + d4ab188 commit aa7d3a0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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 @@ -3550,11 +3550,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 @@ -3621,6 +3622,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 @@ -4222,9 +4225,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 @@ -4237,7 +4242,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 @@ -4361,13 +4366,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 @@ -4394,6 +4400,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 @@ -4413,9 +4420,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 @@ -4562,7 +4569,7 @@ subroutine MAPL_StateVarWriteNCPar(filename, STATE, ARRDES, CLOCK, NAME, forceWr
call ESMF_InfoSet(infoh_bundle, key="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
51 changes: 36 additions & 15 deletions generic/MAPL_Generic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ end subroutine i_Run
integer , pointer :: phase_coldstart(:)=> null()
integer , pointer :: phase_refresh(:)=> null()
procedure(i_run), public, nopass, pointer :: customRefresh => null()

! Make accessors?
type(ESMF_GridComp) :: RootGC
type(ESMF_GridComp) , pointer :: parentGC => null()
Expand Down Expand Up @@ -1979,11 +1979,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
type(ESMF_Info) :: infoh

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 @@ -2004,12 +2006,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 @@ -2273,6 +2278,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 @@ -2290,6 +2296,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 @@ -2392,7 +2400,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 @@ -2416,7 +2425,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 @@ -2472,7 +2482,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 @@ -2727,6 +2738,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 @@ -2745,6 +2757,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 @@ -2757,7 +2770,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 @@ -2774,7 +2788,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 @@ -5750,14 +5765,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 @@ -5778,11 +5794,13 @@ 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
type(ESMF_Info) :: infoh

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 @@ -5966,9 +5984,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 @@ -10386,11 +10404,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 @@ -10474,7 +10495,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 @@ -10490,7 +10511,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

0 comments on commit aa7d3a0

Please sign in to comment.