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 | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(inout) | :: | this |
Timer instance previously started with |
||
| 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 |
|
| logical, | intent(in), | optional | :: |
Optional output switch; defaults to |
||
| 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. |
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