Reference documentation for deal.II version Git 7e3e0f8 2017-12-13 08:28:15 -0500
Timer Class Reference

#include <deal.II/base/timer.h>

## Classes

struct  ClockMeasurements

## Public Member Functions

Timer ()

Timer (MPI_Comm mpi_communicator, const bool sync_lap_times=false)

const Utilities::MPI::MinMaxAvgget_data () const

const Utilities::MPI::MinMaxAvgget_last_lap_wall_time_data () const

const Utilities::MPI::MinMaxAvgget_total_data () const

const Utilities::MPI::MinMaxAvgget_accumulated_wall_time_data () const

template<class StreamType >
void print_data (StreamType &stream) const

template<class StreamType >
void print_last_lap_wall_time_data (StreamType &stream) const

template<class StreamType >
void print_total_data (StreamType &stream) const

template<class StreamType >
void print_accumulated_wall_time_data (StreamType &stream) const

void start ()

double stop ()

void reset ()

void restart ()

double operator() () const

double wall_time () const

double last_wall_time () const

double cpu_time () const

double last_cpu_time () const

double get_lap_time () const

## Private Types

typedef CPUClock cpu_clock_type

## Private Attributes

ClockMeasurements< wall_clock_typewall_times

ClockMeasurements< cpu_clock_typecpu_times

bool running

MPI_Comm mpi_communicator

bool sync_lap_times

Utilities::MPI::MinMaxAvg last_lap_wall_time_data

Utilities::MPI::MinMaxAvg accumulated_wall_time_data

## Detailed Description

The Timer class provides a way to measure both the amount of wall time (i.e., the amount of time elapsed on a wall clock) and the amount of CPU time that certain sections of an application have used. This class also offers facilities for synchronizing the elapsed time across an MPI communicator.

### Usage

The Timer class can be started and stopped several times. It stores both the amount of time elapsed over the last start-stop cycle, or lap, as well as the total time elapsed over all laps. Here is an example:

Timer timer; // creating a timer also starts it
// do some complicated computations here
// ...
timer.stop();
std::cout << "Elapsed CPU time: " << timer.cpu_time() << " seconds.\n";
std::cout << "Elapsed wall time: " << timer.wall_time() << " seconds.\n";
// reset timer for the next thing it shall do
timer.reset();

Alternatively, you can also restart the timer instead of resetting it. The times between successive calls to start() and stop() (i.e., the laps) will then be accumulated. The usage of this class is also explained in the step-28 tutorial program.

Note
The TimerOutput (combined with TimerOutput::Scope) class provide a convenient way to time multiple named sections and summarize the output.
Implementation of this class is system dependent. In particular, CPU times are accumulated from summing across all threads and will usually exceed the wall times.

Definition at line 117 of file timer.h.

## Member Typedef Documentation

private

typedef for the wall clock.

Definition at line 352 of file timer.h.

 typedef CPUClock Timer::cpu_clock_type
private

typedef for the CPU clock.

Definition at line 357 of file timer.h.

## Constructor & Destructor Documentation

 Timer::Timer ( )

Constructor. Sets the accumulated times at zero and calls Timer::start().

Definition at line 153 of file timer.cc.

 Timer::Timer ( MPI_Comm mpi_communicator, const bool sync_lap_times = false )

Constructor specifying that CPU times should be summed over the given communicator. If sync_lap_times is true then the Timer will set the elapsed wall and CPU times over the last lap to their maximum values across the provided communicator. This synchronization is only performed if Timer::stop() is called before the timer is queried for time duration values.

This constructor calls Timer::start().

Note
The timer is stopped before the synchronization over the communicator occurs; the extra cost of the synchronization is not measured.

Definition at line 160 of file timer.cc.

## Member Function Documentation

 const Utilities::MPI::MinMaxAvg & Timer::get_data ( ) const
inline

Return a reference to the data structure with global timing information for the last lap. This structure does not contain meaningful values until Timer::stop() has been called.

Deprecated:
Use Timer::get_last_lap_wall_time_data() instead, which returns a reference to the same structure.

Definition at line 899 of file timer.h.

 const Utilities::MPI::MinMaxAvg & Timer::get_last_lap_wall_time_data ( ) const
inline

Return a reference to the data structure containing basic statistics on the last lap's wall time measured across all MPI processes in the given communicator. This structure does not contain meaningful values until Timer::stop() has been called.

Definition at line 908 of file timer.h.

 const Utilities::MPI::MinMaxAvg & Timer::get_total_data ( ) const
inline

Return a reference to the data structure containing basic statistics on the accumulated wall time measured across all MPI processes in the given communicator. This structure does not contain meaningful values until Timer::stop() has been called.

Deprecated:
Use Timer::get_accumulated_wall_time_data() instead, which returns a reference the same structure.

Definition at line 917 of file timer.h.

 const Utilities::MPI::MinMaxAvg & Timer::get_accumulated_wall_time_data ( ) const
inline

Return a reference to the data structure containing basic statistics on the accumulated wall time measured across all MPI processes in the given communicator. This structure does not contain meaningful values until Timer::stop() has been called.

Definition at line 926 of file timer.h.

template<class StreamType >
 void Timer::print_data ( StreamType & stream ) const
inline

Prints the data returned by get_data(), i.e. for the last lap, to the given stream.

Deprecated:
Use Timer::print_last_lap_wall_time_data() instead, which prints the same information.

Definition at line 936 of file timer.h.

template<class StreamType >
 void Timer::print_last_lap_wall_time_data ( StreamType & stream ) const
inline

Print the data returned by Timer::get_last_lap_wall_time_data() to the given stream.

Definition at line 946 of file timer.h.

template<class StreamType >
 void Timer::print_total_data ( StreamType & stream ) const
inline

Prints the data returned by get_total_data(), i.e. for the total run, to the given stream.

Deprecated:
Use Timer::print_accumulated_wall_time_data() instead, which prints the same information.

Definition at line 959 of file timer.h.

template<class StreamType >
 void Timer::print_accumulated_wall_time_data ( StreamType & stream ) const
inline

Print the data returned by Timer::get_accumulated_wall_time_data() to the given stream.

Definition at line 969 of file timer.h.

 void Timer::start ( )

Begin measuring a new lap. If sync_lap_times is true then an MPI barrier is used to ensure that all processes begin the lap at the same wall time.

Definition at line 173 of file timer.cc.

 double Timer::stop ( )

Stop the timer. This updates the lap times and accumulated times. If sync_lap_times is true then the lap times are synchronized over all processors in the communicator (i.e., the lap times are set to the maximum lap time).

Return the accumulated CPU time in seconds.

Definition at line 189 of file timer.cc.

 void Timer::reset ( )

Stop the timer, if it is running, and reset all measured values to their default states.

Definition at line 283 of file timer.cc.

 void Timer::restart ( )
inline

Equivalent to calling Timer::reset() followed by calling Timer::start().

Definition at line 889 of file timer.h.

 double Timer::operator() ( ) const

Access to the current CPU time without stopping the timer. The elapsed time is returned in units of seconds.

Deprecated:

Definition at line 254 of file timer.cc.

 double Timer::wall_time ( ) const

Return the current accumulated wall time (including the current lap, if the timer is running) in seconds without stopping the timer.

Definition at line 261 of file timer.cc.

 double Timer::last_wall_time ( ) const

Return the wall time of the last lap in seconds. The timer is not stopped by this function.

Definition at line 276 of file timer.cc.

 double Timer::cpu_time ( ) const

Return the accumulated CPU time (including the current lap, if the timer is running) in seconds without stopping the timer.

If an MPI communicator is provided to the constructor then the returned value is the sum of all accumulated CPU times over all processors in the communicator.

Definition at line 221 of file timer.cc.

 double Timer::last_cpu_time ( ) const

Return the CPU time of the last lap in seconds. The timer is not stopped by this function.

Definition at line 240 of file timer.cc.

 double Timer::get_lap_time ( ) const

Return the wall time taken between the last start()/stop() call.

Deprecated:

Definition at line 247 of file timer.cc.

## Member Data Documentation

 ClockMeasurements Timer::wall_times
private

Collection of wall time measurements.

Definition at line 362 of file timer.h.

 ClockMeasurements Timer::cpu_times
private

Collection of CPU time measurements.

Definition at line 367 of file timer.h.

 bool Timer::running
private

Whether or not the timer is presently running.

Definition at line 372 of file timer.h.

 MPI_Comm Timer::mpi_communicator
private

The communicator over which various time values are synchronized and combined: see the documentation of the relevant constructor for additional information.

Definition at line 379 of file timer.h.

 bool Timer::sync_lap_times
private

Store whether or not the wall time and CPU time are synchronized across the communicator in Timer::start() and Timer::stop().

Definition at line 385 of file timer.h.

 Utilities::MPI::MinMaxAvg Timer::last_lap_wall_time_data
private

A structure for parallel wall time measurement that includes the minimum, maximum, and average over all processors known to the MPI communicator of the last lap time.

Definition at line 392 of file timer.h.

 Utilities::MPI::MinMaxAvg Timer::accumulated_wall_time_data
private

A structure for parallel wall time measurement that includes the minimum time recorded among all processes, the maximum time as well as the average time defined as the sum of all individual times divided by the number of MPI processes in the MPI_Comm for the total run time.

Definition at line 400 of file timer.h.

The documentation for this class was generated from the following files: