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