Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

CH_Timer.H

Go to the documentation of this file.
00001 #ifndef CH_TIMER_H
00002 #define CH_TIMER_H
00003 
00004 #ifdef CH_AIX
00005 #define FOUR_COUNTERS
00006 #endif
00007 
00008 #include <cstdio>
00009 
00010 #ifdef CH_MPI
00011 #include "mpi.h"
00012 #endif
00013 
00014 extern "C" {
00015 // these are for gettimeofday() wall-clock timing
00016 #include <unistd.h>
00017 #include <sys/time.h>
00018 // obviously, if you don't have PAPI installed on your system
00019 // (which requires kernel modification) then the counters wont
00020 // work, so don't compile with -DPAPI
00021 #ifdef PAPI
00022 #include <papi.h>
00023 #endif
00024 }
00025 
00026 #ifndef TIMER_COUNTER
00027 #define TIMER_COUNTER 0
00028 #endif
00029 
00030 #include <list>
00031 #include <string>
00032 using namespace std;
00033 
00034 namespace Chombo {
00035   class Timer {
00036 
00037   public:
00038 
00039     Timer();                                  // unmanaged
00040     Timer(const string&, const int);          // root parent-only
00041     Timer(const string&, Timer&, const int);  // parent/child
00042     Timer(const string&, Timer&);             // child only
00043     Timer(const string&, Timer&, const int, bool);  // diagnostic
00044 
00045     ~Timer();
00046 
00047     void setup();
00048     void start();
00049     void stop();
00050     void clear();
00051 
00052     inline double getTimeStampWC();
00053     double wc_time() { return m_accumulated_WCtime; }
00054 
00055 #ifdef PAPI
00056     long long int papi_counter0() { return m_accumulated_counter0; }
00057     long long int papi_counter1() { return m_accumulated_counter1; }
00058     double total_papi_counter0()  { return m_totalPapiCounter0; }
00059     double total_papi_counter1()  { return m_totalPapiCounter1; }
00060 #ifdef FOUR_COUNTERS
00061     long long int papi_counter2() { return m_accumulated_counter2; }
00062     long long int papi_counter3() { return m_accumulated_counter3; }
00063     double total_papi_counter2()  { return m_totalPapiCounter2; }
00064     double total_papi_counter3()  { return m_totalPapiCounter3; }
00065 #endif
00066 #endif
00067 
00068     string        Name()    { return m_name;     }
00069     long long int Count()   { return m_count;    }
00070     int           tableID() { return m_tableID;  }
00071 
00072     static list<Timer*> *TimerList; // must be initialized somewhere
00073 
00074     static void TimerSummary(const int bert, const int ernie) {
00075       TimerSummary(); // backwards compatibilty...
00076     }
00077 
00078     static void TimerInit(const int rank);
00079     static void TimerSummary(void);
00080 
00081   private:
00082 
00083     // internally called...
00084     static void TimerSummary_(void);
00085     static void writeParentTables(FILE *out, const double TimerCost);
00086     static void writeDiagnosticTables(FILE *out, const double TimerCost);
00087 
00088     //bool timer_on;    // State of timer, either on(true) or off(false)
00089     int m_tableID;  // the table ID -- where parent goes in the summary
00090 
00091     double m_accumulated_WCtime, m_last_WCtime_stamp;
00092 
00093     // wall-clock timer data
00094 #ifndef CH_MPI
00095     struct timeval tv;   //  Values from call to gettimeofday
00096     struct timezone tz;
00097 #endif
00098 
00099     int m_ID;
00100     string m_name;
00101     bool m_diagnostic;
00102     Timer& m_Parent;
00103 
00104     double m_avgWC, m_minWC, m_maxWC, m_avgCount;
00105 
00106 #ifdef PAPI
00107     long long int m_accumulated_counter0;
00108     long long int m_accumulated_counter1;
00109     long long int m_previous_counter0;
00110     long long int m_previous_counter1;
00111     double m_totalPapiCounter0;
00112     double m_totalPapiCounter1;
00113 #ifdef FOUR_COUNTERS
00114     long long int m_values[4];
00115     long long int m_accumulated_counter2;
00116     long long int m_accumulated_counter3;
00117     long long int m_previous_counter2;
00118     long long int m_previous_counter3;
00119     double m_totalPapiCounter2;
00120     double m_totalPapiCounter3;
00121 #else
00122     long long int m_values[2];
00123 #endif
00124 
00125 #endif
00126 
00127     long long int m_count;
00128     long long int m_totalCount;
00129   };
00130 }
00131 
00132 #endif // CH_TIMER_H

Generated on Wed Oct 5 13:52:08 2005 for Chombo&AMRSelfGravity by  doxygen 1.4.1