Chombo + EB  3.2
OldTimer.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _OLDTIMER_H_
12 #define _OLDTIMER_H_
13 
14 #ifndef CH_NTIMER
15 
16 #ifdef CH_AIX
17 #define FOUR_COUNTERS
18 #endif
19 
20 #include <cstdio>
21 #include "REAL.H"
22 #include "MayDay.H"
23 #include "Vector.H"
24 #include "ClockTicks.H"
25 #ifdef CH_MPI
26 #include "mpi.h"
27 #endif
28 
29 extern "C"
30 {
31  // these are for gettimeofday() wall-clock timing
32 #include <unistd.h>
33 #include <sys/time.h>
34 
35  // obviously, if you don't have PAPI installed on your system
36  // (which requires kernel modification) then the counters wont
37  // work, so don't compile with -DPAPI
38 #ifdef PAPI
39 #include <papi.h>
40 #endif
41 }
42 
43 #ifndef TIMER_COUNTER
44 #define TIMER_COUNTER 0
45 #endif
46 
47 #include <list>
48 #include <string>
49 #include "List.H"
50 
51 #include <string>
52 #include <iostream>
53 #include "BaseNamespaceHeader.H"
54 
55 using namespace std;
56 
57  /** A simple class for keeping track of elapsed time.
58 
59  CH_XD::OldTimer provides the ability to measure the passage of wall-clock time
60  within units of code, and relate multiple measurements in a hierarchical
61  manner.
62 
63  A timer can be started, stopped, reset and printed out. Multiple timers
64  can be instantiated and related to each other hierarchically: a timer instance
65  may have a parent and children. The hierarchical relationship is relevant only
66  when printing out the summary report.
67 
68  In parallel, the timers on each proc operate independently. Only the summary
69  operations cause communication between procs.
70  */
71 class OldTimer
72 {
73  public:
74 
75  // Constructors
76 
77  /// Construct an unnamed timer that has no relation to any other instance
78  OldTimer(); // unmanaged
79  /// Construct a named timer and add it to a table.
80  OldTimer(const string& a_name, const int a_tableID); // root parent-only
81  OldTimer(const string& a_name, OldTimer&, const int a_tableID); // parent/child
82  OldTimer(const string& a_name, OldTimer&); // child only
83  OldTimer(const string& a_name, OldTimer&, const int a_tableID, bool); // diagnostic
84 
85  ~OldTimer();
86 
87  void setup();
88  void start();
89  void stop();
90  void stop(Real& wc1);
91  void clear();
92 
93  inline double getTimeStampWC();
94  double wc_time()
95  {
96  return m_accumulated_WCtime;
97  }
98  double mflops();
99  void writeTotalPct(const string& a_extra = "");
100 
101 #ifdef PAPI
102  long long int papi_counter0()
103  {
104  return m_accumulated_counter0;
105  }
106  long long int papi_counter1()
107  {
108  return m_accumulated_counter1;
109  }
110  double total_papi_counter0()
111  {
112  return m_totalPapiCounter0;
113  }
114  double total_papi_counter1()
115  {
116  return m_totalPapiCounter1;
117  }
118 #ifdef FOUR_COUNTERS
119  long long int papi_counter2()
120  {
121  return m_accumulated_counter2;
122  }
123  long long int papi_counter3()
124  {
125  return m_accumulated_counter3;
126  }
127  double total_papi_counter2()
128  {
129  return m_totalPapiCounter2;
130  }
131  double total_papi_counter3()
132  {
133  return m_totalPapiCounter3;
134  }
135 #endif
136 #endif
137 
138  string Name()
139  {
140  return m_name;
141  }
142  long long int Count()
143  {
144  return m_count;
145  }
146  int tableID()
147  {
148  return m_tableID;
149  }
150 
151  static list<OldTimer*> *TimerList; // must be initialized somewhere
152 
153  static void TimerSummary(const int bert, const int ernie)
154  {
155  TimerSummary(); // backwards compatibilty...
156  }
157 
158  static void TimerInit(const int rank);
159  static void TimerSummary(void);
160  static void TimerSummaryWithTITAfiles(void);
161 
162  private:
163 
164  // internally called...
165  static void TimerSummary_(const int itita);
166  static void writeParentTables(FILE *out, const double TimerCost);
167  static void writeDiagnosticTables(FILE *out, const double TimerCost);
168 
169  //bool timer_on; // State of timer, either on(true) or off(false)
170  int m_tableID; // the table ID -- where parent goes in the summary
171 
172  double m_accumulated_WCtime, m_last_WCtime_stamp;
173 
174  // wall-clock timer data
175 #ifndef CH_MPI
176  struct timeval tv; // Values from call to gettimeofday
177  struct timezone tz;
178 #endif
179 
180  int m_ID;
181  string m_name;
184 
186  double m_avgWC, m_minWC, m_maxWC, m_avgCount;
187 
188 #ifdef PAPI
189  long long int m_accumulated_counter0;
190  long long int m_accumulated_counter1;
191  long long int m_previous_counter0;
192  long long int m_previous_counter1;
193  double m_totalPapiCounter0;
194  double m_totalPapiCounter1;
195 #ifdef FOUR_COUNTERS
196  long long int m_values[4];
197  long long int m_accumulated_counter2;
198  long long int m_accumulated_counter3;
199  long long int m_previous_counter2;
200  long long int m_previous_counter3;
201  double m_totalPapiCounter2;
202  double m_totalPapiCounter3;
203 #else
204  long long int m_values[2];
205 #endif
206 #endif
207 
208  long long int m_count;
209  long long int m_totalCount;
210  };
211 
212 /*
213 #else // CH_NTIMER
214 
215 // stub OldTimer class
216 using namespace std;
217 
218 class OldTimer
219 {
220 public:
221 
222  OldTimer()
223  {
224  }
225 
226  OldTimer(const string&, const int)
227  {
228  }
229 
230  OldTimer(const string&, OldTimer&, const int)
231  {
232  }
233 
234  OldTimer(const string&, OldTimer&)
235  {
236  }
237 
238  OldTimer(const string&, OldTimer&, const int, bool)
239  {
240  }
241 
242  ~OldTimer()
243  {
244  }
245 
246  void setup()
247  {
248  }
249  void start()
250  {
251  }
252  void stop()
253  {
254  }
255  void stop(Real& wc1)
256  {
257  }
258  void clear()
259  {
260  }
261 
262  inline double getTimeStampWC()
263  {
264  return 0.0;
265  }
266  double wc_time()
267  {
268  return 0.0;
269  }
270  double mflops();
271  void writeTotalPct(const string& a_extra = "");
272 
273 #ifdef PAPI
274  long long int papi_counter0()
275  {
276  return 0;
277  }
278  long long int papi_counter1()
279  {
280  return 0;
281  }
282  double total_papi_counter0()
283  {
284  return 0.0;
285  }
286  double total_papi_counter1()
287  {
288  return 0.0;
289  }
290 #ifdef FOUR_COUNTERS
291  long long int papi_counter2()
292  {
293  return 0;
294  }
295  long long int papi_counter3()
296  {
297  return 0;
298  }
299  double total_papi_counter2()
300  {
301  return 0.0;
302  }
303  double total_papi_counter3()
304  {
305  return 0.0;
306  }
307 #endif
308 #endif
309 
310  string Name()
311  {
312  return NULL;
313  }
314  long long int Count()
315  {
316  return 0;
317  }
318  int tableID()
319  {
320  return 0;
321  }
322 
323  static void TimerSummary(const int bert, const int ernie)
324  {
325  TimerSummary(); // backwards compatibilty...
326  }
327 
328  static void TimerInit(const int rank)
329  {
330  }
331  static void TimerSummary(void)
332  {
333  }
334  static void TimerSummaryWithTITAfiles(void)
335  {
336  };
337 
338 private:
339 
340  // internally called...
341  static void TimerSummary_(const int itita)
342  {
343  }
344  static void writeParentTables(FILE *out, const double TimerCost)
345  {
346  }
347  static void writeDiagnosticTables(FILE *out, const double TimerCost)
348  {
349  }
350 };
351 
352 */
353 
354 #include "BaseNamespaceFooter.H"
355 #endif // CH_NTIMER
356 
357 #endif // CH_OLDTIMER_H
bool m_evenCountAcrossRanks
Definition: OldTimer.H:185
long long int m_totalCount
Definition: OldTimer.H:209
static list< OldTimer * > * TimerList
Definition: OldTimer.H:151
long long int Count()
Definition: OldTimer.H:142
string Name()
Definition: OldTimer.H:138
int m_tableID
Definition: OldTimer.H:170
Definition: OldTimer.H:71
double m_last_WCtime_stamp
Definition: OldTimer.H:172
OldTimer & m_Parent
Definition: OldTimer.H:183
long long int m_count
Definition: OldTimer.H:208
double Real
Definition: REAL.H:33
string m_name
Definition: OldTimer.H:181
static void TimerSummary(const int bert, const int ernie)
Definition: OldTimer.H:153
double wc_time()
Definition: OldTimer.H:94
int tableID()
Definition: OldTimer.H:146
bool m_diagnostic
Definition: OldTimer.H:182
double m_minWC
Definition: OldTimer.H:186
int m_ID
Definition: OldTimer.H:180