mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
A class to track the number of iterations in an OMP parallelized loop.
Uses omp critical directives to deconflict updates by different loops. Example:
This will result in the following output
1 / 1000 (0.1%) 2 / 1000 (0.2%) 3 / 1000 (0.3%)
and so on.
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.
outputT | a type which accepts size_t, float, and character input via the << operator (default is std::ostream). |
_printPretty | flag 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). |
_printLoops | flag to control whether the number of loops is sent to the output each time (default is true). |
_printPercent | flag to control whether the percentage complete is calculated (default is true). |
_printNLine | flag to control whether the newline '\n' is sent ot output (default is false). If false, '\r' is written at end of output. |
_time | flag 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... | |
|
inline |
Constructor.
Registers the output and sets the number of loops.
nLoops | is the total number of loops. |
output | is the instance of type outputT to which the output will be sent. |
Definition at line 147 of file ompLoopWatcher.hpp.
References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_counter, mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_nLoops, mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_output, and mx::sys::get_curr_time().
|
inlineprotected |
Advance the counter by a number of steps.
Definition at line 97 of file ompLoopWatcher.hpp.
References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_counter, and mx::sys::get_curr_time().
Referenced by mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::advance(), and mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::advanceAndOutputStatus().
|
inlineprotected |
Increment the counter.
Definition at line 90 of file ompLoopWatcher.hpp.
References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_counter, and mx::sys::get_curr_time().
Referenced by mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::increment(), and mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::incrementAndOutputStatus().
|
inlineprotected |
Perform the output.
Definition at line 104 of file ompLoopWatcher.hpp.
References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_counter, and mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_nLoops.
Referenced by mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::advanceAndOutputStatus(), mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::incrementAndOutputStatus(), and mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::outputStatus().
|
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.
|
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().
|
inline |
Increment the counter.
Call this once per loop. It contains an omp critical directive.
Definition at line 160 of file ompLoopWatcher.hpp.
|
inline |
Increment and output status.
Call this to increment and then give a status update. Has only one omp critical directive for the two steps.
Definition at line 187 of file ompLoopWatcher.hpp.
References mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_increment(), and mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_outputStatus().
Referenced by mx::AO::analysis::fourierVarVec(), mx::AO::analysis::fourierTemporalPSD< _realT, aosysT >::makePSDGrid(), and mx::improc::KLIPreduction< _realT, _derotFunctObj, _evCalcT >::worker().
|
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.
|
protected |
The current counter.
Definition at line 82 of file ompLoopWatcher.hpp.
Referenced by mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::ompLoopWatcher(), mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_advance(), mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_increment(), and mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_outputStatus().
|
protected |
The total number of loops.
Definition at line 81 of file ompLoopWatcher.hpp.
Referenced by mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::ompLoopWatcher(), and mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::_outputStatus().
|
protected |
Pointer to the instance of type outputT.
Definition at line 87 of file ompLoopWatcher.hpp.
Referenced by mx::ipc::ompLoopWatcher< _outputT, _printPretty, _printLoops, _printPercent, _printNLine, _time >::ompLoopWatcher().