OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::util::Timer< T > Class Template Reference

How to use in Code: More...

#include <timer.h>

+ Collaboration diagram for olb::util::Timer< T >:

Public Member Functions

 Timer (int maxTimeSteps, std::size_t numFluidCells=1, unsigned int printModeSummary=0)
 initializes timer with the given values, abbreviation to Timer() + initialize(int,int)
 
timevalDiffTimeMs (timeval end, timeval start)
 returns the time difference between two timeval objects in ms
 
getMLUPs ()
 returns Million DESCRIPTOR Site Updates per second (all processes together)
 
getMLUPps ()
 returns Million DESCRIPTOR Site Updates per second and process
 
getTotalMLUPs ()
 returns average Million DESCRIPTOR Site Updates per second between start() and stop()
 
getTotalMLUPps ()
 returns average Million DESCRIPTOR Site Updates per second and process between start() and stop()
 
void start ()
 (Re-)sets start value for time measurement.
 
void update (int currentTimeStep)
 Updates all time values of interest during computation.
 
void stop ()
 Terminates time measurement and sets end value.
 
double getTotalCpuTime ()
 Returns the total cpu time in seconds between start() and stop().
 
getTotalRealTime ()
 Returns the total measured time between start() and stop() in seconds.
 
getTotalRealTimeMs ()
 Returns the total measured time between start() and stop() in ms.
 
void printStep (int printMode=0)
 Prints a one-line-summary of the values calculated in update() for use during computation.
 
void printStep (OstreamManager &fout, int printMode=0)
 
void print (std::size_t currentTimeStep, int printMode=0)
 Performs an update() followed by a printStep().
 
void printSummary ()
 Prints a (short) summary containing the overall time consumption in real and in cpu time for use after computation.
 
void printSummary (OstreamManager &fout)
 
void printShortSummary ()
 Prints a short summary containing only time consumptions (real and cpu time)
 
void printShortSummary (OstreamManager &fout)
 

Detailed Description

template<typename T>
class olb::util::Timer< T >

How to use in Code:

Timer timer;
timer.inizialize();

timer.start();

loop(i=1..iMax)
{
  do_some_calculation();
  timer.print(i);
} end_loop;

timer.stop();

timer.printSummary();

class for measurement of computation time

Definition at line 72 of file timer.h.

Constructor & Destructor Documentation

◆ Timer()

template<typename T >
olb::util::Timer< T >::Timer ( int maxTimeSteps,
std::size_t numFluidCells = 1,
unsigned int printModeSummary = 0 )

initializes timer with the given values, abbreviation to Timer() + initialize(int,int)

Definition at line 36 of file timer.hh.

37 : clout(std::cout,"Timer"),
38 deltaTS(0), curTS(0), maxTS(maxTimeSteps),
39 numFC(numFluidCells), rtRemMs(1) // avoids some stupid numbers in first call of printStep() (not for T=double)
40
41{
42 tp = nullptr;
43 this->_printModeSummary = printModeSummary;
44}

Member Function Documentation

◆ getMLUPps()

template<typename T >
T olb::util::Timer< T >::getMLUPps ( )

returns Million DESCRIPTOR Site Updates per second and process

Definition at line 62 of file timer.hh.

63{
64 T mlupps = getMLUPs()/singleton::mpi().getSize();
65#ifdef PARALLEL_MODE_OMP
66 mlupps /= singleton::omp().getSize();
67#endif
68 return mlupps;
69}
int getSize() const
Returns the number of processes.
T getMLUPs()
returns Million DESCRIPTOR Site Updates per second (all processes together)
Definition timer.hh:55
MpiManager & mpi()
ompManager omp()
int getSize() const

References olb::singleton::MpiManager::getSize(), olb::ompManager::getSize(), olb::singleton::mpi(), and olb::singleton::omp().

+ Here is the call graph for this function:

◆ getMLUPs()

template<typename T >
T olb::util::Timer< T >::getMLUPs ( )

returns Million DESCRIPTOR Site Updates per second (all processes together)

Definition at line 55 of file timer.hh.

56{
57 T mlups = (numFC * deltaTS) / (timevalDiffTimeMs(msTimeCur, msTimeLast)*1000);
58 return mlups;
59}
T timevalDiffTimeMs(timeval end, timeval start)
returns the time difference between two timeval objects in ms
Definition timer.hh:47

◆ getTotalCpuTime()

template<typename T >
double olb::util::Timer< T >::getTotalCpuTime ( )

Returns the total cpu time in seconds between start() and stop().

Definition at line 134 of file timer.hh.

135{
136 return (cpuTimeEnd-cpuTimeStart)/CLOCKS_PER_SEC;
137}

◆ getTotalMLUPps()

template<typename T >
T olb::util::Timer< T >::getTotalMLUPps ( )

returns average Million DESCRIPTOR Site Updates per second and process between start() and stop()

Definition at line 79 of file timer.hh.

80{
81 T tmlupps = getTotalMLUPs()/singleton::mpi().getSize();
82#ifdef PARALLEL_MODE_OMP
83 tmlupps /= singleton::omp().getSize();
84#endif
85 return tmlupps;
86}
T getTotalMLUPs()
returns average Million DESCRIPTOR Site Updates per second between start() and stop()
Definition timer.hh:72

References olb::singleton::MpiManager::getSize(), olb::ompManager::getSize(), olb::singleton::mpi(), and olb::singleton::omp().

+ Here is the call graph for this function:

◆ getTotalMLUPs()

template<typename T >
T olb::util::Timer< T >::getTotalMLUPs ( )

returns average Million DESCRIPTOR Site Updates per second between start() and stop()

Definition at line 72 of file timer.hh.

73{
74 T tmlups = (numFC * curTS) / double(timevalDiffTimeMs(msTimeEnd, msTimeStart)*1000);
75 return tmlups;
76}

◆ getTotalRealTime()

template<typename T >
T olb::util::Timer< T >::getTotalRealTime ( )

Returns the total measured time between start() and stop() in seconds.

Definition at line 140 of file timer.hh.

141{
142 return difftime(sTimeEnd,sTimeStart);
143}

◆ getTotalRealTimeMs()

template<typename T >
T olb::util::Timer< T >::getTotalRealTimeMs ( )

Returns the total measured time between start() and stop() in ms.

Definition at line 146 of file timer.hh.

147{
148 return timevalDiffTimeMs(msTimeEnd, msTimeStart);
149}

◆ print()

template<typename T >
void olb::util::Timer< T >::print ( std::size_t currentTimeStep,
int printMode = 0 )

Performs an update() followed by a printStep().

Automatically calls the function update(currentTimeStep) (if not yet done with currentTimeStep) and displays the timer's during-iteration-information.

Parameters
currentTimeStepcurrent iteration value, e.g. i or iT
printModemode of display style passed to printStep()
See also
printStep()

Definition at line 152 of file timer.hh.

153{
154 if (currentTimeStep!=curTS) {
155 update(currentTimeStep);
156 }
157 printStep(printMode);
158}
void printStep(int printMode=0)
Prints a one-line-summary of the values calculated in update() for use during computation.
Definition timer.hh:161
void update(int currentTimeStep)
Updates all time values of interest during computation.
Definition timer.hh:99

◆ printShortSummary() [1/2]

template<typename T >
void olb::util::Timer< T >::printShortSummary ( )

Prints a short summary containing only time consumptions (real and cpu time)

Definition at line 244 of file timer.hh.

245{
246 printShortSummary(clout);
247}
void printShortSummary()
Prints a short summary containing only time consumptions (real and cpu time)
Definition timer.hh:244

◆ printShortSummary() [2/2]

template<typename T >
void olb::util::Timer< T >::printShortSummary ( OstreamManager & fout)

Definition at line 250 of file timer.hh.

251{
252 fout << "realTime=" << (int)getTotalRealTimeMs()/1000 << "." << (int)getTotalRealTimeMs()-(int)getTotalRealTimeMs()/1000*1000
253 << "; cpuTime=" << std::setprecision(3) << std::fixed << getTotalCpuTime() << std::endl;
254}
double getTotalCpuTime()
Returns the total cpu time in seconds between start() and stop().
Definition timer.hh:134
T getTotalRealTimeMs()
Returns the total measured time between start() and stop() in ms.
Definition timer.hh:146

◆ printStep() [1/2]

template<typename T >
void olb::util::Timer< T >::printStep ( int printMode = 0)

Prints a one-line-summary of the values calculated in update() for use during computation.

Displays timer informations about current calculation with two different output modes. Before calling printStep() one should first recalculate all values with update().

Parameters
printModeValue for selecting style of output.
0 = default semicolon-separated single row mode without cpu-time
1 = single row mode without cpu-time
2 = nicely formatted two-line layout including current and remaining cpu-time
See also
update()

Definition at line 161 of file timer.hh.

162{
163 printStep(clout, printMode);
164}

◆ printStep() [2/2]

template<typename T >
void olb::util::Timer< T >::printStep ( OstreamManager & fout,
int printMode = 0 )

Definition at line 167 of file timer.hh.

168{
169 switch (printMode) {
170 case 0: //single-line layout, usable for data extraction as csv
171 fout
172 << "step=" << curTS << "; "
173 // << "stepMax=" << maxTS << "; "
174 << "percent=" << 100.0*curTS/maxTS << "; "
175 << "passedTime=" << (double)rtPasMs/1000 << "; "
176 // << "totalTime=" << (double)rtTotMs/1000 << "; "
177 << "remTime=" << rtRemMs/1000 << "; "
178 << "MLUPs=" << getMLUPs()
179 << std::endl;
180 break;
181
182 case 1: //single-line layout (not conform with output-rules)
183 fout
184 << "latticeTS: "
185 << curTS << "/" << maxTS << " (" << 100*curTS/maxTS << "%); "
186 << "pas/totTime: "
187 << std::setprecision(2) << std::fixed << (double)rtPasMs/1000 << "/"
188 << std::setprecision(1) << std::fixed << (double)rtTotMs/1000 << "s; "
189 << "remTime: "
190 << std::setw(2) << (int)((double)rtRemMs/1000)/60 << "m " << std::setfill('0') << std::setw(4) << (double)((int)((double)rtRemMs/100)%600)/10 << "s; "
191 << std::setfill(' ')
192 << "MLUPs: " << getMLUPs()
193 << std::endl;
194 break;
195
196 case 2: //pretty double line layout in colums, but non-conform
197 fout
198 << std::setw(21) << std::left << "Lattice-Timesteps"
199 << std::setw(17) << std::left << "| CPU time/estim"
200 << std::setw(18) << std::left << "| REAL time/estim"
201 << std::setw(6) << std::left << "| ETA"
202 << std::setw(6) << std::left << "| MLUPs"
203 << std::endl << std::right
204 << std::setw(6) << std::setprecision(2) << std::fixed << curTS << "/" << std::setw(6) << maxTS << " (" << std::setw(3) << 100*curTS/maxTS << "%) |"
205 << std::setw(7) << ctPas << "/" << std::setw(7) << ctTot << " |"
206 << std::setw(8) << (double)rtPasMs/1000 << "/" << std::setw(7) << (double)rtTotMs/1000 << " |"
207 << std::setw(4) << (int)rtRemMs/1000+1 << " |"
208 << std::setw(6) << getMLUPs()
209 << std::endl;
210 break;
211
212 case 3: //performance output only
213 fout
214 << "step " << curTS << "; "
215 << "MLUPs=" << std::setw(8) << getMLUPs() << ", MLUPps=" << std::setw(8) << getMLUPps() << std::endl;
216 break;
217
218 default:
219 fout << "Error in function printStep in class_timer.h: printMode="<<printMode<<" not found" << std::endl << std::flush;
220 }
221}
T getMLUPps()
returns Million DESCRIPTOR Site Updates per second and process
Definition timer.hh:62

◆ printSummary() [1/2]

template<typename T >
void olb::util::Timer< T >::printSummary ( )

Prints a (short) summary containing the overall time consumption in real and in cpu time for use after computation.

Definition at line 224 of file timer.hh.

225{
226 printSummary(clout);
227}
void printSummary()
Prints a (short) summary containing the overall time consumption in real and in cpu time for use afte...
Definition timer.hh:224

◆ printSummary() [2/2]

template<typename T >
void olb::util::Timer< T >::printSummary ( OstreamManager & fout)

Definition at line 230 of file timer.hh.

231{
232 fout << std::endl;
233 fout << "----------------Summary:Timer----------------" << std::endl;
234 fout << "measured time (rt) : " << (int)getTotalRealTimeMs()/1000 << "." << (int)getTotalRealTimeMs()-(int)getTotalRealTimeMs()/1000*1000 << "s" << std::endl;
235 fout << "measured time (cpu): " << std::setprecision(3) << std::fixed << getTotalCpuTime() << "s" << std::endl;
236 if (numFC > 0 && curTS > 0) {
237 fout << "average MLUPs : " << getTotalMLUPs() << std::endl;
238 fout << "average MLUPps: " << getTotalMLUPps() << std::endl;
239 }
240 fout << "---------------------------------------------" << std::endl;
241}
T getTotalMLUPps()
returns average Million DESCRIPTOR Site Updates per second and process between start() and stop()
Definition timer.hh:79

◆ start()

template<typename T >
void olb::util::Timer< T >::start ( )

(Re-)sets start value for time measurement.

Definition at line 90 of file timer.hh.

91{
92 sTimeStart = time(tp); // time in s
93 gettimeofday(&msTimeStart, nullptr); // time in ms
94 gettimeofday(&msTimeCur, nullptr); // time in ms, here only necessary for MLUP-calculations
95 cpuTimeStart = clock(); //cpu-time
96}

◆ stop()

template<typename T >
void olb::util::Timer< T >::stop ( )

Terminates time measurement and sets end value.

It is necessary to call this function immediately after the computation loop has terminated. Otherwise printSummary() would display incorrect values.

See also
printSummary()

Definition at line 126 of file timer.hh.

127{
128 cpuTimeEnd = clock(); // cpu-time
129 sTimeEnd = time(tp); // time in s
130 gettimeofday(&msTimeEnd, nullptr); // time in ms
131}

◆ timevalDiffTimeMs()

template<typename T >
T olb::util::Timer< T >::timevalDiffTimeMs ( timeval end,
timeval start )

returns the time difference between two timeval objects in ms

The timeval data type is used in the variables for ms-time measurement.

See also
getTotalRealTimeMs

Definition at line 47 of file timer.hh.

48{
49 const T msDiff ( 1000*(end.tv_sec - start.tv_sec)
50 +(end.tv_usec-start.tv_usec)/1000 );
51 return util::max<T>(msDiff, 1.0);
52}
void start()
(Re-)sets start value for time measurement.
Definition timer.hh:90

◆ update()

template<typename T >
void olb::util::Timer< T >::update ( int currentTimeStep)

Updates all time values of interest during computation.

i.e. elapsed time, remaining time and total time. Recommended to be used directly before printStep to output up-to-date values.

Definition at line 99 of file timer.hh.

100{
101
102 cpuTimeCur = clock(); // CPU-time
103 sTimeCur = time(tp); // time in s
104 msTimeLast = msTimeCur;
105 gettimeofday(&msTimeCur, nullptr); // time in ms
106
107 // calculate and update missing time-values
108 deltaTS = currentTimeStep - curTS; // this makes multiple calls
109 curTS = currentTimeStep; // of update() critical
110
111 rtPas = difftime(sTimeCur,sTimeStart); // here calculation is based on s-time
112 rtTot = rtPas*maxTS/util::max<int>(curTS, 1);
113 rtRem = rtTot-rtPas;
114
115 rtPasMs = timevalDiffTimeMs(msTimeCur, msTimeStart); // here with ms-time as timeval-value
116 rtTotMs = rtPasMs*maxTS/util::max<int>(curTS, 1);
117 rtRemMs = rtTotMs-rtPasMs;
118
119 ctPas = (cpuTimeCur-cpuTimeStart)/CLOCKS_PER_SEC; // and here the same for CPU-time
120 ctTot = ctPas*maxTS/util::max<int>(curTS, 1);
121 ctRem = ctTot-ctPas;
122
123}

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