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

Generated on Thu Aug 29 11:05:46 2002 for Chombo&INS by doxygen1.2.16