28 if(
approx(
a.getDeltaCpuTime(),
b.getDeltaCpuTime(), MFloatEps))
return (
a.getInitCpuTime() <
b.getInitCpuTime());
29 return (
a.getDeltaCpuTime() <
b.getDeltaCpuTime());
34 if(omp_get_max_threads() > 1) {
35 m_log <<
"Skipping profile output for OpenMP. FIXME: Tracer not thread-safe!" << std::endl;
42 const MFloat thresholdPercentage = 0.5;
44 sstream <<
" CPU WALL FUNCTION >> profile: '" <<
m_name <<
"' <<";
45 const string header = sstream.str();
46 const MString dashes1(header.size(),
'_');
47 const MString dashes2(header.size(),
'-');
48 m_log << dashes1 << endl << header << endl << dashes2 << endl << endl;
62 if(relCpuTime < thresholdPercentage) {
67 sprintf(buffer,
"%6.2f", relCpuTime);
69 sprintf(buffer2,
"%6.2f", relWallTime);
75 m_log <<
" ..... ..... (" << supCounter <<
" shorter timings with CPU<" << thresholdPercentage
76 <<
"% were suppressed)" << endl;
80 m_log <<
"No timings recorded for timer '" <<
m_name <<
"'." << endl;
82 m_log << dashes2 << endl;
85 m_log << dashes1 << endl;
102 ASSERT(tId > -1,
"Non-existing timer");
111 const MFloat div = floor(rem / 86400.0);
112 time << ((
MInt)div) <<
" days, ";
113 rem -= div * 86400.0;
116 const MFloat div = floor(rem / 3600.0);
117 time << ((
MInt)div) <<
" hours, ";
121 const MFloat div = floor(rem / 60.0);
122 time << ((
MInt)div) <<
" mins, ";
125 time << rem <<
" secs";
126 const MString ret = time.str();
136 m_deltaWallTime(0.0),
172 const MInt domainId,
const MInt noDomains) {
175 std::vector<std::pair<MFloat, MString>> durations{};
176 durations.push_back(std::make_pair(duration, comment));
177 logDurations(durations, module, comm, domainId, noDomains);
182void logDurations(std::vector<std::pair<MFloat, MString>>& durations,
const MString module,
const MPI_Comm comm,
183 const MInt domainId,
const MInt noDomains) {
184 const MInt noDurations = durations.size();
186 std::vector<MFloat> maxDurations(noDurations);
187 for(
MInt i = 0; i < noDurations; i++) {
188 maxDurations[i] = durations[i].first;
191 std::vector<MFloat> minDurations = maxDurations;
192 std::vector<MFloat> sumDurations = maxDurations;
196 "MPI_IN_PLACE",
"maxDurations");
198 "MPI_IN_PLACE",
"minDurations");
200 "MPI_IN_PLACE",
"sumDurations");
202 const MInt maxLineLength = 256;
204 for(
MInt i = 0; i < noDurations; i++) {
205 const MString comment = durations[i].second;
206 snprintf(
b, maxLineLength,
"=== MAIA %s DURATION: %-35s | min: %.4e s | avg: %.4e s | max: %.4e s |",
207 module.c_str(), comment.c_str(), minDurations[i], sumDurations[i] / (
MFloat)noDomains, maxDurations[i]);
209 std::cerr <<
b << std::endl;
This class counts the static execution time of a function.
FunctionTiming & operator=(const FunctionTiming &t)
FunctionTiming(std::string name)
MTimers manages all MAIA Timers and allows primitive profiling.
static MString printTime(MFloat secs)
static MInt getTimingId(std::string name)
const MFloat m_initWallTime
static std::vector< FunctionTiming > s_functionTimings
const MFloat m_initCpuTime
MBool approx(const T &, const U &, const T)
MFloat cpuTime()
Return the process cpu time (user time) (high-resolution timer - do not use clock())
std::basic_string< char > MString
int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, const MString &name, const MString &sndvarname, const MString &rcvvarname)
same as MPI_Allreduce
void logDuration_(const MFloat timeStart, const MString module, const MString comment, const MPI_Comm comm, const MInt domainId, const MInt noDomains)
Output the min/max/average duration of a code section over the ranks in a communicator Note: only use...
void logDurations(std::vector< std::pair< MFloat, MString > > &durations, const MString module, const MPI_Comm comm, const MInt domainId, const MInt noDomains)
Output the min/max/average durations of provided timed code sections over the ranks in a communicator...
MBool operator<(const FunctionTiming &a, const FunctionTiming &b)