profilingPstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::profilingPstream
28 
29 Description
30  Timers and values for simple (simplistic) mpi-profiling.
31  The entire class behaves as a singleton.
32 
33 SourceFiles
34  profilingPstream.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef profilingPstream_H
39 #define profilingPstream_H
40 
41 #include "cpuTime.H"
42 #include "FixedList.H"
43 #include <memory>
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class profilingPstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class profilingPstream
55 {
56 public:
57 
58  // Public Types
59 
60  //- Enumeration within times array
61  enum timingType
62  {
63  GATHER = 0,
68  };
69 
70  //- The timing values
72 
73 
74 private:
75 
76  // Private Static Data
77 
78  //- The timer to use
79  static std::unique_ptr<cpuTime> timer_;
80 
81  //- The timing values
82  static timingList times_;
83 
84  //- Is timer in a suspend state?
85  static bool suspend_;
86 
87 
88 public:
89 
90  // Constructors
91 
92  //- Default construct, enables global timer
94 
95 
96  //- Destructor, disables global timer
98 
99 
100  // Member Functions
101 
102  //- Create timer for measuring communication, or reset existing
103  static void enable();
104 
105  //- Remove timer for measuring communication activity
106  static void disable();
107 
108  //- Suspend use of timer (if active)
109  inline static void suspend()
110  {
111  suspend_ = bool(timer_);
112  }
113 
114  //- Resume use of timer (if previously active)
115  static void resume()
116  {
117  suspend_ = false;
118  }
119 
120  //- Timer is active
121  inline static bool active()
122  {
123  return !suspend_ && bool(timer_);
124  }
125 
126  //- Access to the timing information
127  inline static timingList& times()
128  {
129  return times_;
130  }
131 
132  //- Access to the timing information at given index
133  inline static double times(const enum timingType idx)
134  {
135  return times_[idx];
136  }
137 
138  //- Update timer prior to measurement
139  inline static void beginTiming()
140  {
141  if (active())
142  {
143  (void) timer_->cpuTimeIncrement();
144  }
145  }
146 
147  //- Add time increment
148  inline static void addTime(const enum timingType idx)
149  {
150  if (active())
151  {
152  times_[idx] += timer_->cpuTimeIncrement();
153  }
154  }
155 
156  //- Add time increment to gatherTime
157  inline static void addGatherTime()
158  {
159  addTime(GATHER);
160  }
161 
162  //- Add time increment to scatterTime
163  inline static void addScatterTime()
164  {
165  addTime(SCATTER);
166  }
167 
168  //- Add time increment to reduceTime
169  inline static void addReduceTime()
170  {
171  addTime(REDUCE);
172  }
173 
174  //- Add time increment to waitTime
175  inline static void addWaitTime()
176  {
177  addTime(WAIT);
178  }
179 
180  //- Add time increment to allToAllTime
181  inline static void addAllToAllTime()
182  {
184  }
185 };
186 
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 } // End namespace Foam
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 #endif
195 
196 // ************************************************************************* //
Foam::profilingPstream::addWaitTime
static void addWaitTime()
Add time increment to waitTime.
Definition: profilingPstream.H:174
Foam::profilingPstream::suspend
static void suspend()
Suspend use of timer (if active)
Definition: profilingPstream.H:108
Foam::profilingPstream::beginTiming
static void beginTiming()
Update timer prior to measurement.
Definition: profilingPstream.H:138
Foam::profilingPstream::times
static double times(const enum timingType idx)
Access to the timing information at given index.
Definition: profilingPstream.H:132
Foam::profilingPstream
Timers and values for simple (simplistic) mpi-profiling. The entire class behaves as a singleton.
Definition: profilingPstream.H:53
Foam::profilingPstream::REDUCE
Definition: profilingPstream.H:64
Foam::profilingPstream::addScatterTime
static void addScatterTime()
Add time increment to scatterTime.
Definition: profilingPstream.H:162
Foam::profilingPstream::active
static bool active()
Timer is active.
Definition: profilingPstream.H:120
Foam::profilingPstream::timingList
FixedList< double, 5 > timingList
The timing values.
Definition: profilingPstream.H:70
Foam::profilingPstream::addGatherTime
static void addGatherTime()
Add time increment to gatherTime.
Definition: profilingPstream.H:156
Foam::profilingPstream::timingType
timingType
Enumeration within times array.
Definition: profilingPstream.H:60
Foam::profilingPstream::GATHER
Definition: profilingPstream.H:62
Foam::profilingPstream::resume
static void resume()
Resume use of timer (if previously active)
Definition: profilingPstream.H:114
Foam::profilingPstream::times
static timingList & times()
Access to the timing information.
Definition: profilingPstream.H:126
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::profilingPstream::~profilingPstream
~profilingPstream()
Destructor, disables global timer.
Definition: profilingPstream.C:49
Foam::profilingPstream::addAllToAllTime
static void addAllToAllTime()
Add time increment to allToAllTime.
Definition: profilingPstream.H:180
Foam::profilingPstream::disable
static void disable()
Remove timer for measuring communication activity.
Definition: profilingPstream.C:73
Foam::profilingPstream::addTime
static void addTime(const enum timingType idx)
Add time increment.
Definition: profilingPstream.H:147
Foam::profilingPstream::SCATTER
Definition: profilingPstream.H:63
Foam::profilingPstream::addReduceTime
static void addReduceTime()
Add time increment to reduceTime.
Definition: profilingPstream.H:168
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::profilingPstream::ALL_TO_ALL
Definition: profilingPstream.H:66
bool
bool
Definition: EEqn.H:20
FixedList.H
Foam::profilingPstream::WAIT
Definition: profilingPstream.H:65
Foam::profilingPstream::enable
static void enable()
Create timer for measuring communication, or reset existing.
Definition: profilingPstream.C:57
Foam::profilingPstream::profilingPstream
profilingPstream()
Default construct, enables global timer.
Definition: profilingPstream.C:41