Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Timer.H

Go to the documentation of this file.
00001 // Timer.H
00002 #ifndef TIMER_H
00003 #define TIMER_H
00004 
00005 
00006 #ifdef USE_MPI
00007 #define MPI
00008 #endif
00009 
00010 #ifdef MPI
00011 #include "mpi.h"
00012 #endif
00013 
00014 // if TIMER is not defined, then we just have a stub class.
00015 #ifdef TIMER
00016 
00017 extern "C" {
00018   // these are for gettimeofday() wall-clock timing
00019 #include <unistd.h>
00020 #include <sys/time.h>
00021 
00022   // obviously, if you don't have PAPI installed on your system
00023   // (which requires kernel modification) then the counters wont 
00024   // work, so don't compile with -DPAPI
00025 #ifdef PAPI
00026 #include <papi.h>
00027 #endif
00028 
00029 }
00030 
00031 #ifndef TIMER_COUNTER
00032 #define TIMER_COUNTER 0
00033 #endif
00034 
00035 #include <list>
00036 #include <string>
00037 using namespace std;
00038 
00039 #define DIAG_TABLE1 1
00040 #define DIAG_TABLE2 2
00041 #define DIAG_TABLE3 3
00042 #define DIAG_TABLE4 4
00043 
00044 class Timer {
00045 
00046 public:
00047   
00048   Timer();                                  // unmanaged
00049   Timer(const string&);                     // root
00050   Timer(const string&, Timer&);             // managed
00051   Timer(const string&, Timer&, const int);  // diagnostic
00052 
00053   //Timer(const string&, const int);  // counter
00054 
00055   ~Timer();
00056   
00057   void setup();
00058   void start();
00059   void stop();
00060   void clear();
00061 
00062   inline double getTimeStampWC();
00063   double wc_time() { return accumulated_WCtime; }
00064 
00065 #ifdef PAPI
00066   long long int papi_counter1() { return accumulated_counter1; }
00067   long long int papi_counter2() { return accumulated_counter2; }
00068   double total_papi_counter1() { return totalPapiCounter1; }
00069   double total_papi_counter2() { return totalPapiCounter2; }
00070 #endif
00071 
00072   string Name() { return timer_name;  }
00073   
00074   long long int Count() { return count; }
00075 
00076   static list<Timer*> *TimerList; // must be initialized somewhere
00077 
00078   static void TimerSummary(const int bert, const int ernie) {
00079     TimerSummary(); // backwards compatibilty...
00080   }
00081   
00082   static void TimerSummary(void);
00083   
00084 private:
00085   
00086   // internally called...
00087   static void TimerSummary_(void);
00088 
00089   //bool timer_on;    // State of timer, either on(true) or off(false)
00090   int diagnostic_table;  // the diagnostic table this Timer belongs in
00091 
00092   double accumulated_WCtime, last_WCtime_stamp;
00093 
00094   // wall-clock timer data
00095 #ifndef MPI  
00096   struct timeval tv;   //  Values from call to gettimeofday
00097   struct timezone tz;
00098 #endif
00099 
00100   int ID;  
00101   string timer_name;
00102   Timer& Parent;
00103 
00104   double avgWC, minWC, maxWC, avgCount;
00105 
00106 #ifdef PAPI
00107   long long int values[2];
00108   long long int accumulated_counter1;
00109   long long int accumulated_counter2;
00110   double totalPapiCounter1;
00111   double totalPapiCounter2;
00112 #endif
00113 
00114   long long int count;
00115   long long int totalCount;
00116 
00117 };
00118 
00119 
00120 #else
00121 
00122 
00123 // stub Timer class
00124 #include <string>
00125 #include <iostream>
00126 using namespace std;
00127 
00128 #define DIAG_TABLE1 1
00129 #define DIAG_TABLE2 2
00130 #define DIAG_TABLE3 3
00131 #define DIAG_TABLE4 4
00132 
00133 class Timer {
00134 
00135 public:
00136 
00137   Timer() {}
00138   Timer(const string&) {}
00139   //Timer(const string&, int) {}
00140   Timer(const string&, Timer&) {}
00141   Timer(const string&, Timer&, const int) {}
00142   ~Timer() {}
00143 
00144   inline void setup(){}
00145   inline void start(){}
00146   inline void stop(){}  
00147   inline void clear(){}
00148 
00149   inline double getTimeStampWC() {return 0.0;}
00150   inline double wc_time() {return 0.0;}
00151 
00152 #ifdef PAPI
00153   inline long long int papi_counter1() {return 0;}
00154   inline long long int papi_counter2() {return 0;}
00155 #endif
00156 
00157   inline string Name() {return NULL;}
00158   
00159   inline long int Count() {return 0;}
00160   
00161   static void TimerSummary(const int bert, const int ernie) {
00162     TimerSummary(); // backwards compatibilty...
00163   }
00164 
00165   static void TimerSummary(void) {
00166     int rank;
00167 #ifdef MPI
00168     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00169 #else
00170     rank=0;
00171 #endif
00172     if(rank==0) {
00173       cout << " Timers Disabled.  No timing output written."  << endl;
00174     }
00175   }
00176 
00177 };
00178 
00179 #endif // TIMER
00180 
00181 #endif // TIMER_H

Generated on Wed Jan 19 17:51:27 2005 for Chombo&INSwithParticles by doxygen1.2.16