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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::profilingPstream
28
29Description
30 Timers and values for simple (simplistic) mpi-profiling.
31 The entire class behaves as a singleton.
32
33SourceFiles
34 profilingPstream.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_profilingPstream_H
39#define Foam_profilingPstream_H
40
41#include "cpuTime.H"
42#include "FixedList.H"
43#include <memory>
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class profilingPstream Declaration
52\*---------------------------------------------------------------------------*/
55{
56public:
57
58 // Public Types
59
60 //- Enumeration within times array
61 enum timingType
62 {
63 GATHER = 0,
67 WAIT,
69 };
70
71 //- The timing values
73
74
75private:
76
77 // Private Static Data
78
79 //- The timer to use
80 static std::unique_ptr<cpuTime> timer_;
81
82 //- The timing values
83 static timingList times_;
84
85 //- Is timer in a suspend state?
86 static bool suspend_;
87
88
89public:
90
91 // Constructors
92
93 //- Default construct, enables global timer
95
96
97 //- Destructor, disables global timer
99
100
101 // Member Functions
102
103 //- Create timer for measuring communication, or reset existing
104 static void enable();
105
106 //- Remove timer for measuring communication activity
107 static void disable();
108
109 //- Suspend use of timer (if active)
110 inline static void suspend()
111 {
112 suspend_ = bool(timer_);
113 }
114
115 //- Resume use of timer (if previously active)
116 static void resume()
117 {
118 suspend_ = false;
119 }
120
121 //- Timer is active
122 inline static bool active()
123 {
124 return !suspend_ && bool(timer_);
125 }
126
127 //- Access to the timing information
128 inline static timingList& times()
129 {
130 return times_;
131 }
132
133 //- Access to the timing information at given index
134 inline static double times(const enum timingType idx)
135 {
136 return times_[idx];
137 }
138
139 //- Update timer prior to measurement
140 inline static void beginTiming()
141 {
142 if (active())
143 {
144 (void) timer_->cpuTimeIncrement();
145 }
146 }
147
148 //- Add time increment
149 inline static void addTime(const enum timingType idx)
150 {
151 if (active())
152 {
153 times_[idx] += timer_->cpuTimeIncrement();
154 }
155 }
156
157 //- Add time increment to gatherTime
158 inline static void addGatherTime()
159 {
161 }
162
163 //- Add time increment to scatterTime
164 inline static void addScatterTime()
165 {
167 }
168
169 //- Add time increment to broadcastTime
170 inline static void addBroadcastTime()
171 {
173 }
174
175 //- Add time increment to reduceTime
176 inline static void addReduceTime()
177 {
179 }
180
181 //- Add time increment to waitTime
182 inline static void addWaitTime()
183 {
184 addTime(WAIT);
185 }
186
187 //- Add time increment to allToAllTime
188 inline static void addAllToAllTime()
189 {
191 }
192};
193
194
195// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196
197} // End namespace Foam
198
199// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200
201#endif
202
203// ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
Timers and values for simple (simplistic) mpi-profiling. The entire class behaves as a singleton.
static void addReduceTime()
Add time increment to reduceTime.
static void addTime(const enum timingType idx)
Add time increment.
static void addBroadcastTime()
Add time increment to broadcastTime.
static void resume()
Resume use of timer (if previously active)
static void addAllToAllTime()
Add time increment to allToAllTime.
static double times(const enum timingType idx)
Access to the timing information at given index.
static void enable()
Create timer for measuring communication, or reset existing.
static bool active()
Timer is active.
static void addScatterTime()
Add time increment to scatterTime.
~profilingPstream()
Destructor, disables global timer.
static void beginTiming()
Update timer prior to measurement.
static void addWaitTime()
Add time increment to waitTime.
static void addGatherTime()
Add time increment to gatherTime.
static void disable()
Remove timer for measuring communication activity.
FixedList< double, 6 > timingList
The timing values.
static void suspend()
Suspend use of timer (if active)
timingType
Enumeration within times array.
profilingPstream()
Default construct, enables global timer.
static timingList & times()
Access to the timing information.
bool
Definition: EEqn.H:20
Namespace for OpenFOAM.