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

Timer.H

Go to the documentation of this file.
00001 /*   _______              __
00002     / ___/ /  ___  __ _  / /  ___
00003    / /__/ _ \/ _ \/  V \/ _ \/ _ \
00004    \___/_//_/\___/_/_/_/_.__/\___/
00005 */
00006 // CHOMBO Copyright (c) 2000-2004, The Regents of the University of
00007 // California, through Lawrence Berkeley National Laboratory (subject to
00008 // receipt of any required approvals from U.S. Dept. of Energy).  All
00009 // rights reserved.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are met:
00013 //
00014 // (1) Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 // (2) Redistributions in binary form must reproduce the above copyright
00017 // notice, this list of conditions and the following disclaimer in the
00018 // documentation and/or other materials provided with the distribution.
00019 // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S.
00020 // Dept. of Energy nor the names of its contributors may be used to endorse
00021 // or promote products derived from this software without specific prior
00022 // written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035 //
00036 // You are under no obligation whatsoever to provide any bug fixes,
00037 // patches, or upgrades to the features, functionality or performance of
00038 // the source code ("Enhancements") to anyone; however, if you choose to
00039 // make your Enhancements available either publicly, or directly to
00040 // Lawrence Berkeley National Laboratory, without imposing a separate
00041 // written license agreement for such Enhancements, then you hereby grant
00042 // the following license: a non-exclusive, royalty-free perpetual license
00043 // to install, use, modify, prepare derivative works, incorporate into
00044 // other computer software, distribute, and sublicense such Enhancements or
00045 // derivative works thereof, in binary and source code form.
00046 //
00047 // TRADEMARKS. Product and company names mentioned herein may be the
00048 // trademarks of their respective owners.  Any rights not expressly granted
00049 // herein are reserved.
00050 //
00051 
00052 // Timer.H
00053 #ifndef _TIMER_H_
00054 #define _TIMER_H_
00055 
00056 //#define CATFISH  // to compile stand-alone Timer tester
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"     // temp holding spot for this temp hack
00070 #include "parstream.H"   // for pout()'s
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 // if TIMER is not defined, then we just have a stub class.
00081 #ifdef TIMER
00082 
00083 extern "C" {
00084   // these are for gettimeofday() wall-clock timing
00085 #include <unistd.h>
00086 #include <sys/time.h>
00087 
00088   // obviously, if you don't have PAPI installed on your system
00089   // (which requires kernel modification) then the counters wont
00090   // work, so don't compile with -DPAPI
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();                                  // unmanaged
00109   Timer(const string&, const int);          // root parent-only
00110   Timer(const string&, Timer&, const int);  // parent/child
00111   Timer(const string&, Timer&);             // child only
00112   Timer(const string&, Timer&, const int, bool);  // diagnostic
00113 
00114   //void define(const string&, Timer&, const int, bool);
00115 
00116   //Timer(const string&, const int);  // counter
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; // must be initialized somewhere
00147 
00148   static void TimerSummary(const int bert, const int ernie) {
00149     TimerSummary(); // backwards compatibilty...
00150   }
00151 
00152   static void TimerInit(const int rank);
00153   static void TimerSummary(void);
00154 
00155 private:
00156 
00157   // internally called...
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   //bool timer_on;    // State of timer, either on(true) or off(false)
00163   int m_tableID;  // the table ID -- where parent goes in the summary
00164 
00165   double m_accumulated_WCtime, m_last_WCtime_stamp;
00166 
00167   // wall-clock timer data
00168 #ifndef CH_MPI
00169   struct timeval tv;   //  Values from call to gettimeofday
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 // stub Timer class
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(); // backwards compatibilty...
00253   }
00254 
00255   static void TimerInit(const int rank){}
00256   static void TimerSummary(void){}
00257 
00258 private:
00259 
00260   // internally called...
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

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