OpenLB 1.7
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2011 Lukas Baron, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef TIMER_H
25#define TIMER_H
26
27#include <sys/time.h>
28#include <iostream>
29#include <iomanip>
30#include <stdio.h>
31#include "io/ostreamManager.h"
32#include "io/xmlReader.h"
33#include "core/unitConverter.h"
34
35namespace olb {
36
37namespace util {
38
39// using namespace olb; //necessary? Problems have occured with singleton::xxx
40
66/* BUGS:
67- cavity2d with 20 seconds yields average MLUPs values much smaller than the ones 'live in computation' (with T=int, due to integer overflow)
68*/
69
71template<typename T>
72class Timer {
73
74private:
75 mutable OstreamManager clout;
76
77 /* INFORMATION about time data types:
78 timeval: Struct with "long tv_usec" and "unsigned long tv_sec".
79 time_t : seconds since 1st january 1970, 00:00:00 (GMT).
80 */
81
82 // parameter for time measurement
83 double cpuTimeStart{}, cpuTimeCur{}, cpuTimeEnd{}; // in cpu-time
84 time_t sTimeStart{}, sTimeCur{}, sTimeEnd{}, *tp{}; // in seconds
85 timeval msTimeStart{}, msTimeCur{}, msTimeEnd{}; // in ms
86 timeval msTimeLast{}; // in ms, for MegaLatticeUpdate-measurements only
87 T deltaTS{}; // time-step difference since last call of update()
88
89 // Input-parameter of the algorithm to compute remaining runtimes and performance (actually constants)
90 std::size_t curTS{}; // current lattice time step
91 std::size_t maxTS{}; // total number of lattice time steps that are intended to be computed
92 std::size_t numFC{}; // number of fluid cells (depending from size and dimension of the domain)
93
94 // parameter-prefixes for output
95 /* prefix-explanation:
96 rt: realtime-values, elapsed time on a wall clock
97 ct: cpu-time values
98 lt: lattice-time values, elapsed time within the simulated system
99 */
100
101 int ltPas{}, ltRem{}, ltTot{}; // lattice time (time steps)
102 double ctPas{}, ctRem{}, ctTot{}; // cpu time
103 T rtPas{}, rtRem{}, rtTot{}; // times in s
104 T rtPasMs{}, rtRemMs{}, rtTotMs{}; // times in ms
105
106 unsigned int _printModeSummary; // select what kind of timer summary to print (0 for default, 1 for short summary)
107
108public:
110 Timer(int maxTimeSteps, std::size_t numFluidCells=1, unsigned int printModeSummary = 0);
111
113
114 T timevalDiffTimeMs(timeval end, timeval start);
115
117 T getMLUPs();
118
120 T getMLUPps();
121
123 T getTotalMLUPs();
124
126 T getTotalMLUPps();
127
129 void start();
130
132
133 void update(int currentTimeStep);
134
136
137 void stop();
138
140 double getTotalCpuTime();
141
144
147
149
153 void printStep(int printMode=0);
154 void printStep(OstreamManager& fout, int printMode=0);
155
157
162 void print(std::size_t currentTimeStep, int printMode=0);
163
165 void printSummary();
166 void printSummary(OstreamManager& fout);
168 void printShortSummary();
170};
171
172// Factory function /////////////////////////////////
173template<typename T, typename DESCRIPTOR>
174// Timer<T>* createTimer(XMLreader& param);
175Timer<T>* createTimer(XMLreader& param, const UnitConverter<T,DESCRIPTOR>& converter, size_t numLatticePoints);
177
178} // namespace util
179
180} // namespace olb
181
182#endif
class for marking output with some text
Conversion between physical and lattice units, as well as discretization.
How to use in Code:
Definition timer.h:72
Timer(int maxTimeSteps, std::size_t numFluidCells=1, unsigned int printModeSummary=0)
initializes timer with the given values, abbreviation to Timer() + initialize(int,...
Definition timer.hh:36
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 printShortSummary()
Prints a short summary containing only time consumptions (real and cpu time)
Definition timer.hh:244
T getMLUPs()
returns Million DESCRIPTOR Site Updates per second (all processes together)
Definition timer.hh:55
T getTotalRealTime()
Returns the total measured time between start() and stop() in seconds.
Definition timer.hh:140
void update(int currentTimeStep)
Updates all time values of interest during computation.
Definition timer.hh:99
void print(std::size_t currentTimeStep, int printMode=0)
Performs an update() followed by a printStep().
Definition timer.hh:152
T getTotalMLUPps()
returns average Million DESCRIPTOR Site Updates per second and process between start() and stop()
Definition timer.hh:79
T getTotalMLUPs()
returns average Million DESCRIPTOR Site Updates per second between start() and stop()
Definition timer.hh:72
double getTotalCpuTime()
Returns the total cpu time in seconds between start() and stop().
Definition timer.hh:134
T getMLUPps()
returns Million DESCRIPTOR Site Updates per second and process
Definition timer.hh:62
T getTotalRealTimeMs()
Returns the total measured time between start() and stop() in ms.
Definition timer.hh:146
void start()
(Re-)sets start value for time measurement.
Definition timer.hh:90
T timevalDiffTimeMs(timeval end, timeval start)
returns the time difference between two timeval objects in ms
Definition timer.hh:47
void stop()
Terminates time measurement and sets end value.
Definition timer.hh:126
void printSummary()
Prints a (short) summary containing the overall time consumption in real and in cpu time for use afte...
Definition timer.hh:224
Timer< T > * createTimer(XMLreader &param, const UnitConverter< T, DESCRIPTOR > &converter, size_t numLatticePoints)
Definition timer.hh:260
Top level namespace for all of OpenLB.
Unit conversion handling – header file.
Input/Output in XML format – header file.