Skip to content

Commit

Permalink
add run time info (#114)
Browse files Browse the repository at this point in the history
* add optional run time info in nuopc cap. Author: Jun Wang
  • Loading branch information
junwang-noaa authored Sep 7, 2023
1 parent 06acdc8 commit be40a41
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions config_src/drivers/nuopc_cap/mom_cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ module MOM_cap_mod
character(len=256) :: tmpstr
logical :: write_diagnostics = .false.
logical :: overwrite_timeslice = .false.
logical :: write_runtimelog = .false.
character(len=32) :: runtype !< run type
logical :: profile_memory = .true.
logical :: grid_attach_area = .false.
Expand All @@ -147,6 +148,7 @@ module MOM_cap_mod
type(ESMF_GeomType_Flag) :: geomtype
#endif
character(len=8) :: restart_mode = 'alarms'
real(8) :: timere

contains

Expand Down Expand Up @@ -230,6 +232,8 @@ subroutine InitializeP0(gcomp, importState, exportState, clock, rc)
integer :: iostat
character(len=64) :: value, logmsg
character(len=*),parameter :: subname='(MOM_cap:InitializeP0)'
type(ESMF_VM) :: vm
integer :: mype

rc = ESMF_SUCCESS

Expand All @@ -247,6 +251,14 @@ subroutine InitializeP0(gcomp, importState, exportState, clock, rc)
write(logmsg,*) write_diagnostics
call ESMF_LogWrite('MOM_cap:DumpFields = '//trim(logmsg), ESMF_LOGMSG_INFO)

write_runtimelog = .false.
call NUOPC_CompAttributeGet(gcomp, name="RunTimeLog", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) write_runtimelog=(trim(value)=="true")
write(logmsg,*) write_runtimelog
call ESMF_LogWrite('MOM_cap:RunTimeLog = '//trim(logmsg), ESMF_LOGMSG_INFO)

overwrite_timeslice = .false.
call NUOPC_CompAttributeGet(gcomp, name="OverwriteSlice", value=value, &
isPresent=isPresent, isSet=isSet, rc=rc)
Expand Down Expand Up @@ -422,9 +434,11 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
! (same as restartfile if single restart file)
character(len=*), parameter :: subname='(MOM_cap:InitializeAdvertise)'
character(len=32) :: calendar
real(8) :: MPI_Wtime, timeiads
!--------------------------------

rc = ESMF_SUCCESS
if(write_runtimelog) timeiads = MPI_Wtime()

call ESMF_LogWrite(subname//' enter', ESMF_LOGMSG_INFO)

Expand Down Expand Up @@ -774,7 +788,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
call NUOPC_Advertise(exportState, standardName=fldsFrOcn(n)%stdname, name=fldsFrOcn(n)%shortname, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
enddo
if(is_root_pe()) write(stdout,*) 'InitializeAdvertise complete'
if(write_runtimelog .and. is_root_pe()) write(stdout,*) 'In ',trim(subname),' time ', MPI_Wtime()-timeiads

end subroutine InitializeAdvertise

!> Called by NUOPC to realize import and export fields. "Realizing" a field
Expand Down Expand Up @@ -856,9 +871,11 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
real(ESMF_KIND_R8) :: min_areacor_glob(2)
real(ESMF_KIND_R8) :: max_areacor_glob(2)
character(len=*), parameter :: subname='(MOM_cap:InitializeRealize)'
real(8) :: MPI_Wtime, timeirls
!--------------------------------

rc = ESMF_SUCCESS
if(write_runtimelog) timeirls = MPI_Wtime()

call shr_log_setLogUnit (stdout)

Expand Down Expand Up @@ -1350,6 +1367,9 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! timeslice=1, relaxedFlag=.true., rc=rc)
!if (ChkErr(rc,__LINE__,u_FILE_u)) return

timere = 0.
if(write_runtimelog .and. is_root_pe()) write(stdout,*) 'In ',trim(subname),' time ', MPI_Wtime()-timeirls

end subroutine InitializeRealize

!> TODO
Expand Down Expand Up @@ -1378,8 +1398,11 @@ subroutine DataInitialize(gcomp, rc)
type(ESMF_Field) :: field
character(len=64),allocatable :: fieldNameList(:)
character(len=*),parameter :: subname='(MOM_cap:DataInitialize)'
real(8) :: MPI_Wtime, timedis
!--------------------------------

if(write_runtimelog) timedis = MPI_Wtime()

! query the Component for its clock, importState and exportState
call ESMF_GridCompGet(gcomp, clock=clock, importState=importState, exportState=exportState, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand Down Expand Up @@ -1440,6 +1463,8 @@ subroutine DataInitialize(gcomp, rc)
enddo
endif

if(write_runtimelog .and. is_root_pe()) write(stdout,*) 'In ',trim(subname),' time ', MPI_Wtime()-timedis

end subroutine DataInitialize

!> Called by NUOPC to advance the model a single timestep.
Expand Down Expand Up @@ -1490,9 +1515,14 @@ subroutine ModelAdvance(gcomp, rc)
character(len=*),parameter :: subname='(MOM_cap:ModelAdvance)'
character(len=8) :: suffix
integer :: num_rest_files
real(8) :: MPI_Wtime, timers

rc = ESMF_SUCCESS
if(profile_memory) call ESMF_VMLogMemInfo("Entering MOM Model_ADVANCE: ")
if(write_runtimelog) then
timers = MPI_Wtime()
if(timere>0. .and. is_root_pe()) write(stdout,*) 'In ',trim(subname),' time since last time step ',timers-timere
endif

call shr_log_setLogUnit (stdout)

Expand Down Expand Up @@ -1726,6 +1756,11 @@ subroutine ModelAdvance(gcomp, rc)
enddo
endif

if(write_runtimelog) then
timere = MPI_Wtime()
if(is_root_pe()) write(stdout,*) 'In ',trim(subname),' time ', timere-timers
endif

if(profile_memory) call ESMF_VMLogMemInfo("Leaving MOM Model_ADVANCE: ")

end subroutine ModelAdvance
Expand Down Expand Up @@ -1928,11 +1963,13 @@ subroutine ocean_model_finalize(gcomp, rc)
character(len=64) :: timestamp
logical :: write_restart
character(len=*),parameter :: subname='(MOM_cap:ocean_model_finalize)'
real(8) :: MPI_Wtime, timefs

if (is_root_pe()) then
write(stdout,*) 'MOM: --- finalize called ---'
endif
rc = ESMF_SUCCESS
if(write_runtimelog) timefs = MPI_Wtime()

call ESMF_GridCompGetInternalState(gcomp, ocean_internalstate, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand Down Expand Up @@ -1961,9 +1998,7 @@ subroutine ocean_model_finalize(gcomp, rc)
call io_infra_end()
call MOM_infra_end()

if (is_root_pe()) then
write(stdout,*) 'MOM: --- completed ---'
endif
if(write_runtimelog .and. is_root_pe()) write(stdout,*) 'In ',trim(subname),' time ', MPI_Wtime()-timefs

end subroutine ocean_model_finalize

Expand Down

0 comments on commit be40a41

Please sign in to comment.