From dce7176d5181313a993dc1365055a8d6e102f26a Mon Sep 17 00:00:00 2001 From: Dusan Jovic Date: Tue, 1 Apr 2025 13:59:51 +0000 Subject: [PATCH 1/3] Add ufs_tracing --- .../drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index 8ced569a5..4ed7f2237 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -58,6 +58,7 @@ module ice_comp_nuopc #ifndef CESMCOUPLED use shr_is_restart_fh_mod, only : init_is_restart_fh, is_restart_fh, is_restart_fh_type #endif + use ufs_trace_mod implicit none private @@ -116,6 +117,7 @@ module ice_comp_nuopc character(*), parameter :: u_FILE_u = & __FILE__ + integer :: mype = -1 !======================================================================= contains !=============================================================================== @@ -127,12 +129,21 @@ subroutine SetServices(gcomp, rc) integer, intent(out) :: rc ! Local variables + type(ESMF_VM) :: vm character(len=*),parameter :: subname=trim(modName)//':(SetServices) ' !-------------------------------- rc = ESMF_SUCCESS if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO) + call ESMF_GridCompGet(gcomp, vm=vm,rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + call ESMF_VMGet(vm, localpet=mype, rc=rc) + if (ChkErr(rc,__LINE__,u_FILE_u)) return + + if (mype == 0) call ufs_trace_init() + if (mype == 0) call ufs_trace("cice", "SetServices", "B") + ! the NUOPC gcomp component will register the generic methods call NUOPC_CompDerive(gcomp, model_routine_SS, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -168,6 +179,7 @@ subroutine SetServices(gcomp, rc) if (dbug > 5) call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO) + if (mype == 0) call ufs_trace("cice", "SetServices", "E") end subroutine SetServices !=============================================================================== @@ -186,6 +198,7 @@ subroutine InitializeP0(gcomp, importState, exportState, clock, rc) !-------------------------------- rc = ESMF_SUCCESS + if (mype == 0) call ufs_trace("cice", "InitializeP0", "B") ! Switch to IPDv01 by filtering all other phaseMap entries call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, & @@ -200,6 +213,7 @@ subroutine InitializeP0(gcomp, importState, exportState, clock, rc) write(logmsg,*) profile_memory call ESMF_LogWrite('CICE_cap:ProfileMemory = '//trim(logmsg), ESMF_LOGMSG_INFO) + if (mype == 0) call ufs_trace("cice", "InitializeP0", "E") end subroutine InitializeP0 !=============================================================================== @@ -255,6 +269,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) character(len=*), parameter :: subname=trim(modName)//':(InitializeAdvertise) ' !-------------------------------- + if (mype == 0) call ufs_trace("cice", "InitializeAdvertise", "B") + call ufs_settimer(wtime) call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldName", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc) @@ -756,6 +772,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call t_stopf ('cice_init_total') if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeAdvertise time: ',runtimelog,wtime) + if (mype == 0) call ufs_trace("cice", "InitializeAdvertise", "E") end subroutine InitializeAdvertise !=============================================================================== @@ -789,6 +806,8 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) !-------------------------------- rc = ESMF_SUCCESS + if (mype == 0) call ufs_trace("cice", "InitializeRealize", "B") + if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO) call ufs_settimer(wtime) @@ -990,6 +1009,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) call flush_fileunit(nu_diag) if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeRealize time: ',runtimelog,wtime) + if (mype == 0) call ufs_trace("cice", "InitializeRealize", "E") end subroutine InitializeRealize !=============================================================================== @@ -1038,6 +1058,7 @@ subroutine ModelAdvance(gcomp, rc) !-------------------------------- rc = ESMF_SUCCESS + if (mype == 0) call ufs_trace("cice", "ModelAdvance", "B") if (mastertask) call ufs_logtimer(nu_timer,msec,'ModelAdvance time since last step: ',runtimelog,wtime) call ufs_settimer(wtime) @@ -1278,6 +1299,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: ',runtimelog,wtime) + if (mype == 0) call ufs_trace("cice", "ModelAdvance", "E") call ufs_settimer(wtime) end subroutine ModelAdvance @@ -1432,6 +1454,7 @@ subroutine ModelFinalize(gcomp, rc) !-------------------------------- rc = ESMF_SUCCESS + if (mype == 0) call ufs_trace("cice", "ModelFinalize", "B") call ufs_settimer(wtime) if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO) if (my_task == master_task) then @@ -1442,6 +1465,7 @@ subroutine ModelFinalize(gcomp, rc) if (dbug > 5) call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO) if(mastertask) call ufs_logtimer(nu_timer,msec,'ModelFinalize time: ',runtimelog,wtime) + if (mype == 0) call ufs_trace("cice", "ModelFinalize", "E") end subroutine ModelFinalize From 01024e66cdb2f966fec1fc35de1acbf1cd6633a9 Mon Sep 17 00:00:00 2001 From: Dusan Jovic Date: Wed, 10 Sep 2025 13:57:09 +0000 Subject: [PATCH 2/3] Conditional compilation of ufs_tracing --- .../drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index f54ec55c5..9ed8868d7 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -58,7 +58,9 @@ module ice_comp_nuopc #ifndef CESMCOUPLED use shr_is_restart_fh_mod, only : init_is_restart_fh, is_restart_fh, is_restart_fh_type #endif +#ifdef UFS_TRACING use ufs_trace_mod +#endif implicit none private @@ -141,8 +143,10 @@ subroutine SetServices(gcomp, rc) call ESMF_VMGet(vm, localpet=mype, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return +#ifdef UFS_TRACING if (mype == 0) call ufs_trace_init() if (mype == 0) call ufs_trace("cice", "SetServices", "B") +#endif ! the NUOPC gcomp component will register the generic methods call NUOPC_CompDerive(gcomp, model_routine_SS, rc=rc) @@ -179,7 +183,9 @@ subroutine SetServices(gcomp, rc) if (dbug > 5) call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO) +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "SetServices", "E") +#endif end subroutine SetServices !=============================================================================== @@ -198,7 +204,9 @@ subroutine InitializeP0(gcomp, importState, exportState, clock, rc) !-------------------------------- rc = ESMF_SUCCESS +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "InitializeP0", "B") +#endif ! Switch to IPDv01 by filtering all other phaseMap entries call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, & @@ -213,7 +221,9 @@ subroutine InitializeP0(gcomp, importState, exportState, clock, rc) write(logmsg,*) profile_memory call ESMF_LogWrite('CICE_cap:ProfileMemory = '//trim(logmsg), ESMF_LOGMSG_INFO) +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "InitializeP0", "E") +#endif end subroutine InitializeP0 !=============================================================================== @@ -269,7 +279,9 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) character(len=*), parameter :: subname=trim(modName)//':(InitializeAdvertise) ' !-------------------------------- +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "InitializeAdvertise", "B") +#endif call ufs_settimer(wtime) @@ -772,7 +784,9 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc) call t_stopf ('cice_init_total') if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeAdvertise time: ',runtimelog,wtime) +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "InitializeAdvertise", "E") +#endif end subroutine InitializeAdvertise !=============================================================================== @@ -806,7 +820,9 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) !-------------------------------- rc = ESMF_SUCCESS +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "InitializeRealize", "B") +#endif if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO) @@ -1009,7 +1025,9 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) call flush_fileunit(nu_diag) if (mastertask) call ufs_logtimer(nu_timer,msec,'InitializeRealize time: ',runtimelog,wtime) +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "InitializeRealize", "E") +#endif end subroutine InitializeRealize !=============================================================================== @@ -1058,7 +1076,9 @@ subroutine ModelAdvance(gcomp, rc) !-------------------------------- rc = ESMF_SUCCESS +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "ModelAdvance", "B") +#endif if (mastertask) call ufs_logtimer(nu_timer,msec,'ModelAdvance time since last step: ',runtimelog,wtime) call ufs_settimer(wtime) @@ -1299,7 +1319,9 @@ 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: ',runtimelog,wtime) +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "ModelAdvance", "E") +#endif call ufs_settimer(wtime) end subroutine ModelAdvance @@ -1454,7 +1476,9 @@ subroutine ModelFinalize(gcomp, rc) !-------------------------------- rc = ESMF_SUCCESS +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "ModelFinalize", "B") +#endif call ufs_settimer(wtime) if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO) if (my_task == master_task) then @@ -1465,7 +1489,9 @@ subroutine ModelFinalize(gcomp, rc) if (dbug > 5) call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO) if(mastertask) call ufs_logtimer(nu_timer,msec,'ModelFinalize time: ',runtimelog,wtime) +#ifdef UFS_TRACING if (mype == 0) call ufs_trace("cice", "ModelFinalize", "E") +#endif end subroutine ModelFinalize From f04d6eebb2f9d6e8d067d4ae135edf14a174fc22 Mon Sep 17 00:00:00 2001 From: Dusan Jovic Date: Mon, 29 Dec 2025 18:47:53 +0000 Subject: [PATCH 3/3] Update ice_comp_nuopc.F90 Add UFS_TRACING ifdef around variables specific to tracing --- cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 index 41e78ee88..bb1b5b56f 100644 --- a/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 +++ b/cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90 @@ -120,7 +120,9 @@ module ice_comp_nuopc character(*), parameter :: u_FILE_u = & __FILE__ +#ifdef UFS_TRACING integer :: mype = -1 +#endif !======================================================================= contains !=============================================================================== @@ -132,19 +134,21 @@ subroutine SetServices(gcomp, rc) integer, intent(out) :: rc ! Local variables +#ifdef UFS_TRACING type(ESMF_VM) :: vm +#endif character(len=*),parameter :: subname=trim(modName)//':(SetServices) ' !-------------------------------- rc = ESMF_SUCCESS if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO) +#ifdef UFS_TRACING call ESMF_GridCompGet(gcomp, vm=vm,rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return call ESMF_VMGet(vm, localpet=mype, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return -#ifdef UFS_TRACING if (mype == 0) call ufs_trace_init() if (mype == 0) call ufs_trace("cice", "SetServices", "B") #endif