diff --git a/src/CLUBB_core/advance_xp2_xpyp_module.F90 b/src/CLUBB_core/advance_xp2_xpyp_module.F90 index b1e5f12084..dede73e5a5 100644 --- a/src/CLUBB_core/advance_xp2_xpyp_module.F90 +++ b/src/CLUBB_core/advance_xp2_xpyp_module.F90 @@ -15,6 +15,8 @@ module advance_xp2_xpyp_module torch_model_load, & torch_model_forward, & torch_delete + use code_timer_module, only: & + timer_t, timer_start, timer_stop implicit none @@ -56,6 +58,11 @@ module advance_xp2_xpyp_module ndiags5 = 5 type(torch_model) :: C14_neural_net + ! Global thread-unsafe timer for measuring the cumulative execution time of C14 + ! evaluation + type(timer_t) :: C14_timer_total + ! Timer for the classical 'constant' assignment of the C14 + type(timer_t) :: C14_timer_no_ml contains @@ -74,10 +81,20 @@ subroutine setup_C14_ML_xp2_xpyp( c14_net_filepath ) character(len=100), intent(in) :: & c14_net_filepath ! Filepath to the C14 neural net + type(timer_t) :: load_timer write(unit=fstdout, fmt='(a,a)') "Reading NN from: ", c14_net_filepath + call timer_start(load_timer) call torch_model_load(C14_neural_net, c14_net_filepath, torch_kCPU) + call timer_stop(load_timer) + + ! Print the load time + write(unit=fstdout, fmt='(a,g,a)') "C14 NN load time: ", load_timer % time_elapsed, " [s]" + + ! Initialise timer + C14_timer_total = timer_t() + C14_timer_no_ml = timer_t() end subroutine setup_C14_ML_xp2_xpyp @@ -98,6 +115,10 @@ subroutine clean_up_C14_ML_xp2_xpyp() call torch_delete( C14_neural_net ) + ! Print the time + write(unit=fstdout, fmt='(a,g,a)') "C14 total evaluation time: ", C14_timer_total % time_elapsed, " [s]" + write(unit=fstdout, fmt='(a,g,a)') "C14 no ML time: ", C14_timer_no_ml % time_elapsed, " [s]" + end subroutine clean_up_C14_ML_xp2_xpyp !============================================================================= @@ -592,6 +613,7 @@ subroutine advance_xp2_xpyp( nzm, nzt, ngrdcol, sclr_dim, sclr_tol, gr, sclr_idx !$acc end parallel loop endif ! l_C2_cloud_frac + call timer_start(C14_timer_no_ml) !$acc parallel loop gang vector collapse(2) default(present) do k = 1, nzm do i = 1, ngrdcol @@ -601,13 +623,14 @@ subroutine advance_xp2_xpyp( nzm, nzt, ngrdcol, sclr_dim, sclr_tol, gr, sclr_idx end do end do !$acc end parallel loop + call timer_stop(C14_timer_no_ml) ! ML scheme for C14 ! Currently performed in a loop one cell at a time. ! Once this is working we can move towards batching a column at a time or multiple ! columns at once. if ( l_c14_ml ) then - + call timer_start(C14_timer_total) ! Interpolate Lscales from thermal to momentum grid Lscale_up_zm(:,:) = zt2zm_api( nzm, nzt, ngrdcol, gr, Lscale_up(:,:), zero_threshold ) Lscale_down_zm(:,:) = zt2zm_api( nzm, nzt, ngrdcol, gr, Lscale_down(:,:), zero_threshold ) @@ -633,7 +656,7 @@ subroutine advance_xp2_xpyp( nzm, nzt, ngrdcol, sclr_dim, sclr_tol, gr, sclr_idx C14_1d(i,k) = one_third * c14_ml_output(1) end do end do - + call timer_stop(C14_timer_total) endif ! l_c14_ml ! Are we solving for passive scalars as well? diff --git a/src/CLUBB_core/code_timer_module.F90 b/src/CLUBB_core/code_timer_module.F90 index 630682f94f..9131d83977 100644 --- a/src/CLUBB_core/code_timer_module.F90 +++ b/src/CLUBB_core/code_timer_module.F90 @@ -11,8 +11,8 @@ module code_timer_module ! A timer!! type timer_t - real :: time_elapsed ! Time elapsed [sec] - real :: secstart ! Timer starting time + real :: time_elapsed = 0.0 ! Time elapsed [sec] + real :: secstart = 0.0 ! Timer starting time end type timer_t public :: timer_t, timer_start, timer_stop