35std::unique_ptr<Foam::cpuTime> Foam::profilingPstream::timer_(
nullptr);
37bool Foam::profilingPstream::suspend_(
false);
51 counts_ = uint64_t(0);
59 timer_.reset(
nullptr);
67 counts_ = uint64_t(0);
74 for (
const double val : times_)
102 const label numProc = result.
size();
103 const Type* values = allValues.
cbegin();
104 const label stride = allValues.
size() / numProc;
106 if (!values || !stride)
112 for (label proci = 0; proci < numProc; ++proci, values += stride)
114 result[proci] = values[index];
121template<
class Type,
class Extract>
134 const label numProc = result.size();
135 const Type*
values = allValues.cbegin();
136 const label stride = allValues.size() / numProc;
138 if (!values || !stride)
144 for (label proci = 0; proci < numProc; ++proci, values += stride)
146 result[proci] =
extract(values);
153 const label numProc =
values.size();
159 for (label proci = 0; proci < numProc; ++proci)
161 if (proci)
Info<<
' ';
172 const label numProc =
values.size();
179 auto&
os =
Info.stdStream();
181 Info<<
indent <<
" counts " << numProc <<
'(';
183 for (label proci = 0; proci < numProc; ++proci)
185 if (proci)
os <<
' ';
218 const bool oldSuspend = suspend();
222 const auto& procValues = times_;
226 allTimes.resize(numProc * procValues.size());
241 const auto& procValues = counts_;
245 allCounts.resize(numProc * procValues.size());
273 const label np = data.size();
274 for (label proci = 1; proci < np; ++proci)
279 if (stats[0].first() > tup.first()) stats[0] = tup;
280 if (stats[1].first() < tup.first()) stats[1] = tup;
281 stats[2].first() += tup.first();
285 if (np) { stats[2].first() /= np; }
291 const auto printTimingStats =
292 [&](
Ostream&
os,
const char* tag,
const statData& stats)
294 os <<
indent << tag <<
": avg = " << stats[2].first()
295 <<
", min = " << stats[0].first()
296 <<
" (proc " << stats[0].second() <<
')'
297 <<
", max = " << stats[1].first()
298 <<
" (proc " << stats[1].second() <<
')'
305 Info<<
"profiling(parallel):" <<
nl
314 extractedCounts.resize(numProc);
323 [=](
const double values[])
326 for (
unsigned i = 0; i < timingType::nCategories; ++i)
333 stats = calcStats(extractedTimes);
335 printTimingStats(
Info(),
"total ", stats);
341 const int index = int(timingType::ALL_TO_ALL);
345 stats = calcStats(extractedTimes);
347 printTimingStats(
Info(),
"all-all ", stats);
354 const int index = int(timingType::BROADCAST);
358 stats = calcStats(extractedTimes);
360 printTimingStats(
Info(),
"broadcast ", stats);
367 const int index = int(timingType::PROBE);
371 stats = calcStats(extractedTimes);
373 printTimingStats(
Info(),
"probe ", stats);
386 [=](
const double values[])
390 values[timingType::REDUCE]
391 + values[timingType::GATHER]
392 + values[timingType::SCATTER]
400 [=](
const uint64_t values[])
404 values[timingType::REDUCE]
405 + values[timingType::GATHER]
406 + values[timingType::SCATTER]
410 stats = calcStats(extractedTimes);
412 printTimingStats(
Info(),
"reduce ", stats);
426 [=](
const double values[])
430 values[timingType::RECV]
431 + values[timingType::SEND]
439 [=](
const uint64_t values[])
443 values[timingType::RECV]
444 + values[timingType::SEND]
448 stats = calcStats(extractedTimes);
450 printTimingStats(
Info(),
"send/recv ", stats);
458 const int index = int(timingType::REQUEST);
462 stats = calcStats(extractedTimes);
464 printTimingStats(
Info(),
"request ", stats);
472 const int index = int(timingType::WAIT);
476 stats = calcStats(extractedTimes);
478 printTimingStats(
Info(),
"wait ", stats);
A 1D vector of objects of type <T> with a fixed length <N>.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void resize(const label len)
Adjust allocated size of list.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
const T1 & first() const noexcept
Access the first element.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool empty() const noexcept
True if List is empty (ie, size() is zero).
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
T * data() noexcept
Return pointer to the underlying array serving as data storage.
void size(const label n)
Older name for setAddressableSize.
static label commWorld() noexcept
Communicator for all ranks (respecting any local worlds).
static void mpiGather(const Type *sendData, Type *recvData, int count, const int communicator=UPstream::worldComm)
Receive identically-sized (contiguous) data from all ranks.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
static bool & parRun() noexcept
Test if this a parallel run.
static void disable() noexcept
Remove timer for measuring communication activity. Does not affect times/counts.
FixedList< double, timingType::nCategories > timingList
Fixed-size container for timing values.
static void enable()
Create timer for measuring communication or un-suspend existing.
static void resume() noexcept
Resume use of timer (if previously active).
FixedList< uint64_t, timingType::nCategories > countList
Fixed-size container for timing counts.
static void reset()
Reset times/counts. Does not affect the timer itself.
static void report(const int reportLevel=0)
Report current information. Uses parallel communication!
static bool suspend() noexcept
Suspend use of timer. Return old status.
static double elapsedTime()
The total of times.
OBJstream os(runTime.globalPath()/outputName)
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
static void extractValues(UList< Type > &result, const int index, const UList< Type > &allValues)
static List< T > extract(const word &key, const UPtrList< entry > &entries, const T &initValue)
messageStream Info
Information stream (stdout output on master, null elsewhere).
static void printTimingDetail(const UList< double > &values)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Ostream & indent(Ostream &os)
Indent stream.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
cpuTimePosix cpuTime
Selection of preferred clock mechanism for the elapsed cpu time.
constexpr char nl
The newline '\n' character (0x0a).