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