Skip to content

Commit

Permalink
add logical control for enabling runtime info
Browse files Browse the repository at this point in the history
  • Loading branch information
DeniseWorthen committed Aug 23, 2023
1 parent a1f066b commit 897ea65
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
18 changes: 13 additions & 5 deletions cicecore/drivers/nuopc/cmeps/cice_wrapper_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ module cice_wrapper_mod
use ice_kinds_mod , only : dbl_kind, int_kind, char_len, char_len_long

implicit none

real(dbl_kind) :: wtime = 0.0
contains
! Define stub routines that do nothing - they are just here to avoid
! having cppdefs in the main program
subroutine ufs_settimer(timevalue)
real(dbl_kind), intent(out) :: timevalue
real(dbl_kind), intent(inout) :: timevalue
end subroutine ufs_settimer
subroutine ufs_logtimer(nunit,elapsedsecs,string,time0)
subroutine ufs_logtimer(nunit,elapsedsecs,string,runtimelog,time0)
integer, intent(in) :: nunit
integer(int_kind), intent(in) :: elapsedsecs
character(len=*), intent(in) :: string
logical, intent(in) :: runtimelog
real(dbl_kind), intent(in) :: time0
end subroutine ufs_logtimer
subroutine ufs_file_setLogUnit(filename,nunit)
subroutine ufs_file_setLogUnit(filename,nunit,runtimelog)
character(len=*), intent(in) :: filename
logical, intent(in) :: runtimelog
integer, intent(out) :: nunit
end subroutine ufs_file_setLogUnit
subroutine ufs_logfhour(msg,hour)
Expand All @@ -41,21 +45,25 @@ subroutine ufs_settimer(timevalue)
timevalue = MPI_Wtime()
end subroutine ufs_settimer

subroutine ufs_logtimer(nunit,elapsedsecs,string,time0)
subroutine ufs_logtimer(nunit,elapsedsecs,string,runtimelog,time0)
integer, intent(in) :: nunit
integer(int_kind), intent(in) :: elapsedsecs
character(len=*), intent(in) :: string
logical, intent(in) :: runtimelog
real(dbl_kind), intent(in) :: time0
real(dbl_kind) :: MPI_Wtime, timevalue
if (.not. runtimelog) return
if (time0 > 0.) then
timevalue = MPI_Wtime()-time0
write(nunit,*)elapsedsecs,' CICE '//trim(string),timevalue
end if
end subroutine ufs_logtimer

subroutine ufs_file_setLogUnit(filename,nunit)
subroutine ufs_file_setLogUnit(filename,nunit,runtimelog)
character(len=*), intent(in) :: filename
logical, intent(in) :: runtimelog
integer, intent(out) :: nunit
if (.not. runtimelog) return
open (newunit=nunit, file=trim(filename))
end subroutine ufs_file_setLogUnit

Expand Down
23 changes: 15 additions & 8 deletions cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ module ice_comp_nuopc

type(ESMF_Mesh) :: ice_mesh

integer :: nthrds ! Number of threads to use in this component
integer :: nu_timer ! Simple timer log
integer :: nthrds ! Number of threads to use in this component
integer :: nu_timer = 6 ! Simple timer log, unused except by UFS
integer :: dbug = 0
logical :: profile_memory = .false.
logical :: mastertask
logical :: runtimelog = .false.
integer :: start_ymd ! Start date (YYYYMMDD)
integer :: start_tod ! start time of day (s)
integer :: curr_ymd ! Current date (YYYYMMDD)
Expand Down Expand Up @@ -308,6 +309,12 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
write(logmsg,'(i6)') dbug
call ESMF_LogWrite('CICE_cap: dbug = '//trim(logmsg), ESMF_LOGMSG_INFO)

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

!----------------------------------------------------------------------------
! generate local mpi comm
!----------------------------------------------------------------------------
Expand Down Expand Up @@ -490,7 +497,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
! Set the nu_diag_set flag so it's not reset later

call shr_file_setLogUnit (shrlogunit)
call ufs_file_setLogUnit('./log.ice.timer', nu_timer)
call ufs_file_setLogUnit('./log.ice.timer',nu_timer,runtimelog)

call NUOPC_CompAttributeGet(gcomp, name="diro", value=cvalue, &
isPresent=isPresent, isSet=isSet, rc=rc)
Expand Down Expand Up @@ -703,7 +710,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
end if

call t_stopf ('cice_init_total')
if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeAdvertise time: ',wtime)
if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeAdvertise time: ',runtimelog,wtime)
end subroutine InitializeAdvertise

!===============================================================================
Expand Down Expand Up @@ -917,7 +924,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)

call flush_fileunit(nu_diag)

if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeRealize time: ',wtime)
if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeRealize time: ',runtimelog,wtime)
end subroutine InitializeRealize

!===============================================================================
Expand Down Expand Up @@ -963,7 +970,7 @@ subroutine ModelAdvance(gcomp, rc)
!--------------------------------

rc = ESMF_SUCCESS
if (mastertask) call ufs_logtimer(nu_timer,msec,'ModelAdvance time since last step: ',wtime)
if (mastertask) call ufs_logtimer(nu_timer,msec,'ModelAdvance time since last step: ',runtimelog,wtime)
call ufs_settimer(wtime)

call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)
Expand Down Expand Up @@ -1185,7 +1192,7 @@ subroutine ModelAdvance(gcomp, rc)

if (dbug > 5) call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO)

if (mastertask) call ufs_logtimer(nu_timer,msec,'ModelAdvance time: ', wtime)
if (mastertask) call ufs_logtimer(nu_timer,msec,'ModelAdvance time: ',runtimelog,wtime)
call ufs_settimer(wtime)

end subroutine ModelAdvance
Expand Down Expand Up @@ -1341,7 +1348,7 @@ subroutine ModelFinalize(gcomp, rc)
end if
if (dbug > 5) call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO)

if(mastertask) call ufs_logtimer(nu_timer,msec,'ModelFinalize time: ', wtime)
if(mastertask) call ufs_logtimer(nu_timer,msec,'ModelFinalize time: ',runtimelog,wtime)

end subroutine ModelFinalize

Expand Down

0 comments on commit 897ea65

Please sign in to comment.