Reference documentation for deal.II version Git 053e5b2 2017-07-21 22:33:36 -0600
Public Member Functions | Private Attributes | List of all members
Timer Class Reference

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

Public Member Functions

 Timer ()
 
 Timer (MPI_Comm mpi_communicator, const bool sync_wall_time=false)
 
const Utilities::MPI::MinMaxAvgget_data () const
 
const Utilities::MPI::MinMaxAvgget_total_data () const
 
template<class StreamType >
void print_data (StreamType &stream) const
 
template<class StreamType >
void print_total_data (StreamType &stream) const
 
void start ()
 
double stop ()
 
void reset ()
 
void restart ()
 
double operator() () const 1
 
double wall_time () const
 
double last_wall_time () const
 
double cpu_time () const
 
double last_cpu_time () const
 
double get_lap_time () const 1
 

Private Attributes

double start_time
 
double start_time_children
 
double start_wall_time
 
double cumulative_time
 
double cumulative_wall_time
 
double last_lap_time
 
double last_lap_cpu_time
 
bool running
 
MPI_Comm mpi_communicator
 
bool sync_wall_time
 
Utilities::MPI::MinMaxAvg mpi_data
 
Utilities::MPI::MinMaxAvg mpi_total_data
 

Detailed Description

This is a very simple class which provides information about both the CPU time and the wallclock time elapsed since the timer was started last time. Information is retrieved from the system on the basis of clock cycles since last time the computer was booted for the CPU time. The wall time is based on the system clock accessed by gettimeofday, with a typical accuracy of 0.01 ms on linux systems.

Usage

Use of this class is as you might expect by looking at the member functions:

Timer timer;
timer.start ();
// do some complicated computations here
...
timer.stop ();
std::cout << "Elapsed CPU time: " << timer() << " seconds.";
std::cout << "Elapsed wall time: " << timer.wall_time() << " seconds.";
// 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() / stop() will then be accumulated. The usage of this class is also explained in the step-28, step-29 and step-30 tutorial programs.

Note
Implementation of this class is system dependent. In case multithreaded routines (matrix-vector products, error estimators, etc.) are used, the CPU time is accumulated from all the children.
Author
G. Kanschat, W. Bangerth, M. Kronbichler

Definition at line 76 of file timer.h.

Constructor & Destructor Documentation

Timer::Timer ( )

Constructor. Starts the timer at 0 sec.

Definition at line 43 of file timer.cc.

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

Constructor that takes an MPI communicator as input. A timer constructed this way will sum up the CPU times over all processors in the MPI network when requested by the operator ().

Starts the timer at 0 sec.

If sync_wall_time is true, the wall time is synchronized between all CPUs using a MPI_Barrier() and a collective operation. Note that this only works if you stop() the timer before querying for the wall time. The time for the MPI operations are not included in the timing but may slow down your program.

This constructor is only available if deal.II is compiled with MPI support.

Definition at line 74 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. Filled after calling stop().

Definition at line 777 of file timer.h.

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

Return a reference to the data structure with global timing information for the total run. Filled after calling stop().

Definition at line 786 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.

Definition at line 796 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.

Definition at line 809 of file timer.h.

void Timer::start ( )

Re-start the timer at the point where it was stopped. This way a cumulative measurement of time is possible.

Definition at line 133 of file timer.cc.

double Timer::stop ( )

Set the current time as next starting time and return the elapsed time in seconds.

Definition at line 172 of file timer.cc.

void Timer::reset ( )

Stop the timer if necessary and reset the elapsed time to zero.

Definition at line 313 of file timer.cc.

void Timer::restart ( )
inline

Resets the elapsed time to zero and starts the timer. This corresponds to calling reset() and start() on the Timer object.

Definition at line 765 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:
Use cpu_time() instead.

Definition at line 277 of file timer.cc.

double Timer::wall_time ( ) const

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

Definition at line 284 of file timer.cc.

double Timer::last_wall_time ( ) const

Access to the wall time since the timer has been stopped the last time. The timer is not stopped by this function. The elapsed time is returned in units of seconds.

Definition at line 306 of file timer.cc.

double Timer::cpu_time ( ) const

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

Definition at line 225 of file timer.cc.

double Timer::last_cpu_time ( ) const

Access to the CPU time since the timer has been stopped the last time. The timer is not stopped by this function. The elapsed time is returned in units of seconds.

Definition at line 263 of file timer.cc.

double Timer::get_lap_time ( ) const

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

Deprecated:
Use last_wall_time() instead.

Definition at line 270 of file timer.cc.

Member Data Documentation

double Timer::start_time
private

Value of the user time when start() was called the last time or when the object was created and no stop() was issued in between.

Definition at line 202 of file timer.h.

double Timer::start_time_children
private

Similar to start_time, but needed for children threads in multithread mode. Value of the user time when start() was called the last time or when the object was created and no stop() was issued in between.

For some reason (error in operating system?) the function call getrusage(RUSAGE_CHILDREN,.) gives always 0 (at least on Solaris7). Hence the Timer class still does not yet work for multithreading mode.

Definition at line 215 of file timer.h.

double Timer::start_wall_time
private

Value of the wall time when start() was called the last time or when the object was created and no stop() was issued in between.

Definition at line 221 of file timer.h.

double Timer::cumulative_time
private

Accumulated time for all previous start()/stop() cycles. The time for the present cycle is not included.

Definition at line 227 of file timer.h.

double Timer::cumulative_wall_time
private

Accumulated wall time for all previous start()/stop() cycles. The wall time for the present cycle is not included.

Definition at line 233 of file timer.h.

double Timer::last_lap_time
private

Stores the wall time between the last start()/stop() cycle.

Definition at line 238 of file timer.h.

double Timer::last_lap_cpu_time
private

Stores the CPU time between the last start()/stop() cycle.

Definition at line 243 of file timer.h.

bool Timer::running
private

Store whether the timer is presently running.

Definition at line 248 of file timer.h.

MPI_Comm Timer::mpi_communicator
private

Store whether the timer is presently running.

Definition at line 253 of file timer.h.

bool Timer::sync_wall_time
private

Store whether the wall time is synchronized between machines.

Definition at line 259 of file timer.h.

Utilities::MPI::MinMaxAvg Timer::mpi_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 last lap.

Definition at line 267 of file timer.h.

Utilities::MPI::MinMaxAvg Timer::mpi_total_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 275 of file timer.h.


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