Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Simplified the wall timer and fixed a problem that was causing it to …
Browse files Browse the repository at this point in the history
…add in the elapsed time between when the timer was stopped and when the report was caleld to the interval time.
  • Loading branch information
daminton committed Mar 10, 2023
1 parent a28a064 commit a312d72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/swiftest/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
20 changes: 9 additions & 11 deletions src/walltime/walltime_implementations.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, ";' //&
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/walltime/walltime_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit a312d72

Please sign in to comment.