Stops the timer and calculates the elapsed time. Optionally, it can print a message along with the elapsed time.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(timer), | intent(inout) | :: | this | |||
integer, | intent(in), | optional | :: | nloops | ||
character(len=*), | intent(in), | optional | :: | message | ||
logical, | intent(in), | optional | :: | |||
character(len=*), | intent(in), | optional | :: | color |
impure subroutine timer_stop(this, nloops, message, print, color) class(timer), intent(inout) :: this integer, intent(in), optional :: nloops character(*), intent(in), optional :: message character(:), allocatable :: msg logical, intent(in), optional :: print character(*), intent(in), optional :: color ! Stop the timer call system_clock(count=this%clock_end) ! Calculate the elapsed processor ticks this%clock_elapsed = this%clock_end - this%clock_start ! Convert processor ticks to seconds if (.not.present(nloops)) & this%elapsed_time = real(this%clock_elapsed, kind=rk) / real(this%clock_rate, kind=rk) if ( present(nloops)) & this%elapsed_time = real(this%clock_elapsed, kind=rk) / real(this%clock_rate, kind=rk) / real(nloops, kind=rk) ! Print the elapsed time if (.not. present(message)) then msg = "Elapsed time:" else msg = message end if if (present(print)) then if (print) call print_time(this%elapsed_time, msg, color) else call print_time(this%elapsed_time, msg, color) end if ! Deallocate the message if (allocated(msg)) deallocate(msg) end subroutine timer_stop