SF_TIMER

Description

SciFortran module for timers

Quick access

Routines:

eta(), progress(), start_progress(), start_timer(), stop_progress(), stop_timer(), t_start(), t_stop()

Used modules

  • sf_mpi: SciFortran MPI interface

Subroutines and functions

interface  sf_timer/start_progress([title, unit])

Generic interface to start a timer, to be stopped with stop_progress. It is an alias of start_timer, whose arguments are documented there.

At the moment of the call the timer records three clocks: the wall clock (system_clock, or MPI_Wtime when compiled with MPI and MPI is initialized), the CPU time (cpu_time) and the date and time (date_and_time). It also resets the state used by eta and progress, which need therefore a started timer. Timers can be nested, the last started being the first to be stopped, up to 1000 at the same time: the program stops otherwise.

All the output of the timer, i.e. the title, the messages of eta and progress, and the elapsed time printed by stop_progress, is written to the unit unit. The default is the standard output (unit 6), plus the rank of the process when compiled with MPI, so that each process writes to its own unit; unit 5 is replaced by 6.

Options:
  • title [character(len=*)] – optional: title, printed on the unit of the timer

  • unit [integer] – optional: output unit of the timer, default 6 (+ MPI rank)

interface  sf_timer/stop_progress([msg])

Generic interface to stop the most recently started timer, see start_progress. It is an alias of stop_timer, whose argument is documented there.

The elapsed CPU time and, in parentheses, the elapsed wall-clock time are printed on the unit of the timer, both as hhh:mm:ss.mmm, followed by msg if present: CPU time (wall time): hhh:mm:ss.mmm (hhh:mm:ss.mmm) : msg. The timer is then released.

Options:

msg [character(len=*)] – optional: message, printed after the elapsed time

function  sf_timer/t_start()

This function starts a timer, to be read with t_stop, to measure the time elapsed between two calls, e.g. for profiling. It is independent of start_timer. Timers can be nested, the last started being the first to be stopped, up to 1000 at the same time: the program stops otherwise. The wall clock is MPI_Wtime when compiled with MPI and MPI is initialized, system_clock otherwise. The returned value is always zero.

Result:

pr_t [real] – always 0

function  sf_timer/t_stop()

This function stops the timer most recently started with t_start, releases it, and returns the time elapsed since its start, in seconds.

Result:

pr_t [real] – time elapsed since the matching t_start, in seconds

subroutine  sf_timer/start_timer([title, unit])
Options:
  • title [character(len=*)] – optional: title, printed on the unit of the timer

  • unit [integer] – optional: output unit of the timer, default 6 (+ MPI rank)

subroutine  sf_timer/stop_timer([msg])
Options:

msg [character(len=*)] – optional: message, printed after the elapsed time

subroutine  sf_timer/eta(i, l[, step, method])

This subroutine prints the Expected Time of Arrival (ETA) of a loop of L iterations, to be called at every iteration i. It requires a timer started with start_timer, and it writes on the unit of that timer.

The ETA is the average time per iteration spent so far, times the number of iterations, minus the elapsed time. It is printed only when the completion percentage reaches a multiple of step, as NNN% |ETA: hhh:mm:ss.mmm; at 10%, 50% and 100% the date and time are appended. The internal state is reset when i==L, so that the routine can be used for the next loop. The clock used is selected by the first character of method: c (default) for cpu_time, d for date_and_time, anything else, e.g. s, for system_clock (wall time).

Parameters:
  • i [integer] – current iteration

  • l [integer] – total number of iterations

Options:
  • step [integer] – optional: print every step percent, default 10

  • method [character(len=*)] – optional: clock, ‘c’ cpu_time (default), ‘d’ date_and_time, ‘s’ system_clock

subroutine  sf_timer/progress(i, imax[, method])

This subroutine prints a progress bar with the Expected Time of Arrival (ETA), to be called at every iteration i of a loop of imax iterations. It requires a timer started with start_timer, and it writes on the unit of that timer.

The bar has 50 characters, and it is updated in place on the same line, followed by the ETA computed as in eta: NNN% |*****     | ETA h:mm:ss.mmm. The line is terminated by the last call, i==imax. The clock used is selected by the first character of method: c (default) for cpu_time, d for date_and_time, anything else, e.g. s, for system_clock (wall time).

Parameters:
  • i [integer] – current iteration

  • imax [integer] – total number of iterations

Options:

method [character(len=*)] – optional: clock, ‘c’ cpu_time (default), ‘d’ date_and_time, ‘s’ system_clock