parProfiling.C
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 \*---------------------------------------------------------------------------*/
27 
28 #include "parProfiling.H"
30 #include "UPstream.H"
31 #include "Pstream.H"
32 #include "PstreamReduceOps.H"
33 #include "profilingPstream.H"
34 #include "Tuple2.H"
35 #include "FixedList.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace functionObjects
42 {
43  defineTypeNameAndDebug(parProfiling, 0);
44 
46  (
47  functionObject,
48  parProfiling,
49  dictionary
50  );
51 
52 } // End namespace functionObject
53 
54 
55  // Processor and time for each of: -min -max -sum
57 
58 
59  //- Reduction class. If x and y are not equal assign value.
60  struct statsEqOp
61  {
62  void operator()
63  (
64  FixedList<statData, 2>& xStats,
65  const FixedList<statData, 2>& yStats
66  ) const
67  {
68  forAll(xStats, i)
69  {
70  statData& x = xStats[i];
71  const statData& y = yStats[i];
72 
73  // 0 : min
74  // 1 : max
75  // 2 : sum
76  if (x[0].second() > y[0].second())
77  {
78  x[0].second() = y[0].second();
79  x[0].first() = y[0].first();
80  }
81  if (x[1].second() < y[1].second())
82  {
83  x[1].second() = y[1].second();
84  x[1].first() = y[1].first();
85  }
86  x[2].second() += y[2].second();
87  x[2].first()++;
88  }
89  }
90  };
91 
92 } // End namespace Foam
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
97 Foam::functionObjects::parProfiling::parProfiling
98 (
99  const word& name,
100  const Time& runTime,
101  const dictionary& dict
102 )
103 :
105 {
106  profilingPstream::enable();
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
111 
113 {
115 }
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
121 {
123  {
124  return;
125  }
126 
129 
130  {
131  const scalar masterTime =
132  (
136  );
137 
138  statData& reduceStats = times[0];
139 
140  Tuple2<label, scalar>& minTime = reduceStats[0];
141  minTime.first() = Pstream::myProcNo();
142  minTime.second() = masterTime;
143 
144  Tuple2<label, scalar>& maxTime = reduceStats[1];
145  maxTime.first() = Pstream::myProcNo();
146  maxTime.second() = masterTime;
147 
148  Tuple2<label, scalar>& sumTime = reduceStats[2];
149  sumTime.first() = 1;
150  sumTime.second() = masterTime;
151  }
152 
153  {
154  const scalar allTime =
155  (
158  );
159 
160  statData& allToAllStats = times[1];
161 
162  Tuple2<label, scalar>& minTime = allToAllStats[0];
163  minTime.first() = Pstream::myProcNo();
164  minTime.second() = allTime;
165 
166  Tuple2<label, scalar>& maxTime = allToAllStats[1];
167  maxTime.first() = Pstream::myProcNo();
168  maxTime.second() = allTime;
169 
170  Tuple2<label, scalar>& sumTime = allToAllStats[2];
171  sumTime.first() = 1;
172  sumTime.second() = allTime;
173  }
174 
176 
178 
180 
181 
182  if (Pstream::master())
183  {
184  const statData& reduceStats = times[0];
185  const statData& allToAllStats = times[1];
186 
187  scalar reduceAvg = reduceStats[2].second()/Pstream::nProcs();
188  scalar allToAllAvg = allToAllStats[2].second()/Pstream::nProcs();
189 
190  Info<< type() << ':' << nl
191  << incrIndent
192  << indent << "reduce : avg = " << reduceAvg << 's' << nl
193  << indent << " min = " << reduceStats[0].second()
194  << "s (processor " << reduceStats[0].first() << ')' << nl
195  << indent << " max = " << reduceStats[1].second()
196  << "s (processor " << reduceStats[1].first() << ')' << nl
197  << indent << "all-all : avg = " << allToAllAvg << 's' << nl
198  << indent << " min = " << allToAllStats[0].second()
199  << "s (processor " << allToAllStats[0].first() << ')' << nl
200  << indent << " max = " << allToAllStats[1].second()
201  << "s (processor " << allToAllStats[1].first() << ')'
202  << decrIndent << endl;
203  }
204 }
205 
206 
208 {
209  report();
210  return true;
211 }
212 
213 
215 {
216  return true;
217 }
218 
219 
221 {
223  return true;
224 }
225 
226 
227 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::parProfiling::report
void report()
Report the current profiling information.
Definition: parProfiling.C:120
UPstream.H
Tuple2.H
Foam::profilingPstream::suspend
static void suspend()
Suspend use of timer (if active)
Definition: profilingPstream.H:108
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:458
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::functionObjects::parProfiling::execute
virtual bool execute()
Report.
Definition: parProfiling.C:207
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:327
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:321
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::profilingPstream::REDUCE
Definition: profilingPstream.H:64
Foam::FixedList::first
T & first() noexcept
The first element of the list, position [0].
Definition: FixedListI.H:188
Foam::profilingPstream::active
static bool active()
Timer is active.
Definition: profilingPstream.H:120
Foam::functionObjects::parProfiling::end
virtual bool end()
Report.
Definition: parProfiling.C:220
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::profilingPstream::GATHER
Definition: profilingPstream.H:62
Foam::profilingPstream::resume
static void resume()
Resume use of timer (if previously active)
Definition: profilingPstream.H:114
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::profilingPstream::times
static timingList & times()
Access to the timing information.
Definition: profilingPstream.H:126
Pstream.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:334
Foam::Pstream::combineGather
static void combineGather(const List< commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
Definition: combineGatherScatter.C:48
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:320
PstreamReduceOps.H
Inter-processor communication reduction functions.
Foam::functionObjects::parProfiling::write
virtual bool write()
Do nothing.
Definition: parProfiling.C:214
Foam::profilingPstream::disable
static void disable()
Remove timer for measuring communication activity.
Definition: profilingPstream.C:73
Foam::statsEqOp
Reduction class. If x and y are not equal assign value.
Definition: parProfiling.C:60
parProfiling.H
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:464
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::profilingPstream::SCATTER
Definition: profilingPstream.H:63
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
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
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Tuple2::second
const T2 & second() const noexcept
Return second.
Definition: Tuple2.H:130
Foam::statData
FixedList< Tuple2< label, scalar >, 3 > statData
Definition: parProfiling.C:56
Foam::functionObjects::parProfiling::~parProfiling
virtual ~parProfiling()
Destructor.
Definition: parProfiling.C:112
FixedList.H
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:57
Foam::profilingPstream::WAIT
Definition: profilingPstream.H:65
Foam::Tuple2::first
const T1 & first() const noexcept
Return first.
Definition: Tuple2.H:118
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:446
y
scalar y
Definition: LISASMDCalcMethod1.H:14
profilingPstream.H