kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
TimeMeasure.h
Go to the documentation of this file.
1 /**
2  * @file TimeMeasure.h
3  *
4  * @author Jiri Jaros \n
5  * Faculty of Information Technology \n
6  * Brno University of Technology \n
7  * jarosjir@fit.vutbr.cz
8  *
9  * @brief The header file containing the class measuring elapsed time.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 15 August 2012, 09:35 (created) \n
14  * 04 September 2017, 11:16 (revised)
15  *
16  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
17  *
18  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
21  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
22  * License, or (at your option) any later version.
23  *
24  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
26  * more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
29  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
30  * */
31 
32 
33 #ifndef TIME_MEASURE_H
34 #define TIME_MEASURE_H
35 
36 #ifdef _OPENMP
37  #include <omp.h>
38 #else
39  #include <sys/time.h>
40 #endif
41 
42 
43 /**
44  * @class TimeMeasure
45  * @brief Class measuring elapsed time.
46  * @details Class measuring elapsed time, even over multiple simulation legs.
47  */
49 {
50  public :
51 
52  /// Default constructor.
54  mStartTime(0.0),
55  mStopTime(0.0),
57  { };
58 
59  /// Destructor.
60  virtual ~TimeMeasure() {};
61 
62  /**
63  * @brief Copy constructor.
64  * @details Copy constructor.
65  * @param [in] src - The other class to copy from
66  */
67  TimeMeasure(const TimeMeasure& src) :
69  mStopTime (src.mStopTime),
71  { };
72 
73  /**
74  * @brief operator=
75  * @details operator=
76  * @param [in] src - Source.
77  * @return
78  */
80  {
81  if (this != &src)
82  {
83  mStartTime = src.mStartTime;
84  mStopTime = src.mStopTime;
86  }
87  return *this;
88  };
89 
90  ///Take start timestamp.
91  void start()
92  {
93  #ifdef _OPENMP
94  mStartTime = omp_get_wtime();
95  #else
96  timeval actTime;
97  gettimeofday(&actTime, nullptr);
98  mStartTime = actTime.tv_sec + actTime.tv_usec * 1.0e-6;
99  #endif
100  };
101 
102  ///Take stop timestamp.
103  void stop()
104  {
105  #ifdef _OPENMP
106  mStopTime = omp_get_wtime();
107  #else
108  timeval actTime;
109  gettimeofday(&actTime, nullptr);
110  mStopTime = actTime.tv_sec + actTime.tv_usec * 1.0e-6;
111  #endif
112  };
113 
114  /**
115  * @brief Get elapsed time.
116  * @details Get elapsed time.
117  * @return Elapsed time between start timestamp and stop timestamp.
118  */
119  double getElapsedTime() const
120  {
121  return mStopTime - mStartTime;
122  };
123 
124  /**
125  * @brief Get cumulated elapsed time over all simulation legs.
126  * @details Get cumulated elapsed time over all simulation legs.
127  * @return Elapsed time all (including this one) legs.
128  */
130  {
132  };
133 
134  /**
135  * @brief Get time spent in previous legs.
136  * @details Get time spent in previous legs.
137  * @return Elapsed time over previous legs.
138  */
140  {
142  };
143 
144  /**
145  * @brief Set elapsed time in previous legs of the simulation.
146  * @details Set elapsed time in previous legs of the simulation.
147  * @param [in] elapsedTime - Elapsed time.
148  */
149  void SetElapsedTimeOverPreviousLegs(const double elapsedTime)
150  {
151  mElapsedTimeOverPreviousLegs = elapsedTime;
152  }
153 
154  private:
155  /// Start timestamp of the interval
156  double mStartTime;
157  /// Stop timestamp of the interval
158  double mStopTime;
159  /// Elapsed time in previous simulation legs
161 };// end of TimeMesssure
162 //----------------------------------------------------------------------------------------------------------------------
163 
164 #endif /* #ifndef TIME_MEASURE_H */
165 
TimeMeasure & operator=(const TimeMeasure &src)
operator=
Definition: TimeMeasure.h:79
double getElapsedTime() const
Get elapsed time.
Definition: TimeMeasure.h:119
Class measuring elapsed time.
Definition: TimeMeasure.h:48
void SetElapsedTimeOverPreviousLegs(const double elapsedTime)
Set elapsed time in previous legs of the simulation.
Definition: TimeMeasure.h:149
double getElapsedTimeOverPreviousLegs() const
Get time spent in previous legs.
Definition: TimeMeasure.h:139
double mStartTime
Start timestamp of the interval.
Definition: TimeMeasure.h:156
double getElapsedTimeOverAllLegs() const
Get cumulated elapsed time over all simulation legs.
Definition: TimeMeasure.h:129
TimeMeasure()
Default constructor.
Definition: TimeMeasure.h:53
TimeMeasure(const TimeMeasure &src)
Copy constructor.
Definition: TimeMeasure.h:67
void start()
Take start timestamp.
Definition: TimeMeasure.h:91
void stop()
Take stop timestamp.
Definition: TimeMeasure.h:103
double mElapsedTimeOverPreviousLegs
Elapsed time in previous simulation legs.
Definition: TimeMeasure.h:160
double mStopTime
Stop timestamp of the interval.
Definition: TimeMeasure.h:158
virtual ~TimeMeasure()
Destructor.
Definition: TimeMeasure.h:60