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 -------------------------------------------------------------------------------
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 Foam_profilingPstream_H
39 #define Foam_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
62  {
63  GATHER = 0,
67  WAIT,
68  ALL_TO_ALL,
69  OTHER
70  };
71 
72  //- The timing values
74 
75 
76 private:
77 
78  // Private Static Data
79 
80  //- The timer to use
81  static std::unique_ptr<cpuTime> timer_;
82 
83  //- The timing values
84  static timingList times_;
85 
86  //- Is timer in a suspend state?
87  static bool suspend_;
88 
89 
90 public:
91 
92  // Constructors
93 
94  //- Default construct, enables global timer
96 
97 
98  //- Destructor, disables global timer
100 
101 
102  // Member Functions
103 
104  //- Create timer for measuring communication, or reset existing
105  static void enable();
106 
107  //- Remove timer for measuring communication activity
108  static void disable() noexcept;
109 
110  //- Suspend use of timer (if active)
111  static void suspend() noexcept
112  {
113  suspend_ = bool(timer_);
114  }
115 
116  //- Resume use of timer (if previously active)
117  static void resume() noexcept
118  {
119  suspend_ = false;
120  }
121 
122  //- Timer is active (not suspended and enabled)
123  static bool active() noexcept
124  {
125  return !suspend_ && bool(timer_);
126  }
127 
128  //- Access to the timing information
129  static timingList& times() noexcept
130  {
131  return times_;
132  }
133 
134  //- Access to the timing information at given index
135  static double times(const timingType idx)
136  {
137  return times_[idx];
138  }
139 
140  //- Update timer prior to measurement
141  static void beginTiming()
142  {
143  if (active())
144  {
145  (void) timer_->cpuTimeIncrement();
146  }
147  }
148 
149  //- Add time increment
150  static void addTime(const timingType idx)
151  {
152  if (active())
153  {
154  times_[idx] += timer_->cpuTimeIncrement();
155  }
156  }
157 
158  //- Add time increment to \em gather time
159  static void addGatherTime()
160  {
161  addTime(timingType::GATHER);
162  }
163 
164  //- Add time increment to \em scatter time
165  static void addScatterTime()
166  {
167  addTime(timingType::SCATTER);
168  }
169 
170  //- Add time increment to \em broadcast time
171  static void addBroadcastTime()
172  {
173  addTime(timingType::BROADCAST);
174  }
175 
176  //- Add time increment to \em reduce time
177  static void addReduceTime()
178  {
179  addTime(timingType::REDUCE);
180  }
181 
182  //- Add time increment to \em wait time
183  static void addWaitTime()
184  {
185  addTime(timingType::WAIT);
186  }
187 
188  //- Add time increment to \em allToAll time
189  static void addAllToAllTime()
190  {
191  addTime(timingType::ALL_TO_ALL);
192  }
193 
194  //- Add time increment to \em other time
195  static void addOtherTime()
196  {
197  addTime(timingType::OTHER);
198  }
199 };
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #endif
209 
210 // ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:101
profilingPstream()
Default construct, enables global timer.
static void addReduceTime()
Add time increment to reduce time.
static void addWaitTime()
Add time increment to wait time.
~profilingPstream()
Destructor, disables global timer.
Timers and values for simple (simplistic) mpi-profiling. The entire class behaves as a singleton...
static timingList & times() noexcept
Access to the timing information.
static void suspend() noexcept
Suspend use of timer (if active)
timingType
Enumeration within times array.
FixedList< double, 7 > timingList
The timing values.
static void addOtherTime()
Add time increment to other time.
static void addAllToAllTime()
Add time increment to allToAll time.
static void addTime(const timingType idx)
Add time increment.
static void addScatterTime()
Add time increment to scatter time.
const direction noexcept
Definition: Scalar.H:258
static void beginTiming()
Update timer prior to measurement.
static void resume() noexcept
Resume use of timer (if previously active)
static void addBroadcastTime()
Add time increment to broadcast time.
static void disable() noexcept
Remove timer for measuring communication activity.
static bool active() noexcept
Timer is active (not suspended and enabled)
static void addGatherTime()
Add time increment to gather time.
static void enable()
Create timer for measuring communication, or reset existing.
Namespace for OpenFOAM.