kspaceFirstOrder3D-CUDA  1.1
The CUDA/C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 for class with time measurement
10  *
11  * @version kspaceFirstOrder3D 3.4
12  *
13  * @date 15 August 2012, 09:35 (created) \n
14  * 10 August 2016, 10:34 (revised)
15  *
16  * @section License
17  * This file is part of the C++ extension of the k-Wave Toolbox
18  * (http://www.k-wave.org).\n Copyright (C) 2016 Jiri Jaros and Bradley Treeby.
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify
21  * it under the terms of the GNU Lesser General Public License as published by the Free Software
22  * Foundation, either version 3 of the 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
25  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
26  * General Public License for 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/.
30  */
31 
32 
33 #ifndef TIME_MEASURE_H
34 #define TIME_MEASURE_H
35 
36 #ifdef _OPENMP
37  #include <omp.h>
38 #else
39  // Linux build
40  #ifdef __linux__
41  #include <sys/time.h>
42  #endif
43  // Windows build
44  #ifdef _WIN64
45  #include <Windows.h>
46  #include <time.h>
47  #endif
48 #endif
49 
50 /**
51  * @class TTimeMeasure
52  * @brief Class measuring elapsed time.
53  * @brief Class measuring elapsed time, even over multiple leg simulations.
54  */
56 {
57  public:
58 
59  ///Default constructor
61  startTime(0.0),
62  stopTime(0.0),
64  { };
65 
66  /// Destructor.
67  virtual ~TTimeMeasure() {};
68 
69  /**
70  * @brief Copy constructor.
71  * @details Copy constructor.
72  * @param [in] src - The other class to copy from
73  */
74  TTimeMeasure(const TTimeMeasure& src) :
75  startTime(src.startTime),
76  stopTime (src.stopTime),
78  { };
79 
80  /**
81  * @brief operator =
82  * @details operator =
83  * @param [in] src - source
84  * @return
85  */
87  {
88  if (this != &src)
89  {
90  startTime = src.startTime;
91  stopTime = src.stopTime;
93  }
94  return *this;
95  };
96 
97 
98 
99  /// Get start timestamp.
100  inline void Start()
101  {
102  #ifdef _OPENMP
103  startTime = omp_get_wtime();
104  #else
105  // Linux build
106  #ifdef __linux__
107  timeval ActTime;
108  gettimeofday(&ActTime, NULL);
109  startTime = ActTime.tv_sec + ActTime.tv_usec * 1.0e-6;
110  #endif
111  #ifdef _WIN64
112  startTime = clock() / (double) CLOCKS_PER_SEC;
113  #endif
114  #endif
115  };
116 
117  /// Get stop timestamp.
118  inline void Stop()
119  {
120  #ifdef _OPENMP
121  stopTime = omp_get_wtime();
122  #else
123  // Linux build
124  #ifdef __linux__
125  timeval ActTime;
126  gettimeofday(&ActTime, NULL);
127  stopTime = ActTime.tv_sec + ActTime.tv_usec * 1.0e-6;
128  #endif
129  #ifdef _WIN64
130  stopTime = clock() / (double) CLOCKS_PER_SEC;
131  #endif
132  #endif
133  };
134 
135  /**
136  * @brief Get elapsed time.
137  * @details Get elapsed time.
138  * @return elapsed time between start timestamp and stop timestamp.
139  */
140  inline double GetElapsedTime() const
141  {
142  return stopTime - startTime;
143  };
144 
145  /**
146  * @brief Get cumulated elapsed time over all simulation legs.
147  * @details Get cumulated elapsed time over all simulation legs.
148  * @return elapsed time all (including this one) legs.
149  */
151  {
153  };
154 
155  /**
156  * @brief Get time spent in previous legs
157  * @return elapsed time over previous legs.
158  */
160  {
162  };
163 
164  /**
165  * @brief Set elapsed time in previous legs of the simulation.
166  * @details Set elapsed time in previous legs of the simulation.
167  * @param [in] elapsedTime - Elapsed time
168  */
169  void SetCumulatedElapsedTimeOverPreviousLegs(const double elapsedTime)
170  {
172  }
173 
174  private:
175  /// Start timestamp of the interval
176  double startTime;
177  /// Stop timestamp of the interval
178  double stopTime;
179  /// Elapsed time in previous simulation legs
181 
182 };// end of TTimeMeasure
183 //--------------------------------------------------------------------------------------------------
184 
185 #endif /* TIME_MEASURE_H */
TTimeMeasure & operator=(const TTimeMeasure &src)
operator =
Definition: TimeMeasure.h:86
double startTime
Start timestamp of the interval.
Definition: TimeMeasure.h:176
double GetCumulatedElapsedTimeOverPreviousLegs() const
Get time spent in previous legs.
Definition: TimeMeasure.h:159
void SetCumulatedElapsedTimeOverPreviousLegs(const double elapsedTime)
Set elapsed time in previous legs of the simulation.
Definition: TimeMeasure.h:169
TTimeMeasure()
Default constructor.
Definition: TimeMeasure.h:60
void Start()
Get start timestamp.
Definition: TimeMeasure.h:100
Class measuring elapsed time.
Definition: TimeMeasure.h:55
void Stop()
Get stop timestamp.
Definition: TimeMeasure.h:118
double cumulatedElapsedTimeOverPreviousLegs
Elapsed time in previous simulation legs.
Definition: TimeMeasure.h:180
TTimeMeasure(const TTimeMeasure &src)
Copy constructor.
Definition: TimeMeasure.h:74
virtual ~TTimeMeasure()
Destructor.
Definition: TimeMeasure.h:67
double GetElapsedTime() const
Get elapsed time.
Definition: TimeMeasure.h:140
double stopTime
Stop timestamp of the interval.
Definition: TimeMeasure.h:178
double GetCumulatedElapsedTimeOverAllLegs() const
Get cumulated elapsed time over all simulation legs.
Definition: TimeMeasure.h:150