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-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
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
39namespace Foam
40{
41namespace functionObjects
42{
44
46 (
50 );
51
52} // End namespace functionObject
53} // End namespace Foam
54
55
56// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57
59(
60 const word& name,
61 const Time& runTime,
62 const dictionary& dict
63)
64:
66{
68}
69
70
71// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
72
74{
76}
77
78
79// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80
82{
84 {
85 return;
86 }
87
88 // (Time, Processor) for each of: min/max/sum
89 typedef FixedList<Tuple2<double, int>, 3> statData;
90 typedef FixedList<statData, 2> statDataTimes;
91
92 // Reduction: if x and y are unequal assign value.
93 auto statsEqOp = [](statDataTimes& xStats, const statDataTimes& yStats)
94 {
95 forAll(xStats, i)
96 {
97 statData& x = xStats[i];
98 const statData& y = yStats[i];
99
100 // 0: min, 1: max, 2: total (or avg)
101 if (x[0].first() > y[0].first())
102 {
103 x[0] = y[0];
104 }
105 if (x[1].first() < y[1].first())
106 {
107 x[1] = y[1];
108 }
109 x[2].first() += y[2].first();
110 }
111 };
112
113 statDataTimes times;
114
115 {
116 const double masterTime =
117 (
121 // Include broadcast with reduce instead of all-to-all
123 );
124
125 times[0] = Tuple2<double, int>(masterTime, Pstream::myProcNo());
126 }
127
128 {
129 const double allTime =
130 (
133 );
134
135 times[1] = Tuple2<double, int>(allTime, Pstream::myProcNo());
136 }
137
139
140 Pstream::combineGather(times, statsEqOp);
141
143
144
145 if (Pstream::master())
146 {
147 const statData& reduceStats = times[0];
148 const statData& allToAllStats = times[1];
149
150 double reduceAvg = reduceStats[2].first()/Pstream::nProcs();
151 double allToAllAvg = allToAllStats[2].first()/Pstream::nProcs();
152
153 Info<< type() << ':' << nl
154 << incrIndent
155
156 << indent << "reduce : avg = " << reduceAvg << 's' << nl
157 << indent << " min = " << reduceStats[0].first()
158 << "s (processor " << reduceStats[0].second() << ')' << nl
159 << indent << " max = " << reduceStats[1].first()
160 << "s (processor " << reduceStats[1].second() << ')' << nl
161
162 << indent << "all-all : avg = " << allToAllAvg << 's' << nl
163 << indent << " min = " << allToAllStats[0].first()
164 << "s (processor " << allToAllStats[0].second() << ')' << nl
165 << indent << " max = " << allToAllStats[1].first()
166 << "s (processor " << allToAllStats[1].second() << ')'
167 << decrIndent << endl;
168 }
169}
170
171
173{
174 report();
175 return true;
176}
177
178
180{
181 return true;
182}
183
184
186{
188 return true;
189}
190
191
192// ************************************************************************* //
scalar y
Inter-processor communication reduction functions.
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
static void combineGather(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag, const label comm)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
Simple (simplistic) mpi-profiling.
Definition: parProfiling.H:76
virtual ~parProfiling()
Destructor.
Definition: parProfiling.C:73
void report()
Report the current profiling information.
Definition: parProfiling.C:81
virtual bool write()
Do nothing.
Definition: parProfiling.C:179
int myProcNo() const noexcept
Return processor number.
static void resume()
Resume use of timer (if previously active)
static void enable()
Create timer for measuring communication, or reset existing.
static bool active()
Timer is active.
static void disable()
Remove timer for measuring communication activity.
static void suspend()
Suspend use of timer (if active)
static timingList & times()
Access to the timing information.
splitCell * master() const
Definition: splitCell.H:113
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333