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

Commit

Permalink
Made more changes to the walltimer to make it more intuitive to use.
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Sep 28, 2021
1 parent d7aaa55 commit b3a897d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 93 deletions.
18 changes: 8 additions & 10 deletions src/main/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,13 @@ program swiftest_driver
!$ write(*,'(a)') ' OpenMP parameters:'
!$ write(*,'(a)') ' ------------------'
!$ write(*,'(a,i3,/)') ' Number of threads = ', nthreads
call integration_timer%reset()
call integration_timer%pause()
call file_io_timer%reset()
call file_io_timer%pause()
nout = 0
write(*, *) " *************** Main Loop *************** "
do iloop = 1, nloops
!> Step the system forward in time
call integration_timer%resume()
call integration_timer%start()
call nbody_system%step(param, t, dt)
call integration_timer%pause()
call integration_timer%stop()

t = t0 + iloop * dt

Expand All @@ -96,10 +92,10 @@ program swiftest_driver
iout = iout - 1
if (iout == 0) then
ioutput = ioutput_t0 + iloop / istep_out
call file_io_timer%resume()
call file_io_timer%start()
if (t > old_t_final) call nbody_system%write_frame(param)
nout = nout + 1
call file_io_timer%pause()
call file_io_timer%stop()
iout = istep_out
end if
end if
Expand All @@ -109,11 +105,13 @@ program swiftest_driver
idump = idump - 1
if (idump == 0) then
call integration_timer%report(nsubsteps=istep_dump, message="Integration steps:", param=param)
call file_io_timer%resume()
call integration_timer%reset()
call file_io_timer%start()
call nbody_system%dump(param)
nout = nout + 1
call file_io_timer%pause()
call file_io_timer%stop()
call file_io_timer%report(nsubsteps=nout, message=" File I/O:", param=param)
call file_io_timer%reset()
nout = 0
idump = istep_dump
end if
Expand Down
26 changes: 10 additions & 16 deletions src/modules/walltime_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ module walltime_classes
logical :: is_paused = .false. !! Logical flag indicating whether or not the timer is paused

contains
procedure :: reset => walltime_reset !! Resets the clock ticker, settting main_start to the current ticker value
procedure :: start => walltime_start !! Starts the timer, setting count_start_step to the current ticker value
procedure :: stop => walltime_stop !! Stops the timer, setting count_stop_step to the current ticker value
procedure :: pause => walltime_pause !! Pauses the step timer (but not the main timer). Use resume to continue.
procedure :: resume => walltime_resume !! Resumes a paused step timer.
procedure :: report => walltime_report !! Prints the elapsed time information to the terminal
procedure :: reset => walltime_reset !! Resets the clock ticker, settting main_start to the current ticker value
procedure :: start => walltime_start !! Starts or resumes the step timer
procedure :: start_main => walltime_start_main !! Starts the main timer
procedure :: stop => walltime_stop !! Pauses the step timer
procedure :: report => walltime_report !! Prints the elapsed time information to the terminal
end type walltimer

type, extends(walltimer) :: interaction_timer
Expand All @@ -50,16 +49,6 @@ module walltime_classes
end type interaction_timer

interface
module subroutine walltime_pause(self)
implicit none
class(walltimer), intent(inout) :: self !! Walltimer object
end subroutine walltime_pause

module subroutine walltime_resume(self)
implicit none
class(walltimer), intent(inout) :: self !! Walltimer object
end subroutine walltime_resume

module subroutine walltime_report(self, nsubsteps, message, param)
use swiftest_classes, only : swiftest_parameters
implicit none
Expand All @@ -79,6 +68,11 @@ module subroutine walltime_start(self)
class(walltimer), intent(inout) :: self !! Walltimer object
end subroutine walltime_start

module subroutine walltime_start_main(self)
implicit none
class(walltimer), intent(inout) :: self !! Walltimer object
end subroutine walltime_start_main

module subroutine walltime_stop(self)
implicit none
class(walltimer), intent(inout) :: self !! Walltimer object
Expand Down
2 changes: 1 addition & 1 deletion src/symba/symba_step.f90
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ module recursive subroutine symba_step_recur_system(self, param, t, ireci)
else
nloops = NTENC
end if
call system%pl%set_renc(irecp)
do j = 1, nloops
call system%pl%set_renc(irecp)
lencounter = plplenc_list%encounter_check(param, system, dtl, irecp) .or. pltpenc_list%encounter_check(param, system, dtl, irecp)

call plplenc_list%kick(system, dth, irecp, 1)
Expand Down
109 changes: 43 additions & 66 deletions src/walltime/walltime.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
use swiftest
contains

module subroutine walltime_pause(self)
module subroutine walltime_stop(self)
!! author: David A. Minton
!!
!! Pauses the step timer (but not the main timer). Use resume to continue.
!! Pauses the step timer (but not the main timer).
implicit none
! Arguments
class(walltimer), intent(inout) :: self !! Walltimer object

if (.not.self%main_is_started) then
write(*,*) "Wall timer error: Cannot pause the step time until reset is called at least once!"
return
end if
! Internals
integer(I8B) :: count_delta

if (self%is_paused) then
write(*,*) "Wall timer error: Timer is already paused!"
Expand All @@ -23,8 +20,13 @@ module subroutine walltime_pause(self)
call system_clock(self%count_pause)
self%is_paused = .true.

self%count_stop_step = self%count_pause

count_delta = self%count_stop_step - self%count_start_step
self%wall_step = count_delta / (self%count_rate * 1.0_DP)

return
end subroutine walltime_pause
end subroutine walltime_stop


module subroutine walltime_report(self, nsubsteps, message, param)
Expand All @@ -40,7 +42,7 @@ module subroutine walltime_report(self, nsubsteps, message, param)
! Internals
character(len=*), parameter :: walltimefmt = '" Total wall time: ", es12.5, "; Interval wall time: ", es12.5, "; Interval wall time/step: ", es12.5'
character(len=STRMAX) :: fmt
integer(I8B) :: count_delta_step, count_delta_main, count_finish_step
integer(I8B) :: count_delta_step, count_delta_main, count_now
real(DP) :: wall_main !! Value of total elapsed time at the end of a timed step
real(DP) :: wall_step !! Value of elapsed time since the start of a timed step
real(DP) :: wall_per_substep !! Value of time per substep
Expand All @@ -50,105 +52,79 @@ module subroutine walltime_report(self, nsubsteps, message, param)
return
end if

call self%stop()
count_finish_step = self%count_stop_step

count_delta_step = count_finish_step - self%count_start_step
count_delta_main = count_finish_step - self%count_start_main
call system_clock(count_now)
count_delta_main = count_now - self%count_start_main
count_delta_step = count_now - self%count_start_step
wall_main = count_delta_main / (self%count_rate * 1.0_DP)
wall_per_substep = self%wall_step / nsubsteps
wall_step = count_delta_step / (self%count_rate * 1.0_DP)
wall_per_substep = wall_step / nsubsteps

fmt = '("' // adjustl(message) // '",' // walltimefmt // ')'
write(*,trim(adjustl(fmt))) wall_main, self%wall_step, wall_per_substep

call self%start()

return
end subroutine walltime_report


module subroutine walltime_reset(self)
!! author: David A. Minton
!!
!! Resets the clock ticker, settting main_start to the current ticker value
implicit none
! Arguments
class(walltimer), intent(inout) :: self !! Walltimer object

call system_clock(self%count_start_main, self%count_rate, self%count_max)
self%main_is_started = .true.
call self%start()

return
end subroutine walltime_reset


module subroutine walltime_resume(self)
!! author: David A. Minton
!!
!! Resumes a paused step timer.
!! Resets the step timer
implicit none
! Arguments
class(walltimer), intent(inout) :: self !! Walltimer object
! Internals
integer(I8B) :: count_resume, count_delta
integer(I8B) :: count_delta

if (.not.self%is_paused) then
write(*,*) "Wall timer error: Timer is not paused, and so cannot resume!"
return
end if

call system_clock(count_resume)
count_delta = count_resume - self%count_pause
self%count_pause = 0_I8B
self%count_start_step = self%count_start_step + count_delta
self%is_paused = .false.
self%wall_step = 0.0_DP

return
end subroutine walltime_resume
end subroutine walltime_reset


module subroutine walltime_start(self)
module subroutine walltime_start_main(self)
!! author: David A. Minton
!!
!! Starts the timer, setting step_start to the current ticker value
!! Resets the clock ticker, settting main_start to the current ticker value
implicit none
! Arguments
class(walltimer), intent(inout) :: self !! Walltimer object

call system_clock(self%count_start_main, self%count_rate, self%count_max)
self%main_is_started = .true.

if (.not.self%main_is_started) then
write(*,*) "Wall timer error: Cannot start the step time until reset is called at least once!"
return
end if

call system_clock(self%count_start_step)

return
end subroutine walltime_start
return
end subroutine walltime_start_main


module subroutine walltime_stop(self)
module subroutine walltime_start(self)
!! author: David A. Minton
!!
!! Starts the timer, setting step_start to the current ticker value
!! Starts or resumes the step timer
!!
implicit none
! Arguments
class(walltimer), intent(inout) :: self !! Walltimer object
! Internals
integer(I8B) :: count_delta
integer(I8B) :: count_resume, count_delta

if (.not.self%main_is_started) then
write(*,*) "Wall timer error: Cannot start the step time until reset is called at least once!"
return
end if

call system_clock(self%count_stop_step)
if (.not.self%main_is_started) call self%start_main()

count_delta = self%count_stop_step - self%count_start_step
self%wall_step = count_delta / (self%count_rate * 1.0_DP)
if (self%is_paused) then ! Resume a paused step timer
call system_clock(count_resume)
count_delta = count_resume - self%count_pause
self%count_pause = 0_I8B
self%count_start_step = self%count_start_step + count_delta
self%is_paused = .false.
else ! Start a new step timer
call system_clock(self%count_start_step)
end if

return
end subroutine walltime_stop
end subroutine walltime_start


module subroutine walltime_interaction_adapt(self, param, pl, ninteractions)
Expand Down Expand Up @@ -317,6 +293,7 @@ module subroutine walltime_interaction_time_this_loop(self, param, pl, ninteract
call io_log_one_message(INTERACTION_TIMER_LOG_OUT, trim(adjustl(self%loopname)) // ": stage " // schar )

call self%reset()
call self%start()

return
end subroutine walltime_interaction_time_this_loop
Expand Down

0 comments on commit b3a897d

Please sign in to comment.