DUNE-FEM (unstable)

FemTimer Class Reference

class with singleton instance managing timing for parts of program. More...

#include <dune/fem/misc/femtimer.hh>

Detailed Description

class with singleton instance managing timing for parts of program.

The simplest way of timing one line of code is to enclose it with the TIMEDEXECUTION macro; the return value corresponds to the elapsed time, e.g., instead of writting

double error = calcError(u,uh);

use

double used = TIMEDEXECUTION(
double error = calcError(u,uh);
)

A more general usage is through the FemTimer class. The singleton instance can either be accessed through FemTimer::instance or through the reference femTimer. In order to use the timer, it is necessary to define the preprocessor variable FEMTIMER or in the Makefile or in the main file before including the FemTimer header. If FEMTIMER is not defined all methods of the class FemTimer with the exception of start and stop used for the TIMEDEXECUTION macro are empty.

For computing the execution time of any part of a code, first get a unique id from the FemTimer by calling

unsigned int id = FemTimer::addTo(name,subMarkers);

where name is a string used for output and subMarkers is an integer value greaten or equal to one, which can be used to time parts of the program. This can for example be done in the constructor of an operator. Remember to return the id to the FemTimer by calling

FemTimer::removeFrom(id);

To start and stop the time keeping for a given program write

FemTimer::start(id);
// do something
FemTimer::stop(id);

Execution time is summed up over all calls to start and stop. It is possible to pass an operation argument which changes this behavior; sum and max are implemented Using

FemTimer::reset(id);

the main timer (and all its subtimings) are set back to zero. Calling reset without an argument resets all stored timers.

The use of sub timers works as shown in the following example:

#define FEMTIMER
#include <config>
#include <dune/fem/misc/femtimer.hh>
int main ()
{
unsigned int id = FemTimer::addTo("test",2);
FemTimer::start(id);
FemTimer::start(id,1);
// do something
FemTimer::stop(id,1);
FemTimer::start(id,2);
// do something
FemTimer::stop(id,2);
FemTimer::stop(id);
}

Using FemTimer::print(out,"test"); the result of all timings is printed to an ostream. Subtimings are given relative to the main timing, i.e., first the main time is printed and following that the relative time used for each subpart of the algorithm. In the same manner the timing information can be stored in a file using FemTimer::printFile(filename). The first call opens the file and prints the string identifying each timing; each successive call prints one line containing all the timing information, again given first the main timing followed by the relative time used in each sub timing.


The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 27, 22:29, 2024)