src/Utility/IpplCounter.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files
00027 #include "Utility/IpplCounter.h"
00028 #include "Utility/IpplInfo.h"
00029 #include "Message/GlobalComm.h"
00030 #include "PETE/IpplExpressions.h"
00031 
00032 // forward references for counter routines
00033 #ifdef SGI_HW_COUNTERS
00034 extern "C" int start_counters( int e0, int e1);
00035 extern "C" int read_counters( int e0, long long *c0, int e1, long long *c21);
00036 #endif
00037 
00038 
00040 // constructor
00041 IpplCounter::IpplCounter(const char *category)
00042   : category_m(category), msg_m("Counter"),
00043     e0_m(0), e1_m(21), c0_m(0), c21_m(0),
00044     gen_start_m(0), gen_read_m(0), totalcyc_m(0), totalinst_m(0)
00045 { }
00046 
00047 
00049 // destructor
00050 IpplCounter::~IpplCounter()
00051 { }
00052 
00053 
00055 // start a mflops counter going
00056 void IpplCounter::startCounter()
00057 {
00058 #ifdef SGI_HW_COUNTERS
00059   gen_start_m = start_counters(e0_m, e1_m);
00060 #endif
00061 }
00062 
00063 
00065 // stop a mflops counter, and accumulate results
00066 void IpplCounter::stopCounter()
00067 {
00068 #ifdef SGI_HW_COUNTERS
00069   gen_read_m = read_counters(e0_m, &c0_m, e1_m, &c21_m);
00070 #endif
00071 
00072   if(gen_read_m != gen_start_m) {
00073     msg_m << "Lost counters! MFLOPS Counters not working." << endl;
00074   } else {
00075     totalcyc_m += c0_m;
00076     totalinst_m += c21_m;
00077   }
00078 }
00079 
00080 
00082 // print out mflops
00083 void IpplCounter::printIt()
00084 {
00085   double cpu_mhz = 195.0, totalmflops = 0.0, totalsofar = 0.0;
00086   double maxmflops = 0.0, minmflops = 0.0;
00087   double mflops = 0.0, runMflops = 0.0;
00088 
00089   if (c0_m != 0)
00090     mflops = double(c21_m) / double(c0_m) * cpu_mhz;
00091 
00092   if (totalcyc_m != 0)
00093     runMflops = double(totalinst_m) / double(totalcyc_m) * cpu_mhz;
00094 
00095   reduce(mflops, totalmflops, OpAddAssign());
00096   reduce(mflops, maxmflops, OpMaxAssign());
00097   reduce(mflops, minmflops, OpMinAssign());
00098   reduce(runMflops, totalsofar, OpAddAssign());
00099 
00100   msg_m << category_m << " MFLOPS -> total = " << totalmflops;
00101   msg_m << ", pernode = " << totalmflops/(double)(Ippl::getNodes());
00102   msg_m << ", min = " << minmflops << ", max = " << maxmflops;
00103   msg_m << ", duration = " << totalsofar << endl;
00104 }
00105 
00106 
00107 /***************************************************************************
00108  * $RCSfile: IpplCounter.cpp,v $   $Author: adelmann $
00109  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00110  ***************************************************************************/
00111 
00112 /***************************************************************************
00113  * $RCSfile: addheaderfooter,v $   $Author: adelmann $
00114  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:17 $
00115  * IPPL_VERSION_ID: $Id: addheaderfooter,v 1.1.1.1 2003/01/23 07:40:17 adelmann Exp $ 
00116  ***************************************************************************/
00117 

Generated on Mon Jan 16 13:23:59 2006 for IPPL by  doxygen 1.4.6