diff --git a/src/OpenFOAM/global/profiling/profilingPstream.C b/src/OpenFOAM/global/profiling/profilingPstream.C index 96df477a4e..c46348bcc6 100644 --- a/src/OpenFOAM/global/profiling/profilingPstream.C +++ b/src/OpenFOAM/global/profiling/profilingPstream.C @@ -70,7 +70,7 @@ void Foam::profilingPstream::enable() } -void Foam::profilingPstream::disable() +void Foam::profilingPstream::disable() noexcept { timer_.reset(nullptr); suspend_ = false; diff --git a/src/OpenFOAM/global/profiling/profilingPstream.H b/src/OpenFOAM/global/profiling/profilingPstream.H index db953241b4..c088d988e0 100644 --- a/src/OpenFOAM/global/profiling/profilingPstream.H +++ b/src/OpenFOAM/global/profiling/profilingPstream.H @@ -65,11 +65,12 @@ public: BROADCAST, REDUCE, WAIT, - ALL_TO_ALL + ALL_TO_ALL, + OTHER }; //- The timing values - typedef FixedList timingList; + typedef FixedList 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); } }; diff --git a/src/functionObjects/utilities/parProfiling/parProfiling.C b/src/functionObjects/utilities/parProfiling/parProfiling.C index 3ba33caf6e..ab0de02f6b 100644 --- a/src/functionObjects/utilities/parProfiling/parProfiling.C +++ b/src/functionObjects/utilities/parProfiling/parProfiling.C @@ -86,7 +86,7 @@ void Foam::functionObjects::parProfiling::report() // (Time, Processor) for each of: min/max/sum typedef FixedList, 3> statData; - typedef FixedList statDataTimes; + typedef FixedList 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(masterTime, Pstream::myProcNo()); + times[0] = Tuple2(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(allTime, Pstream::myProcNo()); + times[1] = Tuple2(total, Pstream::myProcNo()); + } + + // Other time + { + const double total = + ( + profilingPstream::times(profilingPstream::OTHER) + ); + + times[2] = Tuple2(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; } } diff --git a/src/functionObjects/utilities/parProfiling/parProfiling.H b/src/functionObjects/utilities/parProfiling/parProfiling.H index 873e01af28..0529bc01fb 100644 --- a/src/functionObjects/utilities/parProfiling/parProfiling.H +++ b/src/functionObjects/utilities/parProfiling/parProfiling.H @@ -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();