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