ENH: additional 'other' category for profilingPstream

- eg, for user MPI operations that are to be tracked separately
This commit is contained in:
Mark Olesen
2022-12-01 10:58:43 +00:00
parent 8d4e32da22
commit bbd6bfbb7f
4 changed files with 95 additions and 59 deletions

View File

@ -70,7 +70,7 @@ void Foam::profilingPstream::enable()
}
void Foam::profilingPstream::disable()
void Foam::profilingPstream::disable() noexcept
{
timer_.reset(nullptr);
suspend_ = false;

View File

@ -65,11 +65,12 @@ public:
BROADCAST,
REDUCE,
WAIT,
ALL_TO_ALL
ALL_TO_ALL,
OTHER
};
//- The timing values
typedef FixedList<double, 6> timingList;
typedef FixedList<double, 7> timingList;
private:
@ -104,40 +105,40 @@ public:
static void enable();
//- Remove timer for measuring communication activity
static void disable();
static void disable() noexcept;
//- Suspend use of timer (if active)
inline static void suspend()
static void suspend() noexcept
{
suspend_ = bool(timer_);
}
//- Resume use of timer (if previously active)
static void resume()
static void resume() noexcept
{
suspend_ = false;
}
//- Timer is active
inline static bool active()
//- Timer is active (not suspended and enabled)
static bool active() noexcept
{
return !suspend_ && bool(timer_);
}
//- Access to the timing information
inline static timingList& times()
static timingList& times() noexcept
{
return times_;
}
//- Access to the timing information at given index
inline static double times(const enum timingType idx)
static double times(const timingType idx)
{
return times_[idx];
}
//- Update timer prior to measurement
inline static void beginTiming()
static void beginTiming()
{
if (active())
{
@ -146,7 +147,7 @@ public:
}
//- Add time increment
inline static void addTime(const enum timingType idx)
static void addTime(const timingType idx)
{
if (active())
{
@ -154,40 +155,46 @@ public:
}
}
//- Add time increment to gatherTime
inline static void addGatherTime()
//- Add time increment to \em gather time
static void addGatherTime()
{
addTime(GATHER);
addTime(timingType::GATHER);
}
//- Add time increment to scatterTime
inline static void addScatterTime()
//- Add time increment to \em scatter time
static void addScatterTime()
{
addTime(SCATTER);
addTime(timingType::SCATTER);
}
//- Add time increment to broadcastTime
inline static void addBroadcastTime()
//- Add time increment to \em broadcast time
static void addBroadcastTime()
{
addTime(BROADCAST);
addTime(timingType::BROADCAST);
}
//- Add time increment to reduceTime
inline static void addReduceTime()
//- Add time increment to \em reduce time
static void addReduceTime()
{
addTime(REDUCE);
addTime(timingType::REDUCE);
}
//- Add time increment to waitTime
inline static void addWaitTime()
//- Add time increment to \em wait time
static void addWaitTime()
{
addTime(WAIT);
addTime(timingType::WAIT);
}
//- Add time increment to allToAllTime
inline static void addAllToAllTime()
//- Add time increment to \em allToAll time
static void addAllToAllTime()
{
addTime(ALL_TO_ALL);
addTime(timingType::ALL_TO_ALL);
}
//- Add time increment to \em other time
static void addOtherTime()
{
addTime(timingType::OTHER);
}
};

View File

@ -86,7 +86,7 @@ void Foam::functionObjects::parProfiling::report()
// (Time, Processor) for each of: min/max/sum
typedef FixedList<Tuple2<double, int>, 3> statData;
typedef FixedList<statData, 2> statDataTimes;
typedef FixedList<statData, 3> statDataTimes;
// Reduction: if x and y are unequal assign value.
auto statsEqOp = [](statDataTimes& xStats, const statDataTimes& yStats)
@ -111,8 +111,9 @@ void Foam::functionObjects::parProfiling::report()
statDataTimes times;
// Master time
{
const double masterTime =
const double total =
(
profilingPstream::times(profilingPstream::REDUCE)
+ profilingPstream::times(profilingPstream::GATHER)
@ -121,17 +122,29 @@ void Foam::functionObjects::parProfiling::report()
+ profilingPstream::times(profilingPstream::BROADCAST)
);
times[0] = Tuple2<double, int>(masterTime, Pstream::myProcNo());
times[0] = Tuple2<double, int>(total, Pstream::myProcNo());
}
// All time
{
const double allTime =
const double total =
(
profilingPstream::times(profilingPstream::WAIT)
+ profilingPstream::times(profilingPstream::ALL_TO_ALL)
+ profilingPstream::times(profilingPstream::OTHER)
);
times[1] = Tuple2<double, int>(allTime, Pstream::myProcNo());
times[1] = Tuple2<double, int>(total, Pstream::myProcNo());
}
// Other time
{
const double total =
(
profilingPstream::times(profilingPstream::OTHER)
);
times[2] = Tuple2<double, int>(total, Pstream::myProcNo());
}
profilingPstream::suspend();
@ -143,27 +156,43 @@ void Foam::functionObjects::parProfiling::report()
if (Pstream::master())
{
const statData& reduceStats = times[0];
const statData& allToAllStats = times[1];
double reduceAvg = reduceStats[2].first()/Pstream::nProcs();
double allToAllAvg = allToAllStats[2].first()/Pstream::nProcs();
Info<< type() << ':' << nl
<< incrIndent
<< incrIndent;
<< indent << "reduce : avg = " << reduceAvg << 's' << nl
<< indent << " min = " << reduceStats[0].first()
<< "s (processor " << reduceStats[0].second() << ')' << nl
<< indent << " max = " << reduceStats[1].first()
<< "s (processor " << reduceStats[1].second() << ')' << nl
{
const statData& stats = times[0];
double avg = stats[2].first()/Pstream::nProcs();
<< indent << "all-all : avg = " << allToAllAvg << 's' << nl
<< indent << " min = " << allToAllStats[0].first()
<< "s (processor " << allToAllStats[0].second() << ')' << nl
<< indent << " max = " << allToAllStats[1].first()
<< "s (processor " << allToAllStats[1].second() << ')'
<< decrIndent << endl;
Info<< indent << "reduce : avg = " << avg << 's' << nl
<< indent << " min = " << stats[0].first()
<< "s (processor " << stats[0].second() << ')' << nl
<< indent << " max = " << stats[1].first()
<< "s (processor " << stats[1].second() << ')' << nl;
}
{
const statData& stats = times[1];
double avg = stats[2].first()/Pstream::nProcs();
Info<< indent << "all-all : avg = " << avg << 's' << nl
<< indent << " min = " << stats[0].first()
<< "s (processor " << stats[0].second() << ')' << nl
<< indent << " max = " << stats[1].first()
<< "s (processor " << stats[1].second() << ')' << nl;
}
{
const statData& stats = times[2];
double avg = stats[2].first()/Pstream::nProcs();
Info<< indent << "other : avg = " << avg << 's' << nl
<< indent << " min = " << stats[0].first()
<< "s (processor " << stats[0].second() << ')' << nl
<< indent << " max = " << stats[1].first()
<< "s (processor " << stats[1].second() << ')' << nl;
}
Info<< decrIndent;
}
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,8 +51,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_parProfiling_H
#define functionObjects_parProfiling_H
#ifndef Foam_functionObjects_parProfiling_H
#define Foam_functionObjects_parProfiling_H
#include "functionObject.H"
@ -61,7 +61,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class Time;
namespace functionObjects
@ -92,7 +92,7 @@ public:
// Constructors
//- Construct from Time and dictionary
//- Construct from Time and dictionary. Enables profilingPstream
parProfiling
(
const word& name,
@ -101,7 +101,7 @@ public:
);
//- Destructor
//- Destructor. Disables profilingPstream
virtual ~parProfiling();