Public Member Functions | |
| Timer () | |
| Timer (MPI_Comm mpi_communicator, bool sync_wall_time=false) | |
| const Utilities::System::MinMaxAvg & | get_data () const |
| template<class STREAM > | |
| void | print_data (STREAM &stream) const |
| void | start () |
| double | stop () |
| void | reset () |
| void | restart () |
| double | operator() () const |
| double | wall_time () const |
Private Attributes | |
| double | start_time |
| double | start_time_children |
| double | start_wall_time |
| double | cumulative_time |
| double | cumulative_wall_time |
| bool | running |
| MPI_Comm | mpi_communicator |
| bool | sync_wall_time |
| Utilities::System::MinMaxAvg | mpi_data |
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.
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-12 and step-29 tutorial programs.
| Timer::Timer | ( | ) |
Constructor. Starts the timer at 0 sec.
| Timer::Timer | ( | MPI_Comm | mpi_communicator, |
| 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 the deal.II compiler is an MPI compiler.
| const Utilities::System::MinMaxAvg & Timer::get_data | ( | ) | const [inline] |
| void Timer::print_data | ( | STREAM & | stream | ) | const [inline] |
Prints the data to the given stream.
References Utilities::System::MinMaxAvg::avg, Utilities::System::get_this_mpi_process(), Utilities::System::MinMaxAvg::max, Utilities::System::MinMaxAvg::max_index, Utilities::System::MinMaxAvg::min, Utilities::System::MinMaxAvg::min_index, mpi_communicator, and mpi_data.
| void Timer::start | ( | ) |
Re-start the timer at the point where it was stopped. This way a cumulative measurement of time is possible.
Referenced by restart().
| double Timer::stop | ( | ) |
Sets the current time as next starting time and return the elapsed time in seconds.
| void Timer::reset | ( | ) |
Stop the timer if necessary and reset the elapsed time to zero.
Referenced by restart().
| void Timer::restart | ( | ) | [inline] |
| double Timer::operator() | ( | ) | const |
Access to the current CPU time without disturbing time measurement. The elapsed time is returned in units of seconds.
| double Timer::wall_time | ( | ) | const |
Access to the current wall time without disturbing time measurement. The elapsed time is returned in units of seconds.
double Timer::start_time [private] |
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.
double Timer::start_wall_time [private] |
double Timer::cumulative_time [private] |
Accumulated time for all previous start()/stop() cycles. The time for the present cycle is not included.
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.
bool Timer::running [private] |
Store whether the timer is presently running.
MPI_Comm Timer::mpi_communicator [private] |
Store whether the timer is presently running.
Referenced by print_data().
bool Timer::sync_wall_time [private] |
Store whether the wall time is synchronized between machines.
Utilities::System::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.
Referenced by get_data(), and print_data().
documentation generated on Fri Aug 12 2011 15:01:07 by
doxygen
1.7.4