opm-simulators
timer.hpp
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 
19  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
28 #ifndef OPM_TIMER_HPP
29 #define OPM_TIMER_HPP
30 
31 #include <chrono>
32 
33 namespace Opm {
34 
45 class Timer
46 {
47  struct TimeData
48  {
49  std::chrono::high_resolution_clock::time_point realtimeData;
50  std::clock_t cputimeData;
51 
52  // measure the current time and put it into the object.
53  void measure();
54  };
55 
56 public:
57  Timer();
58 
62  void start();
63 
69  double stop();
70 
74  void halt();
75 
79  void reset();
80 
85  double realTimeElapsed() const;
86 
92  double elapsed() const
93  { return realTimeElapsed(); }
94 
99  double cpuTimeElapsed() const;
100 
106  double globalCpuTimeElapsed() const;
107 
111  Timer& operator+=(const Timer& other);
112 
113 private:
114  bool isStopped_;
115  double cpuTimeElapsed_;
116  double realTimeElapsed_;
117  TimeData startTime_;
118 };
119 
120 } // namespace Opm
121 
122 #endif // OPM_TIMER_HPP
void start()
Start counting the time resources used by the simulation.
Definition: timer.cpp:46
Timer & operator+=(const Timer &other)
Adds the time of another timer to the current one.
Definition: timer.cpp:140
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
void reset()
Make the current point in time t=0 but do not change the status of the timer.
Definition: timer.cpp:82
double realTimeElapsed() const
Return the real time [s] elapsed during the periods the timer was active since the last reset...
Definition: timer.cpp:90
double cpuTimeElapsed() const
Return the CPU time [s] used by all threads of the local process for the periods the timer was active...
Definition: timer.cpp:107
Provides an encapsulation to measure the system time.
Definition: timer.hpp:45
double globalCpuTimeElapsed() const
Return the CPU time [s] used by all threads of the all processes of program.
Definition: timer.cpp:122
double elapsed() const
This is an alias for realTimeElapsed()
Definition: timer.hpp:92
void halt()
Stop the measurement reset all timing values.
Definition: timer.cpp:75
double stop()
Stop counting the time resources.
Definition: timer.cpp:52