Returns the elapsed time as a real(dp) variable
Usage: var = my_timer%get_elapsed_time()
Needs my_timer to be declared previously as type(timer_type) :: my_timer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer_type), | intent(in) | :: | self |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int64), | private | :: | current_count |
function timer_get_elapsed_time(self) result(elapsed) !! Returns the elapsed time as a real(dp) variable !! !! Usage: var = my_timer%get_elapsed_time() !! !! Needs my_timer to be declared previously as type(timer_type) :: my_timer !! class(timer_type), intent(in) :: self real(dp) :: elapsed integer(int64) :: current_count elapsed = 0.0_dp #ifdef _OPENMP if (self%is_running) then elapsed = omp_get_wtime() - self%start_time else elapsed = self%stop_time - self%start_time end if #else ! F2018 16.9.180: a processor with no clock sets COUNT_RATE to zero (and ! COUNT to -HUGE(COUNT)). Dividing by it would be a zero divide, giving ! Inf or NaN -- or, under -ffast-math, an unconstrained value -- which ! then propagates into every derived figure such as a FLOP rate. There is ! no time to report on such a processor, so report none. `elapsed` is ! already 0.0_dp here. ! ! A caller cannot distinguish "this processor has no clock" from "no ! measurable time passed" from the result alone. That is deliberate: ! get_elapsed_time is a function used inside expressions, so it has ! nowhere to put an error_t, and both cases mean the same thing to the ! arithmetic downstream. if (self%count_rate <= 0_int64) return if (self%is_running) then call system_clock(count=current_count) elapsed = real(current_count - self%start_count, dp)/real(self%count_rate, dp) else elapsed = real(self%stop_count - self%start_count, dp)/real(self%count_rate, dp) end if #endif end function timer_get_elapsed_time