A timer instance stores private start times and state flags for the
enabled timing backends. The most recent successful measurement from
each backend is exposed through a public result component:
elapsed_time, cpu_time, elapsed_dtime, and, when enabled,
omp_time and mpi_time.
Start and stop calls must be matched by backend. For example,
timer_start must be followed by timer_stop, and ctimer_start must
be followed by ctimer_stop. Calling a stop routine before its matching
start routine reports an error and leaves the stored result unchanged.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| real(kind=rk), | public | :: | cpu_time | = | 0.0_rk |
Most recent successful CPU-time measurement in seconds. |
|
| real(kind=rk), | public | :: | elapsed_dtime | = | 0.0_rk |
Most recent successful |
|
| real(kind=rk), | public | :: | elapsed_time | = | 0.0_rk |
Most recent successful |
|
| integer(kind=ik), | private | :: | clock_max | = | 0_ik |
Cached maximum |
|
| integer(kind=ik), | private | :: | clock_rate | = | 0_ik |
Cached |
|
| integer(kind=ik), | private | :: | clock_start | = | 0_ik |
|
|
| real(kind=rk), | private | :: | cpu_start | = | 0.0_rk |
CPU time, in seconds, captured by |
|
| real(kind=rk), | private | :: | dtime_start_utc | = | 0.0_rk |
UTC epoch seconds computed from |
|
| logical, | private | :: | is_cpu_started | = | .false. |
True after |
|
| logical, | private | :: | is_dtime_started | = | .false. |
True after |
|
| logical, | private | :: | is_paused | = | .false. |
True after |
|
| logical, | private | :: | is_started | = | .false. |
True after |
|
| integer(kind=ik), | private | :: | pause_start | = | 0_ik |
|
|
| integer(kind=ik), | private | :: | paused_ticks | = | 0_ik |
Total paused duration, in |
Start a CPU-time measurement.
Start the CPU-time timer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(inout) | :: | this |
Timer instance whose CPU-time state is initialized. |
Stop a CPU-time measurement and update cpu_time.
Stop the CPU-time timer and store elapsed CPU seconds.
| 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 CPU 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. |
Append cpu_time to a text file.
Append the last CPU-time result to a text file.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(in) | :: | this |
Timer instance whose |
||
| character(len=*), | intent(in) | :: | file_name |
Path to the output text file. |
Start a date_and_time civil-clock measurement.
Start the date_and_time wall-clock timer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(inout) | :: | this |
Timer instance whose date/time timing state is initialized. |
Stop a date_and_time civil-clock measurement and update elapsed_dtime.
Stop the date_and_time timer and store elapsed seconds.
| 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 date/time duration. |
|
| 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. |
Append elapsed_dtime to a text file.
Append the last date_and_time result to a text file.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(in) | :: | this |
Timer instance whose |
||
| character(len=*), | intent(in) | :: | file_name |
Path to the output text file. |
Pause a running system_clock wall-clock measurement.
Pause a running system_clock wall-clock timer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(inout) | :: | this |
Running wall-clock timer instance to pause. |
Resume a paused system_clock wall-clock measurement.
Resume a paused system_clock wall-clock timer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(inout) | :: | this |
Paused wall-clock timer instance to resume. |
Start a system_clock wall-clock measurement.
Start the system_clock wall-clock timer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(inout) | :: | this |
Timer instance whose wall-clock state is initialized. |
Stop a system_clock wall-clock measurement and update elapsed_time.
Stop the system_clock wall-clock timer and store elapsed seconds.
| 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. |
Append elapsed_time to a text file.
Append the last system_clock result to a text file.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(timer), | intent(in) | :: | this |
Timer instance whose |
||
| character(len=*), | intent(in) | :: | file_name |
Path to the output text file. |
type timer !! author: Seyed Ali Ghasemi !! summary: Timing object with independent state for each supported backend. !! !! A `timer` instance stores private start times and state flags for the !! enabled timing backends. The most recent successful measurement from !! each backend is exposed through a public result component: !! `elapsed_time`, `cpu_time`, `elapsed_dtime`, and, when enabled, !! `omp_time` and `mpi_time`. !! !! Start and stop calls must be matched by backend. For example, !! `timer_start` must be followed by `timer_stop`, and `ctimer_start` must !! be followed by `ctimer_stop`. Calling a stop routine before its matching !! start routine reports an error and leaves the stored result unchanged. integer(ik), private :: clock_rate = 0_ik !! Cached `system_clock` count rate in ticks per second. integer(ik), private :: clock_max = 0_ik !! Cached maximum `system_clock` count used to handle one counter wrap. integer(ik), private :: clock_start = 0_ik !! `system_clock` count captured at the start of the wall-clock interval. integer(ik), private :: pause_start = 0_ik !! `system_clock` count captured when the wall-clock timer is paused. integer(ik), private :: paused_ticks = 0_ik !! Total paused duration, in `system_clock` ticks, excluded from the result. logical, private :: is_started = .false. !! True after `timer_start` and before a successful `timer_stop`. logical, private :: is_paused = .false. !! True after `timer_pause` and before a matching `timer_resume`. real(rk), private :: cpu_start = 0.0_rk !! CPU time, in seconds, captured by `ctimer_start`. logical, private :: is_cpu_started = .false. !! True after `ctimer_start` and before a successful `ctimer_stop`. #if defined(USE_OMP) real(rk), private :: omp_start = 0.0_rk !! OpenMP wall-clock time, in seconds, captured by `otimer_start`. logical, private :: is_omp_started = .false. !! True after `otimer_start` and before a successful `otimer_stop`. #endif #if defined(USE_MPI) real(rk), private :: mpi_start = 0.0_rk !! MPI wall-clock time, in seconds, captured by `mtimer_start`. logical, private :: is_mpi_started = .false. !! True after `mtimer_start` and before a successful `mtimer_stop`. #endif real(rk), private :: dtime_start_utc = 0.0_rk !! UTC epoch seconds computed from `date_and_time` at `dtimer_start`. logical, private :: is_dtime_started = .false. !! True after `dtimer_start` and before a successful `dtimer_stop`. real(rk), public :: elapsed_time = 0.0_rk !! Most recent successful `system_clock` elapsed time in seconds. real(rk), public :: cpu_time = 0.0_rk !! Most recent successful CPU-time measurement in seconds. #if defined(USE_OMP) real(rk), public :: omp_time = 0.0_rk !! Most recent successful OpenMP wall-clock measurement in seconds. #endif #if defined(USE_MPI) real(rk), public :: mpi_time = 0.0_rk !! Most recent successful MPI wall-clock measurement in seconds. #endif real(rk), public :: elapsed_dtime = 0.0_rk !! Most recent successful `date_and_time` elapsed time in seconds. contains procedure, public :: timer_start !! Start a `system_clock` wall-clock measurement. procedure, public :: timer_stop !! Stop a `system_clock` wall-clock measurement and update `elapsed_time`. procedure, public :: timer_write !! Append `elapsed_time` to a text file. procedure, public :: timer_pause !! Pause a running `system_clock` wall-clock measurement. procedure, public :: timer_resume !! Resume a paused `system_clock` wall-clock measurement. procedure, public :: ctimer_start !! Start a CPU-time measurement. procedure, public :: ctimer_stop !! Stop a CPU-time measurement and update `cpu_time`. procedure, public :: ctimer_write !! Append `cpu_time` to a text file. #if defined(USE_OMP) procedure, public :: otimer_start !! Start an OpenMP wall-clock measurement. procedure, public :: otimer_stop !! Stop an OpenMP wall-clock measurement and update `omp_time`. procedure, public :: otimer_write !! Append `omp_time` to a text file. #endif #if defined(USE_MPI) procedure, public :: mtimer_start !! Start an MPI wall-clock measurement. procedure, public :: mtimer_stop !! Stop an MPI wall-clock measurement and update `mpi_time`. procedure, public :: mtimer_write !! Append `mpi_time` to a text file. #endif procedure, public :: dtimer_start !! Start a `date_and_time` civil-clock measurement. procedure, public :: dtimer_stop !! Stop a `date_and_time` civil-clock measurement and update `elapsed_dtime`. procedure, public :: dtimer_write !! Append `elapsed_dtime` to a text file. end type timer