timer_stop Subroutine

private subroutine timer_stop(this, nloops, message, print, color, rfmt)

timer_stop captures the stop tick before validation and reporting work, subtracts ticks accumulated by timer_pause / timer_resume, converts the running interval to seconds, and writes the finalized value to elapsed_time.

The stored value is updated only when the timer was running, was not paused, nloops is valid, and optional printing succeeds.

Type Bound

timer

Arguments

Type IntentOptional Attributes Name
class(timer), intent(inout) :: this

Timer instance previously started with timer_start.

integer, intent(in), optional :: nloops

Optional positive loop count used to compute average elapsed time.

character(len=*), intent(in), optional :: message

Optional output label; defaults to Elapsed time:.

logical, intent(in), optional :: print

Optional output switch; defaults to .true..

character(len=*), intent(in), optional :: color

Optional FACE foreground color used for printed output.

character(len=*), intent(in), optional :: rfmt

Optional Fortran real edit descriptor used for printed output.


Calls

proc~~timer_stop~~CallsGraph proc~timer_stop timer%timer_stop proc~finalize_timing finalize_timing proc~timer_stop->proc~finalize_timing proc~ticks_diff ticks_diff proc~timer_stop->proc~ticks_diff proc~print_time print_time proc~finalize_timing->proc~print_time colorize colorize proc~print_time->colorize

Called by

proc~~timer_stop~~CalledByGraph proc~timer_stop timer%timer_stop proc~run_test1 run_test1 proc~run_test1->proc~timer_stop proc~run_test13 run_test13 proc~run_test13->proc~timer_stop proc~run_test14 run_test14 proc~run_test14->proc~timer_stop proc~run_test15 run_test15 proc~run_test15->proc~timer_stop proc~run_test2 run_test2 proc~run_test2->proc~timer_stop proc~run_test3 run_test3 proc~run_test3->proc~timer_stop proc~run_test31 run_test31 proc~run_test31->proc~timer_stop proc~run_test32 run_test32 proc~run_test32->proc~timer_stop program~example1 example1 program~example1->proc~timer_stop program~example2 example2 program~example2->proc~timer_stop program~check check program~check->proc~run_test1 program~check->proc~run_test13 program~check->proc~run_test14 program~check->proc~run_test15 program~check->proc~run_test2 program~check->proc~run_test3 program~check->proc~run_test31 program~check->proc~run_test32

Source Code

   subroutine timer_stop(this, nloops, message, print, color, rfmt)
      class(timer), intent(inout) :: this
         !! Timer instance previously started with `timer_start`.
      integer, intent(in), optional :: nloops
         !! Optional positive loop count used to compute average elapsed time.
      character(*), intent(in), optional :: message
         !! Optional output label; defaults to `Elapsed time:`.
      logical, intent(in), optional :: print
         !! Optional output switch; defaults to `.true.`.
      character(*), intent(in), optional :: color
         !! Optional FACE foreground color used for printed output.
      character(*), intent(in), optional :: rfmt
         !! Optional Fortran real edit descriptor used for printed output.

      integer(ik) :: clock_end
         !! Stop tick captured from `system_clock`.
      integer(ik) :: ticks
         !! Elapsed running ticks after subtracting paused ticks.
      real(rk) :: raw_seconds
         !! Elapsed running time in seconds before optional loop averaging.
      real(rk) :: out_seconds
         !! Final elapsed time after validation and optional loop averaging.
      logical :: ok
         !! Finalization status returned by `finalize_timing`.

      call system_clock(count=clock_end)

      if (.not. this%is_started) then
         write(error_unit, '(A)') 'Error: timer_stop called before timer_start!'
         return
      end if

      if (this%is_paused) then
         write(error_unit, '(A)') 'Error: timer_stop called while timer is paused!'
         return
      end if

      if (this%clock_rate <= 0_ik) then
         write(error_unit, '(A)') 'Error: system_clock count_rate <= 0; cannot compute seconds.'
         this%is_started = .false.
         return
      end if

      ticks = ticks_diff(clock_end, this%clock_start, this%clock_max) - this%paused_ticks
      if (ticks < 0_ik) ticks = 0_ik

      raw_seconds = real(ticks, rk) / real(this%clock_rate, rk)

      this%is_started = .false.
      this%is_paused = .false.
      this%paused_ticks = 0_ik

      call finalize_timing(raw_seconds, nloops, out_seconds, 'Elapsed time:', message, print, color, rfmt, ok)
      if (.not. ok) return
      this%elapsed_time = out_seconds
   end subroutine timer_stop