OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
IpplStats.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef IPPL_STATS_H
12 #define IPPL_STATS_H
13 
14 /***************************************************************************
15  * IpplStats keeps statistics about a given IPPL job, and can report on
16  * a summary of these statistics when asked.
17  *
18  * To add a new type of statistic, do these steps:
19  * 1. Add a new private variable to accumulate the stats
20  * 2. Add a new public method to call to add values to the stat
21  * 3. In the constructor, initialize the stats object with a name in the
22  * colon-initializer list.
23  * 4. Add commands to the rest of ippl to change the stat as needed.
24  * Example:
25  * #ifndef IPPL_NO_STATS
26  * Ippl::Stats.incMessageSent();
27  * #endif
28  *
29  * This interface is extensible ... you can add new types of statistics
30  * by calling 'addStat(description, initval)' with a string description
31  * of the stat, and the initial value it should have. This will return a
32  * unique integer identifier for that stat. Then, you can modify the stat
33  * by calling incStat(statindex, amount) and decStat(statindex, amount).
34  * At the end, then, this statistic will be printed out just like all the
35  * others.
36  ***************************************************************************/
37 
38 // include files
39 #include "Utility/IpplInfo.h"
40 #include "Utility/Timer.h"
41 
42 #include <vector>
43 
44 class Inform;
45 
46 class IpplStats {
47 
48 public:
49  // constructor: initialize statistics, and start run timer
50  IpplStats();
51 
52  // destructor
53  ~IpplStats();
54 
55  // print out the statistics to the given Inform object
56  void print(Inform &);
57 
58  // add a statistics object to our list of stats ... return an integer
59  // which is the index of the stat in our list, which can be used with
60  // the 'incStat' and 'decStat' methods to change that statistic
61  int addStat(const char *description, long initval = 0) {
62  StatList.push_back(new StatData(description, initval, true));
63  return (StatList.size() - 1);
64  }
65 
66  // increment or decrement the statistic by the given value. Return the
67  // current value
68  long incStat(int statindx, long val = 1) {
69  StatList[statindx]->Value += val;
70  return StatList[statindx]->Value;
71  }
72  long decStat(int statindx, long val = 1) {
73  StatList[statindx]->Value -= val;
74  return StatList[statindx]->Value;
75  }
76 
77  //
78  // general IPPL operation information
79  //
80 
81  // return a ref to the timer, so that it can be turned on and off
82  Timer &getTime() { return Time; }
83 
84  //
85  // communication statistics operations
86  //
87 
96  void incMessageBytesSent(long bytes) { BytesSent.Value += bytes; }
97  void incMessageBytesReceived(long bytes) { BytesReceived.Value += bytes; }
98  void incBarriers() { ++Barriers.Value; }
100  void incScatters() { ++Scatters.Value; }
101 
102  //
103  // BareField statistics operations
104  //
105 
107  void incLFields() { ++LFields.Value; }
108  void incLFieldBytes(long bytes) { LFieldBytes.Value += bytes; }
111  void incExpressions() { ++Expressions.Value; }
118  void incFFTs() { ++FFTs.Value; }
129  //
130  // Particle statistics operations
131  //
132 
139  void incParticlesCreated(long num) { ParticlesCreated.Value += num; }
140  void incParticlesDestroyed(long num) { ParticlesDestroyed.Value += num; }
141  void incParticlesSwapped(long num) { ParticlesSwapped.Value += num; }
142 
143 private:
144  // a simple object used to accumulate a stat, with a name.
145  struct StatData {
146  // constructor
147  StatData(std::vector<StatData *> &datalist, const char *nm, long initval = 0,
148  bool needDelete = false)
149  : Value(initval), Name(nm), NeedDelete(needDelete) {
150  // add ourselves to the list of statistics objects
151  datalist.push_back(this);
152  }
153 
154  // another constructor, without the vector
155  StatData(const char *nm, long initval = 0, bool needDelete = false)
156  : Value(initval), Name(nm), NeedDelete(needDelete) { }
157 
158  // default constructor
159  StatData() : Value(0), Name("") { }
160 
161  // destructor
162  ~StatData() { }
163 
164  // value and name
165  long Value;
166  std::string Name;
167 
168  // if this is true, we need to be deleted by the Stats class
170  };
171 
172  // a vector of statistics data objects, which will be used to print
173  // out the results at the end. All stats should be declared as StatData
174  // variables below; in their constructor, they will put themselves in the
175  // list of statistics objects.
176  std::vector<StatData *> StatList;
177 
178  // a timer to time the whole program (although other timers may certainly be
179  // created throughout the program)
181 
182  // build-in ippl statistics objects
196 
220 
230 
231 };
232 
233 // simple macros used to increment a stat, which is turned on or off
234 // by the IPPL_NO_STATS flag
235 #ifndef IPPL_NO_STATS
236 # define INCIPPLSTAT(stat) Ippl::Stats->stat()
237 # define ADDIPPLSTAT(stat,amount) Ippl::Stats->stat(amount)
238 #else
239 # define INCIPPLSTAT(stat)
240 # define ADDIPPLSTAT(stat,amount)
241 #endif
242 
243 #endif
244 
245 /***************************************************************************
246  * $RCSfile: IpplStats.h,v $ $Author: adelmann $
247  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
248  * IPPL_VERSION_ID: $Id: IpplStats.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
249  ***************************************************************************/
250 
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:51
Definition: Value.h:24
Definition: Inform.h:42
void incMessageBytesSent(long bytes)
Definition: IpplStats.h:96
void incScatters()
Definition: IpplStats.h:100
int addStat(const char *description, long initval=0)
Definition: IpplStats.h:61
void incParensEqualsExpression()
Definition: IpplStats.h:114
StatData BytesSent
Definition: IpplStats.h:191
StatData BytesReceived
Definition: IpplStats.h:192
StatData LFields
Definition: IpplStats.h:198
StatData FieldLayouts
Definition: IpplStats.h:200
Timer & getTime()
Definition: IpplStats.h:82
void incMessageReceiveChecks()
Definition: IpplStats.h:94
void incCompresses()
Definition: IpplStats.h:121
StatData BFEqualsBF
Definition: IpplStats.h:206
StatData Compresses
Definition: IpplStats.h:212
StatData Barriers
Definition: IpplStats.h:193
StatData MessagesSent
Definition: IpplStats.h:183
StatData ParensEqualsExpression
Definition: IpplStats.h:205
void incIBFEqualsIBF()
Definition: IpplStats.h:116
void incLFields()
Definition: IpplStats.h:107
StatData MessageReceiveChecksFailed
Definition: IpplStats.h:190
StatData BareFieldIterators
Definition: IpplStats.h:216
StatData BoundaryConditions
Definition: IpplStats.h:211
void incIpplParticleBases()
Definition: IpplStats.h:134
StatData Repartitions
Definition: IpplStats.h:201
void incBareFieldIterators()
Definition: IpplStats.h:125
void incParticlesDestroyed(long num)
Definition: IpplStats.h:140
long decStat(int statindx, long val=1)
Definition: IpplStats.h:72
void incSubEqualsExpression()
Definition: IpplStats.h:117
void incParticleGathers()
Definition: IpplStats.h:137
StatData MessageReceiveChecks
Definition: IpplStats.h:189
void incDecompresses()
Definition: IpplStats.h:122
StatData EndScalarCodes
Definition: IpplStats.h:219
void incLFieldBytes(long bytes)
Definition: IpplStats.h:108
void incDefaultBareFieldIterators()
Definition: IpplStats.h:126
StatData ParticlesSwapped
Definition: IpplStats.h:229
void incMessageSent()
Definition: IpplStats.h:88
void incParticleScatters()
Definition: IpplStats.h:138
StatData ParticleAttribs
Definition: IpplStats.h:221
StatData BeginScalarCodes
Definition: IpplStats.h:218
void incBFEqualsBF()
Definition: IpplStats.h:115
StatData ParticleScatters
Definition: IpplStats.h:226
StatData DefaultBareFieldIterators
Definition: IpplStats.h:217
void incParticleExpressions()
Definition: IpplStats.h:136
void incReductions()
Definition: IpplStats.h:99
StatData CompressionCompares
Definition: IpplStats.h:214
std::vector< StatData * > StatList
Definition: IpplStats.h:176
StatData Expressions
Definition: IpplStats.h:202
void incIBFEqualsExpression()
Definition: IpplStats.h:113
StatData MessagesReceived
Definition: IpplStats.h:186
void incGuardCellFills()
Definition: IpplStats.h:119
void incParticleAttribs()
Definition: IpplStats.h:133
void incMessageReceived()
Definition: IpplStats.h:91
StatData GuardCellFills
Definition: IpplStats.h:210
void incExpressions()
Definition: IpplStats.h:111
StatData LFieldBytes
Definition: IpplStats.h:199
void incBFEqualsExpression()
Definition: IpplStats.h:112
void print(Inform &)
Definition: IpplStats.cpp:105
StatData BareFields
Definition: IpplStats.h:197
void incBareFields()
Definition: IpplStats.h:106
void incFFTs()
Definition: IpplStats.h:118
void incCompressionCompares(long c)
Definition: IpplStats.h:123
Timer Time
Definition: IpplStats.h:180
void incRepartitions()
Definition: IpplStats.h:110
void incParticlesSwapped(long num)
Definition: IpplStats.h:141
StatData Scatters
Definition: IpplStats.h:195
StatData ParticleUpdates
Definition: IpplStats.h:223
void incBarriers()
Definition: IpplStats.h:98
void incParticleUpdates()
Definition: IpplStats.h:135
StatData MessagesReceivedFromQueue
Definition: IpplStats.h:188
StatData IBFEqualsExpression
Definition: IpplStats.h:204
void incMessageReceivedFromQueue()
Definition: IpplStats.h:93
StatData SubEqualsExpression
Definition: IpplStats.h:208
StatData MessagesSentToOthers
Definition: IpplStats.h:184
void incMessageReceiveChecksFailed()
Definition: IpplStats.h:95
void incMessageSentToOthers()
Definition: IpplStats.h:89
StatData FFTs
Definition: IpplStats.h:209
void incCompressionCompareMax(long c)
Definition: IpplStats.h:124
void incMessageReceivedFromNetwork()
Definition: IpplStats.h:92
void incBoundaryConditions()
Definition: IpplStats.h:120
StatData Reductions
Definition: IpplStats.h:194
StatData BFEqualsExpression
Definition: IpplStats.h:203
StatData ParticleGathers
Definition: IpplStats.h:225
void incMessageBytesReceived(long bytes)
Definition: IpplStats.h:97
StatData ParticleExpressions
Definition: IpplStats.h:224
StatData IBFEqualsIBF
Definition: IpplStats.h:207
void incParticlesCreated(long num)
Definition: IpplStats.h:139
void incBeginScalarCodes()
Definition: IpplStats.h:127
StatData IpplParticleBases
Definition: IpplStats.h:222
StatData Decompresses
Definition: IpplStats.h:213
StatData ParticlesCreated
Definition: IpplStats.h:227
void incFieldLayouts()
Definition: IpplStats.h:109
StatData MessagesSentToSelf
Definition: IpplStats.h:185
StatData ParticlesDestroyed
Definition: IpplStats.h:228
StatData MessagesReceivedFromNetwork
Definition: IpplStats.h:187
long incStat(int statindx, long val=1)
Definition: IpplStats.h:68
void incEndScalarCodes()
Definition: IpplStats.h:128
void incMessageSentToSelf()
Definition: IpplStats.h:90
StatData CompressionCompareMax
Definition: IpplStats.h:215
StatData(const char *nm, long initval=0, bool needDelete=false)
Definition: IpplStats.h:155
StatData(std::vector< StatData * > &datalist, const char *nm, long initval=0, bool needDelete=false)
Definition: IpplStats.h:147
std::string Name
Definition: IpplStats.h:166
Definition: Timer.h:28