From a312d725470282aa1c96b3e4c2beb8fc0035e982 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 10 Mar 2023 17:57:40 -0500 Subject: [PATCH] Simplified the wall timer and fixed a problem that was causing it to add in the elapsed time between when the timer was stopped and when the report was caleld to the interval time. --- src/swiftest/swiftest_driver.f90 | 2 +- src/walltime/walltime_implementations.f90 | 20 +++++++++----------- src/walltime/walltime_module.f90 | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/swiftest/swiftest_driver.f90 b/src/swiftest/swiftest_driver.f90 index 2da264bea..bfa950222 100644 --- a/src/swiftest/swiftest_driver.f90 +++ b/src/swiftest/swiftest_driver.f90 @@ -124,7 +124,7 @@ program swiftest_driver call nbody_system%dump(param) end if - call integration_timer%report(message="Integration steps:", unit=display_unit, nsubsteps=istep_out) + call integration_timer%report(message="Integration steps:", unit=display_unit) call nbody_system%display_run_information(param, integration_timer) call integration_timer%reset() if (param%lenergy) call nbody_system%conservation_report(param, lterminal=.true.) diff --git a/src/walltime/walltime_implementations.f90 b/src/walltime/walltime_implementations.f90 index dcf1a2a60..aaf18f85b 100644 --- a/src/walltime/walltime_implementations.f90 +++ b/src/walltime/walltime_implementations.f90 @@ -38,7 +38,7 @@ module subroutine walltime_stop(self) end subroutine walltime_stop - module subroutine walltime_report(self, message, unit, nsubsteps) + module subroutine walltime_report(self, message, unit) !! author: David A. Minton !! !! Prints the elapsed time information to the terminal @@ -47,7 +47,6 @@ module subroutine walltime_report(self, message, unit, nsubsteps) class(walltimer), intent(inout) :: self !! Walltimer object character(len=*), intent(in) :: message !! Message to prepend to the wall time terminal output integer(I4B), intent(in) :: unit !! Output file unit for report text to be directed - integer(I4B), optional, intent(in) :: nsubsteps !! Number of substeps used to compute the time per step ! Internals character(len=*), parameter :: nosubstepfmt = '" Total wall time: ", es12.5, "; Interval wall time: ", es12.5 ' character(len=*), parameter :: substepfmt = '" Total wall time: ", es12.5, "; Interval wall time: ", es12.5, ";' //& @@ -62,17 +61,14 @@ module subroutine walltime_report(self, message, unit, nsubsteps) call system_clock(count_now) count_delta_main = count_now - self%count_start_main - count_delta_step = count_now - self%count_start_step self%wall_main = count_delta_main / (self%count_rate * 1.0_DP) + + count_delta_step = self%count_stop_step - self%count_start_step self%wall_step = count_delta_step / (self%count_rate * 1.0_DP) - if (present(nsubsteps)) then - self%wall_per_substep = self%wall_step / nsubsteps - fmt = '("' // adjustl(message) // '",' // substepfmt // ')' - write(unit,trim(adjustl(fmt))) self%wall_main, self%wall_step, self%wall_per_substep - else - fmt = '("' // adjustl(message) // '",' // nosubstepfmt // ')' - write(unit,trim(adjustl(fmt))) self%wall_main, self%wall_step - end if + self%wall_per_substep = self%wall_step / self%nsubsteps + + fmt = '("' // adjustl(message) // '",' // substepfmt // ')' + write(unit,trim(adjustl(fmt))) self%wall_main, self%wall_step, self%wall_per_substep return end subroutine walltime_report @@ -90,6 +86,7 @@ module subroutine walltime_reset(self) self%is_paused = .false. self%wall_step = 0.0_DP self%wall_per_substep = 0.0_DP + self%nsubsteps = 0 return end subroutine walltime_reset @@ -106,6 +103,7 @@ module subroutine walltime_start_main(self) call system_clock(self%count_start_main, self%count_rate, self%count_max) self%main_is_started = .true. self%wall_main = 0.0_DP + self%nsubsteps = self%nsubsteps + 1 return end subroutine walltime_start_main diff --git a/src/walltime/walltime_module.f90 b/src/walltime/walltime_module.f90 index 6ccce25b1..fa41bae87 100644 --- a/src/walltime/walltime_module.f90 +++ b/src/walltime/walltime_module.f90 @@ -28,6 +28,7 @@ module walltime integer(I8B) :: count_start_step !! Value of the clock ticker at the start of a timed step integer(I8B) :: count_stop_step !! Value of the clock ticker at the end of a timed step integer(I8B) :: count_pause !! Value of the clock ticker at the end of a timed step + integer(I4B) :: nsubsteps !! Number of substeps in an interval (number of times the timer is turned off and back on again) real(DP) :: wall_step !! Value of the step elapsed time real(DP) :: wall_main !! Value of the main clock elapsed time real(DP) :: wall_per_substep !! Value of time per substep @@ -44,12 +45,11 @@ module walltime interface - module subroutine walltime_report(self, message, unit, nsubsteps) + module subroutine walltime_report(self, message, unit) implicit none class(walltimer), intent(inout) :: self !! Walltimer object character(len=*), intent(in) :: message !! Message to prepend to the wall time terminal output integer(I4B), intent(in) :: unit !! Output file unit for report text to be directed - integer(I4B), optional, intent(in) :: nsubsteps !! Number of substeps used to compute the time per step end subroutine walltime_report module subroutine walltime_reset(self)