00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "Utility/IpplCounter.h"
00028 #include "Utility/IpplInfo.h"
00029 #include "Message/GlobalComm.h"
00030 #include "PETE/IpplExpressions.h"
00031
00032
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
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
00050 IpplCounter::~IpplCounter()
00051 { }
00052
00053
00055
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
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
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
00109
00110
00111
00112
00113
00114
00115
00116
00117