From be40a41360b2eaed31ae86582aa57e1cf41241d5 Mon Sep 17 00:00:00 2001 From: Jun Wang <37633869+junwang-noaa@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:02:27 -0400 Subject: [PATCH] add run time info (#114) * add optional run time info in nuopc cap. Author: Jun Wang --- config_src/drivers/nuopc_cap/mom_cap.F90 | 43 +++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/config_src/drivers/nuopc_cap/mom_cap.F90 b/config_src/drivers/nuopc_cap/mom_cap.F90 index 9db4f03100..71419ea4bf 100644 --- a/config_src/drivers/nuopc_cap/mom_cap.F90 +++ b/config_src/drivers/nuopc_cap/mom_cap.F90 @@ -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. @@ -147,6 +148,7 @@ module MOM_cap_mod type(ESMF_GeomType_Flag) :: geomtype #endif character(len=8) :: restart_mode = 'alarms' +real(8) :: timere contains @@ -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 @@ -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) @@ -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) @@ -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 @@ -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) @@ -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 @@ -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 @@ -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. @@ -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) @@ -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 @@ -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 @@ -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