Loading...
Searching...
No Matches
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-2023 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{
50/*---------------------------------------------------------------------------*\
51 Class profilingPstream Declaration
52\*---------------------------------------------------------------------------*/
53
55{
56public:
57
58 // Public Types
59
60 //- The enumerated timing categories (for times and counts arrays)
61 enum timingType : unsigned
62 {
67 GATHER, // gather (or recv)
68 SCATTER, // scatter (or send)
70 WAIT,
71 OTHER,
72 nCategories // Dimensioning size
73 };
74
75 //- Fixed-size container for timing values
77
78 //- Fixed-size container for timing counts
81
82private:
83
84 // Private Static Data
85
86 //- The timer to use
87 static std::unique_ptr<cpuTime> timer_;
88
89 //- Is timer in a suspend state?
90 static bool suspend_;
91
92 //- The accumulated values for various timing categories
93 static timingList times_;
94
95 //- The timing frequency for various timing categories
96 static countList counts_;
97
98
99public:
100
101 // Static Member Functions
102
103 // Management
104
105 //- True if timer is active (ie, enabled and not suspended)
106 static bool active() noexcept { return !suspend_ && timer_; }
107
108 //- Create timer for measuring communication or un-suspend existing
109 static void enable();
110
111 //- Remove timer for measuring communication activity.
112 //- Does not affect times/counts.
113 static void disable() noexcept;
114
115 //- Reset times/counts. Does not affect the timer itself
116 static void reset();
118 //- Suspend use of timer. Return old status
119 static bool suspend() noexcept
120 {
121 bool old(suspend_);
122 suspend_ = bool(timer_);
123 return old;
124 }
125
126 //- Resume use of timer (if previously active)
127 static void resume() noexcept
128 {
129 suspend_ = false;
130 }
131
132
133 // Timing/Counts
134
135 //- Access to the timing information
136 static timingList& times() noexcept { return times_; }
137
138 //- Access to the timing counts
139 static countList& counts() noexcept { return counts_; }
140
141 //- Access to the timing information for given timing category
142 static double times(const timingType idx)
143 {
144 return times_[idx];
145 }
146
147 //- Access to the count for given timing category
148 static uint64_t counts(const timingType idx)
149 {
150 return counts_[idx];
151 }
152
153 //- The total of times
154 static double elapsedTime();
155
156 //- Update timer prior to measurement
157 static void beginTiming()
158 {
159 if (!suspend_ && timer_)
160 {
161 timer_->resetCpuTimeIncrement();
162 }
163 }
165 //- Add time increment
166 static void addTime(const timingType idx)
167 {
168 if (!suspend_ && timer_)
170 times_[idx] += timer_->cpuTimeIncrement();
171 ++counts_[idx];
172 }
173 }
174
175 //- Add time increment to \em broadcast time
176 static void addBroadcastTime()
181 //- Add time increment to \em reduce time
182 static void addReduceTime()
183 {
185 }
186
187 //- Add time increment to \em probe time
188 static void addProbeTime()
189 {
191 }
192
193 //- Add time increment to \em request time
194 static void addRequestTime()
195 {
197 }
198
199 //- Add time increment to \em wait time
200 static void addWaitTime()
203 }
204
205 //- Add time increment to \em gather time
206 static void addGatherTime()
207 {
209 }
210
211 //- Add time increment to \em scatter time
212 static void addScatterTime()
215 }
216
217 //- Add time increment to \em allToAll time
218 static void addAllToAllTime()
219 {
222
223 //- Add time increment to \em other time
224 static void addOtherTime()
225 {
227 }
228
230 // Output
231
232 //- Report current information. Uses parallel communication!
233 static void report(const int reportLevel = 0);
234};
235
236
237// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238
239} // End namespace Foam
240
241// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242
243#endif
244
245// ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
Timers and values for simple (simplistic) mpi-profiling. The entire class behaves as a singleton.
static void addReduceTime()
Add time increment to reduce time.
static double times(const timingType idx)
Access to the timing information for given timing category.
static void addBroadcastTime()
Add time increment to broadcast time.
static void disable() noexcept
Remove timer for measuring communication activity. Does not affect times/counts.
static void addAllToAllTime()
Add time increment to allToAll time.
FixedList< double, timingType::nCategories > timingList
Fixed-size container for timing values.
static void addOtherTime()
Add time increment to other time.
static void enable()
Create timer for measuring communication or un-suspend existing.
static void addScatterTime()
Add time increment to scatter time.
static void beginTiming()
Update timer prior to measurement.
static void addWaitTime()
Add time increment to wait time.
static countList & counts() noexcept
Access to the timing counts.
static void addGatherTime()
Add time increment to gather time.
timingType
The enumerated timing categories (for times and counts arrays).
static uint64_t counts(const timingType idx)
Access to the count for given timing category.
static void addRequestTime()
Add time increment to request time.
static void resume() noexcept
Resume use of timer (if previously active).
static bool active() noexcept
True if timer is active (ie, enabled and not suspended).
FixedList< uint64_t, timingType::nCategories > countList
Fixed-size container for timing counts.
static void report(const int reportLevel=0)
Report current information. Uses parallel communication!
static void addTime(const timingType idx)
Add time increment.
static timingList & times() noexcept
Access to the timing information.
static void addProbeTime()
Add time increment to probe time.
static bool suspend() noexcept
Suspend use of timer. Return old status.
static double elapsedTime()
The total of times.
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265