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 #ifndef _TIMER_H_
00053 #define _TIMER_H_
00054 
00055 //#define CATFISH  // to compile stand-alone Timer tester
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 //#include "Counter.H"     // temp holding spot for this temp hack
00069 #include "parstream.H"   // for pout()'s
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 // if TIMER is not defined, then we just have a stub class.
00080 #ifdef TIMER
00081 
00082 extern "C" {
00083   // these are for gettimeofday() wall-clock timing
00084 #include <unistd.h>
00085 #include <sys/time.h>
00086 
00087   // obviously, if you don't have PAPI installed on your system
00088   // (which requires kernel modification) then the counters wont
00089   // work, so don't compile with -DPAPI
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();                                  // unmanaged
00108   Timer(const string&, const int);          // root parent-only
00109   Timer(const string&, Timer&, const int);  // parent/child
00110   Timer(const string&, Timer&);             // child only
00111   Timer(const string&, Timer&, const int, bool);  // diagnostic
00112 
00113   //Timer(const string&, const int);  // counter
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; // must be initialized somewhere
00143 
00144   static void TimerSummary(const int bert, const int ernie) {
00145     TimerSummary(); // backwards compatibilty...
00146   }
00147 
00148   static void TimerInit(const int rank);
00149   static void TimerSummary(void);
00150 
00151 private:
00152 
00153   // internally called...
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   //bool timer_on;    // State of timer, either on(true) or off(false)
00159   int m_tableID;  // the table ID -- where parent goes in the summary
00160 
00161   double m_accumulated_WCtime, m_last_WCtime_stamp;
00162 
00163   // wall-clock timer data
00164 #ifndef CH_MPI
00165   struct timeval tv;   //  Values from call to gettimeofday
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 // stub Timer class
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(); // backwards compatibilty...
00247   }
00248 
00249   static void TimerInit(const int rank){}
00250   static void TimerSummary(void){}
00251 
00252 private:
00253 
00254   // internally called...
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

Generated on Wed Oct 5 12:08:15 2005 for Chombo&AMRIdealMHD by  doxygen 1.4.1