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 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. The entire
31  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 "autoPtr.H"
42 #include "cpuTime.H"
43 #include "scalar.H"
44 #include "FixedList.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class profilingPstream Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class profilingPstream
56 {
57  //- Timer to use
58  static autoPtr<cpuTime> timer_;
59 
60  //- Stash for timer during suspend
61  static autoPtr<cpuTime> suspend_;
62 
63  //- The timing values
64  static FixedList<scalar, 5> times_;
65 
66 
67 public:
68 
69  //- Enumeration within times array
70  enum timingType
71  {
72  GATHER = 0,
77  };
78 
79 public:
80 
81  // Constructors
82 
83  //- Construct and enable global timer
85 
86 
87  //- Destructor - remove global timer
89 
90 
91  // Member Functions
92 
93  //- Create timer for measuring communication, or reset existing
94  static void enable();
95 
96  //- Remove timer for measuring communication activity
97  static void disable();
98 
99  //- Suspend use of timer (if active)
100  static void suspend();
101 
102  //- Resume use of timer (if previously active)
103  static void resume();
104 
105  //- Timer is active
106  inline static bool active()
107  {
108  return timer_.valid();
109  }
110 
111  //- Access to the timing information
112  inline static FixedList<scalar, 5>& times()
113  {
114  return times_;
115  }
116 
117  //- Access to the timing information
118  inline static scalar times(const enum timingType idx)
119  {
120  return times_[idx];
121  }
122 
123  //- Update timer prior to measurement
124  inline static void beginTiming()
125  {
126  if (timer_.valid())
127  {
128  (void) timer_->cpuTimeIncrement();
129  }
130  }
131 
132  //- Add time increment
133  inline static void addTime(const enum timingType idx)
134  {
135  if (timer_.valid())
136  {
137  times_[idx] += timer_->cpuTimeIncrement();
138  }
139  }
140 
141  //- Add time increment to gatherTime
142  inline static void addGatherTime()
143  {
144  addTime(GATHER);
145  }
146 
147  //- Add time increment to scatterTime
148  inline static void addScatterTime()
149  {
150  addTime(SCATTER);
151  }
152 
153  //- Add time increment to reduceTime
154  inline static void addReduceTime()
155  {
156  addTime(REDUCE);
157  }
158 
159  //- Add time increment to waitTime
160  inline static void addWaitTime()
161  {
162  addTime(WAIT);
163  }
164 
165  //- Add time increment to allToAllTime
166  inline static void addAllToAllTime()
167  {
169  }
170 };
171 
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 } // End namespace Foam
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 #endif
180 
181 // ************************************************************************* //
Foam::profilingPstream::addWaitTime
static void addWaitTime()
Add time increment to waitTime.
Definition: profilingPstream.H:159
Foam::profilingPstream::beginTiming
static void beginTiming()
Update timer prior to measurement.
Definition: profilingPstream.H:123
Foam::autoPtr::valid
bool valid() const noexcept
True if the managed pointer is non-null.
Definition: autoPtr.H:148
Foam::profilingPstream::suspend
static void suspend()
Suspend use of timer (if active)
Definition: profilingPstream.C:85
Foam::profilingPstream
Timers and values for simple (simplistic) mpi-profiling. The entire class behaves as a singleton.
Definition: profilingPstream.H:54
Foam::profilingPstream::REDUCE
Definition: profilingPstream.H:73
Foam::profilingPstream::addScatterTime
static void addScatterTime()
Add time increment to scatterTime.
Definition: profilingPstream.H:147
Foam::profilingPstream::active
static bool active()
Timer is active.
Definition: profilingPstream.H:105
Foam::profilingPstream::addGatherTime
static void addGatherTime()
Add time increment to gatherTime.
Definition: profilingPstream.H:141
Foam::profilingPstream::times
static scalar times(const enum timingType idx)
Access to the timing information.
Definition: profilingPstream.H:117
Foam::profilingPstream::timingType
timingType
Enumeration within times array.
Definition: profilingPstream.H:69
Foam::profilingPstream::GATHER
Definition: profilingPstream.H:71
Foam::profilingPstream::times
static FixedList< scalar, 5 > & times()
Access to the timing information.
Definition: profilingPstream.H:111
scalar.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::profilingPstream::~profilingPstream
~profilingPstream()
Destructor - remove global timer.
Definition: profilingPstream.C:49
Foam::profilingPstream::addAllToAllTime
static void addAllToAllTime()
Add time increment to allToAllTime.
Definition: profilingPstream.H:165
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::profilingPstream::disable
static void disable()
Remove timer for measuring communication activity.
Definition: profilingPstream.C:78
Foam::profilingPstream::addTime
static void addTime(const enum timingType idx)
Add time increment.
Definition: profilingPstream.H:132
Foam::profilingPstream::SCATTER
Definition: profilingPstream.H:72
Foam::profilingPstream::addReduceTime
static void addReduceTime()
Add time increment to reduceTime.
Definition: profilingPstream.H:153
Foam::FixedList< scalar, 5 >
Foam::profilingPstream::ALL_TO_ALL
Definition: profilingPstream.H:75
FixedList.H
Foam::profilingPstream::WAIT
Definition: profilingPstream.H:74
Foam::profilingPstream::enable
static void enable()
Create timer for measuring communication, or reset existing.
Definition: profilingPstream.C:57
Foam::profilingPstream::profilingPstream
profilingPstream()
Construct and enable global timer.
Definition: profilingPstream.C:41
Foam::profilingPstream::resume
static void resume()
Resume use of timer (if previously active)
Definition: profilingPstream.C:92
autoPtr.H