From b3a897df759c630ed905fde1b430990e0e730b32 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Tue, 28 Sep 2021 08:24:45 -0400 Subject: [PATCH] Made more changes to the walltimer to make it more intuitive to use. --- src/main/swiftest_driver.f90 | 18 +++-- src/modules/walltime_classes.f90 | 26 +++----- src/symba/symba_step.f90 | 2 +- src/walltime/walltime.f90 | 109 ++++++++++++------------------- 4 files changed, 62 insertions(+), 93 deletions(-) diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index 791194635..7e243812e 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -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 @@ -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 @@ -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 diff --git a/src/modules/walltime_classes.f90 b/src/modules/walltime_classes.f90 index b0847bcba..e513801cc 100644 --- a/src/modules/walltime_classes.f90 +++ b/src/modules/walltime_classes.f90 @@ -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 @@ -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 @@ -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 diff --git a/src/symba/symba_step.f90 b/src/symba/symba_step.f90 index 70317cd70..ba4c1a734 100644 --- a/src/symba/symba_step.f90 +++ b/src/symba/symba_step.f90 @@ -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) diff --git a/src/walltime/walltime.f90 b/src/walltime/walltime.f90 index 758c5397a..9211a27f6 100644 --- a/src/walltime/walltime.f90 +++ b/src/walltime/walltime.f90 @@ -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!" @@ -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) @@ -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 @@ -50,19 +52,16 @@ 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 @@ -70,85 +69,62 @@ 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) @@ -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