Stops the timer and calculates the CPU time. Optionally, it can print a message along with the CPU 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 ctimer_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 cpu_time(this%cpu_end) ! Calculate the elapsed CPU time this%cpu_elapsed = this%cpu_end - this%cpu_start ! Convert CPU time to seconds if (.not.present(nloops)) this%cpu_time = this%cpu_elapsed if ( present(nloops)) this%cpu_time = this%cpu_elapsed / real(nloops, kind=rk) ! Print the elapsed time if (.not. present(message)) then msg = "CPU time:" else msg = message end if if (present(print)) then if (print) call print_time(this%cpu_time, msg, color) else call print_time(this%cpu_time, msg, color) end if ! Deallocate the message if (allocated(msg)) deallocate(msg) end subroutine ctimer_stop