OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
IpplCounter.cpp
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 * This program was prepared by PSI.
7 * All rights in the program are reserved by PSI.
8 * Neither PSI nor the author(s)
9 * makes any warranty, express or implied, or assumes any liability or
10 * responsibility for the use of this software
11 *
12 * Visit www.amas.web.psi for more details
13 *
14 ***************************************************************************/
15
16// -*- C++ -*-
17/***************************************************************************
18 *
19 * The IPPL Framework
20 *
21 *
22 * Visit http://people.web.psi.ch/adelmann/ for more details
23 *
24 ***************************************************************************/
25
26// include files
27#include "Utility/IpplCounter.h"
28#include "Utility/IpplInfo.h"
29#include "Message/GlobalComm.h"
31
32// forward references for counter routines
33#ifdef SGI_HW_COUNTERS
34extern "C" int start_counters( int e0, int e1);
35extern "C" int read_counters( int e0, long long *c0, int e1, long long *c21);
36#endif
37
38
40// constructor
41IpplCounter::IpplCounter(const char *category)
42 : totalcyc_m(0), totalinst_m(0), c0_m(0), c21_m(0),
43#ifdef SGI_HW_COUNTERS
44 e0_m(0), e1_m(21),
45#endif
46 gen_start_m(0), gen_read_m(0),
47 category_m(category), msg_m("Counter")
48{ }
49
50
52// destructor
54{ }
55
56
58// start a mflops counter going
60{
61#ifdef SGI_HW_COUNTERS
62 gen_start_m = start_counters(e0_m, e1_m);
63#endif
64}
65
66
68// stop a mflops counter, and accumulate results
70{
71#ifdef SGI_HW_COUNTERS
72 gen_read_m = read_counters(e0_m, &c0_m, e1_m, &c21_m);
73#endif
74
75 if(gen_read_m != gen_start_m) {
76 msg_m << "Lost counters! MFLOPS Counters not working." << endl;
77 } else {
80 }
81}
82
83
85// print out mflops
87{
88 double cpu_mhz = 195.0, totalmflops = 0.0, totalsofar = 0.0;
89 double maxmflops = 0.0, minmflops = 0.0;
90 double mflops = 0.0, runMflops = 0.0;
91
92 if (c0_m != 0)
93 mflops = double(c21_m) / double(c0_m) * cpu_mhz;
94
95 if (totalcyc_m != 0)
96 runMflops = double(totalinst_m) / double(totalcyc_m) * cpu_mhz;
97
98 reduce(mflops, totalmflops, OpAddAssign());
99 reduce(mflops, maxmflops, OpMaxAssign());
100 reduce(mflops, minmflops, OpMinAssign());
101 reduce(runMflops, totalsofar, OpAddAssign());
102
103 msg_m << category_m << " MFLOPS -> total = " << totalmflops;
104 msg_m << ", pernode = " << totalmflops/(double)(Ippl::getNodes());
105 msg_m << ", min = " << minmflops << ", max = " << maxmflops;
106 msg_m << ", duration = " << totalsofar << endl;
107}
108
109
110/***************************************************************************
111 * $RCSfile: IpplCounter.cpp,v $ $Author: adelmann $
112 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
113 ***************************************************************************/
114
115/***************************************************************************
116 * $RCSfile: addheaderfooter,v $ $Author: adelmann $
117 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:17 $
118 * IPPL_VERSION_ID: $Id: addheaderfooter,v 1.1.1.1 2003/01/23 07:40:17 adelmann Exp $
119 ***************************************************************************/
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
Definition: GlobalComm.hpp:55
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
CounterLong totalcyc_m
Definition: IpplCounter.h:54
int gen_start_m
Definition: IpplCounter.h:63
CounterLong totalinst_m
Definition: IpplCounter.h:55
std::string category_m
Definition: IpplCounter.h:66
void stopCounter()
Definition: IpplCounter.cpp:69
IpplCounter(const char *category)
Definition: IpplCounter.cpp:41
CounterLong c21_m
Definition: IpplCounter.h:57
CounterLong c0_m
Definition: IpplCounter.h:56
int gen_read_m
Definition: IpplCounter.h:64
Inform msg_m
Definition: IpplCounter.h:67
void startCounter()
Definition: IpplCounter.cpp:59
void printIt()
Definition: IpplCounter.cpp:86
static int getNodes()
Definition: IpplInfo.cpp:670