Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Classes | Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
TimerOutput Class Reference

#include <timer.h>

Classes

class  Scope
 
struct  Section
 

Public Types

enum  OutputFrequency { every_call, summary, every_call_and_summary, never }
 
enum  OutputType { cpu_times, wall_times, cpu_and_wall_times }
 

Public Member Functions

 TimerOutput (std::ostream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type)
 
 TimerOutput (ConditionalOStream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type)
 
 TimerOutput (MPI_Comm mpi_comm, std::ostream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type)
 
 TimerOutput (MPI_Comm mpi_comm, ConditionalOStream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type)
 
 ~TimerOutput ()
 
void enter_subsection (const std::string &section_name)
 
void enter_section (const std::string &section_name)
 
void leave_subsection (const std::string &section_name=std::string())
 
void exit_section (const std::string &section_name=std::string())
 
void print_summary () const
 
void disable_output ()
 
void enable_output ()
 
void reset ()
 

Public Attributes

enum TimerOutput::OutputFrequency output_frequency
 
enum TimerOutput::OutputType output_type
 

Private Attributes

Timer timer_all
 
std::map< std::string, Sectionsections
 
ConditionalOStream out_stream
 
bool output_is_enabled
 
std::list< std::string > active_sections
 
MPI_Comm mpi_communicator
 
Threads::Mutex mutex
 

Detailed Description

This class can be used to generate formatted output from time measurements of different subsections in a program. It is possible to create several sections that perform certain aspects of the program. A section can be entered several times. By changing the options in OutputFrequency and OutputType, the user can choose whether output should be generated every time a section is joined or just in the end of the program. Moreover, it is possible to show CPU times, wall times or both.

Usage

Use of this class could be as follows:

TimerOutput timer (std::cout, TimerOutput::summary,
TimerOutput::wall_times);
timer.enter_subsection ("Setup dof system");
setup_dofs();
timer.leave_subsection();
timer.enter_subsection ("Assemble");
assemble_system_1();
timer.leave_subsection();
timer.enter_subsection ("Solve");
solve_system_1();
timer.leave_subsection();
timer.enter_subsection ("Assemble");
assemble_system_2();
timer.leave_subsection();
timer.enter_subsection ("Solve");
solve_system_2();
timer.leave_subsection();
// do something else...

When run, this program will return an output like this:

+---------------------------------------------+------------+------------+
| Total wallclock time elapsed since start | 88.8s | |
| | | |
| Section | no. calls | wall time | % of total |
+---------------------------------+-----------+------------+------------+
| Assemble | 2 | 19.7s | 22% |
| Solve | 2 | 3.03s | 3.4% |
| Setup dof system | 1 | 3.97s | 4.5% |
+---------------------------------+-----------+------------+------------+

The output will see that we entered the assembly and solve section twice, and reports how much time we spent there. Moreover, the class measures the total time spent from start to termination of the TimerOutput object. In this case, we did a lot of other stuff, so that the time proportions of the functions we measured are far away from 100 precent.

See the step-32 tutorial program for usage of this class.

Author
M. Kronbichler, 2009.

Definition at line 325 of file timer.h.

Member Enumeration Documentation

Sets whether to generate output every time we exit a section, just in the end, both, or never.

Definition at line 368 of file timer.h.

Sets whether to show CPU times, wall times, or both CPU and wall times.

Definition at line 375 of file timer.h.

Constructor & Destructor Documentation

TimerOutput::TimerOutput ( std::ostream &  stream,
const enum OutputFrequency  output_frequency,
const enum OutputType  output_type 
)

Constructor that takes std::cout as output stream.

TimerOutput::TimerOutput ( ConditionalOStream stream,
const enum OutputFrequency  output_frequency,
const enum OutputType  output_type 
)

Constructor that takes a ConditionalOStream to write output to.

TimerOutput::TimerOutput ( MPI_Comm  mpi_comm,
std::ostream &  stream,
const enum OutputFrequency  output_frequency,
const enum OutputType  output_type 
)

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 for calculating the CPU time.

Meant for using std::cout as output stream.

TimerOutput::TimerOutput ( MPI_Comm  mpi_comm,
ConditionalOStream stream,
const enum OutputFrequency  output_frequency,
const enum OutputType  output_type 
)

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 for calculating the CPU time.

Constructor that takes a ConditionalOStream to write output to.

TimerOutput::~TimerOutput ( )

Destructor. Calls print_summary() in case the option for writing the summary output is set.

Member Function Documentation

void TimerOutput::enter_subsection ( const std::string &  section_name)

Open a section by given a string name of it. In case the name already exists, that section is done once again.

void TimerOutput::enter_section ( const std::string &  section_name)
inline

Same as enter_subsection.

Definition at line 614 of file timer.h.

void TimerOutput::leave_subsection ( const std::string &  section_name = std::string())

Leave a section. If no name is given, the last section that was entered is left.

void TimerOutput::exit_section ( const std::string &  section_name = std::string())
inline

Same as leave_subsection.

Definition at line 623 of file timer.h.

void TimerOutput::print_summary ( ) const

Print a formatted table that summarizes the time consumed in the various sections.

void TimerOutput::disable_output ( )

By calling this function, all output can be disabled. This function together with enable_output() can be useful if one wants to control the output in a flexible way without putting a lot of if clauses in the program.

void TimerOutput::enable_output ( )

This function re-enables output of this class if it was previously disabled with disable_output(). This function together with disable_output() can be useful if one wants to control the output in a flexible way without putting a lot of if clauses in the program.

void TimerOutput::reset ( )

Resets the recorded timing information.

Member Data Documentation

Timer TimerOutput::timer_all
private

A timer object for the overall run time. If we are using MPI, this timer also accumulates over all MPI processes.

Definition at line 509 of file timer.h.

std::map<std::string, Section> TimerOutput::sections
private

A list of all the sections and their information.

Definition at line 528 of file timer.h.

ConditionalOStream TimerOutput::out_stream
private

The stream object to which we are to output.

Definition at line 534 of file timer.h.

bool TimerOutput::output_is_enabled
private

A boolean variable that sets whether output of this class is currently on or off.

Definition at line 541 of file timer.h.

std::list<std::string> TimerOutput::active_sections
private

A list of the sections that have been entered and not exited. The list is kept in the order in which sections have been entered, but elements may be removed in the middle if an argument is given to the exit_section() function.

Definition at line 554 of file timer.h.

MPI_Comm TimerOutput::mpi_communicator
private

mpi communicator

Definition at line 559 of file timer.h.

Threads::Mutex TimerOutput::mutex
private

A lock that makes sure that this class gives reasonable results even when used with several threads.

Definition at line 566 of file timer.h.


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