mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time > Class Template Reference

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
class mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >

A class to track the number of iterations in an OMP parallelized loop.

Uses omp critical directives to deconflict updates by different loops. Example:

ompLoopWatcher<> watcher(1000, std::cout); //Uses defaults
#pragma omp parallel for
int( i=0; i<1000; ++i)
{
watcher.incrementAndOutputStatus();
//Do loop work
...
}

This will result in the following output

1 / 1000 (0.1%) 
2 / 1000 (0.2%)
3 / 1000 (0.3%)

and so on.

Note
This can reduce performance due to critical points it creates if used in fast loops (i.e. do not use inside the inner most loop!).

The behavior of the output is controlled through template parameters. A different output-type can be specified, which needs to accept size_t, and optionally float, and character input using the << operator.

Template Parameters
outputTa type which accepts size_t, float, and character input via the << operator (default is std::ostream).
_printPrettyflag to control whether the output is nicely formatted, if false then just the numbers are sent to the output with no spaces or delimiters (default is true).
_printLoopsflag to control whether the number of loops is sent to the output each time (default is true).
_printPercentflag to control whether the percentage complete is calculated (default is true).
_printNLineflag to control whether the newline '\n' is sent ot output (default is false). If false, '\r' is written at end of output.
_timeflag to control whether time is tracked. Default is true.

Definition at line 75 of file ompLoopWatcher.hpp.

#include <ipc/ompLoopWatcher.hpp>

Public Member Functions

 ompLoopWatcher (size_t nLoops, outputT &output)
 Constructor. More...
 
void increment ()
 Increment the counter. More...
 
void advance (size_t diff_count)
 Advance the counter by a number of steps. More...
 
void outputStatus ()
 Output current status. More...
 
void incrementAndOutputStatus ()
 Increment and output status. More...
 
void advanceAndOutputStatus (size_t diff_count)
 Advance and output status. More...
 

Protected Member Functions

void _increment ()
 Increment the counter. More...
 
void _advance (size_t diff_count)
 Advance the counter by a number of steps. More...
 
void _outputStatus ()
 Perform the output. More...
 

Protected Attributes

size_t _nLoops
 The total number of loops. More...
 
size_t _counter
 The current counter. More...
 
outputT * _output
 Pointer to the instance of type outputT. More...
 

Constructor & Destructor Documentation

◆ ompLoopWatcher()

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::ompLoopWatcher ( size_t  nLoops,
outputT &  output 
)
inline

Member Function Documentation

◆ _advance()

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
void mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_advance ( size_t  diff_count)
inlineprotected

◆ _increment()

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
void mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_increment ( )
inlineprotected

◆ _outputStatus()

◆ advance()

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
void mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::advance ( size_t  diff_count)
inline

Advance the counter by a number of steps.

Call this once per loop. It contains an omp critical directive.

Definition at line 169 of file ompLoopWatcher.hpp.

References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_advance().

◆ advanceAndOutputStatus()

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
void mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::advanceAndOutputStatus ( size_t  diff_count)
inline

Advance and output status.

Call this to advance and then give a status update. Has only one omp critical directive for the two steps.

Definition at line 199 of file ompLoopWatcher.hpp.

References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_advance(), and mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_outputStatus().

◆ increment()

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
void mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::increment ( )
inline

Increment the counter.

Call this once per loop. It contains an omp critical directive.

Definition at line 160 of file ompLoopWatcher.hpp.

References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_increment().

◆ incrementAndOutputStatus()

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
void mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::incrementAndOutputStatus ( )
inline

◆ outputStatus()

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
void mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::outputStatus ( )
inline

Output current status.

Call this whenever you want a status update. It contains an omp critical directive.

Definition at line 178 of file ompLoopWatcher.hpp.

References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_outputStatus().

Member Data Documentation

◆ _counter

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
size_t mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_counter
protected

◆ _nLoops

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
size_t mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_nLoops
protected

◆ _output

template<class _outputT = std::ostream, bool _printPretty = true, bool _printLoops = true, bool _printPercent = true, bool _printNLine = false, bool _time = true>
outputT* mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_output
protected

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