00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef _TIMER_H_
00054 #define _TIMER_H_
00055
00056
00057
00058 #ifdef CH_AIX
00059 #define FOUR_COUNTERS
00060 #endif
00061
00062 #include <cstdio>
00063
00064 #ifdef CH_MPI
00065 #include "mpi.h"
00066 #endif
00067
00068 #ifndef CATFISH
00069 #include "Counter.H"
00070 #include "parstream.H"
00071 #endif
00072
00073 #define DTIMESAMR 200
00074 #define DTIMELS 202
00075 #define DTIMEFORT 204
00076 #define DTIMECOMM 206
00077 #define DTIMEDEFINES 210
00078 #define DTIMEALLGSRB 212
00079
00080
00081 #ifdef TIMER
00082
00083 extern "C" {
00084
00085 #include <unistd.h>
00086 #include <sys/time.h>
00087
00088
00089
00090
00091 #ifdef PAPI
00092 #include <papi.h>
00093 #endif
00094 }
00095
00096 #ifndef TIMER_COUNTER
00097 #define TIMER_COUNTER 0
00098 #endif
00099
00100 #include <list>
00101 #include <string>
00102 using namespace std;
00103
00104 class Timer {
00105
00106 public:
00107
00108 Timer();
00109 Timer(const string&, const int);
00110 Timer(const string&, Timer&, const int);
00111 Timer(const string&, Timer&);
00112 Timer(const string&, Timer&, const int, bool);
00113
00114
00115
00116
00117
00118 ~Timer();
00119
00120 void setup();
00121 void start();
00122 void stop();
00123 void clear();
00124
00125 inline double getTimeStampWC();
00126 double wc_time() { return m_accumulated_WCtime; }
00127 double mflops();
00128
00129 #ifdef PAPI
00130 long long int papi_counter0() { return m_accumulated_counter0; }
00131 long long int papi_counter1() { return m_accumulated_counter1; }
00132 double total_papi_counter0() { return m_totalPapiCounter0; }
00133 double total_papi_counter1() { return m_totalPapiCounter1; }
00134 #ifdef FOUR_COUNTERS
00135 long long int papi_counter2() { return m_accumulated_counter2; }
00136 long long int papi_counter3() { return m_accumulated_counter3; }
00137 double total_papi_counter2() { return m_totalPapiCounter2; }
00138 double total_papi_counter3() { return m_totalPapiCounter3; }
00139 #endif
00140 #endif
00141
00142 string Name() { return m_name; }
00143 long long int Count() { return m_count; }
00144 int tableID() { return m_tableID; }
00145
00146 static list<Timer*> *TimerList;
00147
00148 static void TimerSummary(const int bert, const int ernie) {
00149 TimerSummary();
00150 }
00151
00152 static void TimerInit(const int rank);
00153 static void TimerSummary(void);
00154
00155 private:
00156
00157
00158 static void TimerSummary_(void);
00159 static void writeParentTables(FILE *out, const double TimerCost);
00160 static void writeDiagnosticTables(FILE *out, const double TimerCost);
00161
00162
00163 int m_tableID;
00164
00165 double m_accumulated_WCtime, m_last_WCtime_stamp;
00166
00167
00168 #ifndef CH_MPI
00169 struct timeval tv;
00170 struct timezone tz;
00171 #endif
00172
00173 int m_ID;
00174 string m_name;
00175 bool m_diagnostic;
00176 Timer& m_Parent;
00177
00178 bool m_evenCountAcrossRanks;
00179 double m_avgWC, m_minWC, m_maxWC, m_avgCount;
00180
00181 #ifdef PAPI
00182 long long int m_accumulated_counter0;
00183 long long int m_accumulated_counter1;
00184 long long int m_previous_counter0;
00185 long long int m_previous_counter1;
00186 double m_totalPapiCounter0;
00187 double m_totalPapiCounter1;
00188 #ifdef FOUR_COUNTERS
00189 long long int m_values[4];
00190 long long int m_accumulated_counter2;
00191 long long int m_accumulated_counter3;
00192 long long int m_previous_counter2;
00193 long long int m_previous_counter3;
00194 double m_totalPapiCounter2;
00195 double m_totalPapiCounter3;
00196 #else
00197 long long int m_values[2];
00198 #endif
00199
00200 #endif
00201
00202 long long int m_count;
00203 long long int m_totalCount;
00204 };
00205
00206 #else
00207
00208
00209 #include <string>
00210 #include <iostream>
00211 using namespace std;
00212
00213 class Timer {
00214
00215 public:
00216
00217 Timer(){}
00218 Timer(const string&, const int){}
00219 Timer(const string&, Timer&, const int){}
00220 Timer(const string&, Timer&){}
00221 Timer(const string&, Timer&, const int, bool){}
00222
00223 ~Timer(){}
00224
00225 void setup(){}
00226 void start(){}
00227 void stop(){}
00228 void clear(){}
00229
00230 inline double getTimeStampWC(){return 0.0;}
00231 double wc_time() {return 0.0;}
00232 double mflops();
00233
00234 #ifdef PAPI
00235 long long int papi_counter0() {return 0;}
00236 long long int papi_counter1() {return 0;}
00237 double total_papi_counter0() {return 0.0;}
00238 double total_papi_counter1() {return 0.0;}
00239 #ifdef FOUR_COUNTERS
00240 long long int papi_counter2() {return 0;}
00241 long long int papi_counter3() {return 0;}
00242 double total_papi_counter2() {return 0.0;}
00243 double total_papi_counter3() {return 0.0;}
00244 #endif
00245 #endif
00246
00247 string Name() { return NULL; }
00248 long long int Count() { return 0; }
00249 int tableID() { return 0; }
00250
00251 static void TimerSummary(const int bert, const int ernie) {
00252 TimerSummary();
00253 }
00254
00255 static void TimerInit(const int rank){}
00256 static void TimerSummary(void){}
00257
00258 private:
00259
00260
00261 static void TimerSummary_(void){}
00262 static void writeParentTables(FILE *out, const double TimerCost){}
00263 static void writeDiagnosticTables(FILE *out, const double TimerCost){}
00264 };
00265
00266 #endif // TIMER
00267
00268 #endif // TIMER_H