Loading [MathJax]/extensions/tex2jax.js
MAIA bb96820c
Multiphysics at AIA
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
timer.cpp File Reference

Go to the source code of this file.

Functions

MTimerstimers ()
 
MBool operator< (const FunctionTiming &a, const FunctionTiming &b)
 
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 this function for timing initialization steps or similar due to the blocking MPI_Allreduce operations involved. Instead use logDurations() to assemble a vector of durations first and evaluate at once. More...
 
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. More...
 

Function Documentation

◆ logDuration_()

void logDuration_ ( const MFloat  timeStart,
const MString  module,
const MString  comment,
const MPI_Comm  comm,
const MInt  domainId,
const MInt  noDomains 
)
Parameters
[in]timeStartstart time obtained with wallTime()/MPI_Wtime() to compute difference to

Definition at line 171 of file timer.cpp.

172 {
173 const MFloat duration = wallTime() - timeStart;
174
175 std::vector<std::pair<MFloat, MString>> durations{};
176 durations.push_back(std::make_pair(duration, comment));
177 logDurations(durations, module, comm, domainId, noDomains);
178}
MFloat wallTime()
Definition: functions.h:80
double MFloat
Definition: maiatypes.h:52
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...
Definition: timer.cpp:182

◆ logDurations()

void logDurations ( std::vector< std::pair< MFloat, MString > > &  durations,
const MString  module,
const MPI_Comm  comm,
const MInt  domainId,
const MInt  noDomains 
)

Definition at line 182 of file timer.cpp.

183 {
184 const MInt noDurations = durations.size();
185
186 std::vector<MFloat> maxDurations(noDurations);
187 for(MInt i = 0; i < noDurations; i++) {
188 maxDurations[i] = durations[i].first;
189 }
190 // Copy durations vector
191 std::vector<MFloat> minDurations = maxDurations;
192 std::vector<MFloat> sumDurations = maxDurations;
193
194 // Compute max, min and sum of durations over all involved ranks
195 MPI_Allreduce(MPI_IN_PLACE, &maxDurations[0], noDurations, maia::type_traits<MFloat>::mpiType(), MPI_MAX, comm, AT_,
196 "MPI_IN_PLACE", "maxDurations");
197 MPI_Allreduce(MPI_IN_PLACE, &minDurations[0], noDurations, maia::type_traits<MFloat>::mpiType(), MPI_MIN, comm, AT_,
198 "MPI_IN_PLACE", "minDurations");
199 MPI_Allreduce(MPI_IN_PLACE, &sumDurations[0], noDurations, maia::type_traits<MFloat>::mpiType(), MPI_SUM, comm, AT_,
200 "MPI_IN_PLACE", "sumDurations");
201
202 const MInt maxLineLength = 256;
203 MChar b[maxLineLength];
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]);
208 if(domainId == 0) {
209 std::cerr << b << std::endl;
210 }
211 m_log << b << std::endl;
212 }
213}
InfoOutFile m_log
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
char MChar
Definition: maiatypes.h:56
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

◆ operator<()

MBool operator< ( const FunctionTiming a,
const FunctionTiming b 
)

Definition at line 27 of file timer.cpp.

27 {
28 if(approx(a.getDeltaCpuTime(), b.getDeltaCpuTime(), MFloatEps)) return (a.getInitCpuTime() < b.getInitCpuTime());
29 return (a.getDeltaCpuTime() < b.getDeltaCpuTime());
30}
MBool approx(const T &, const U &, const T)
Definition: functions.h:272
Definition: contexttypes.h:19

◆ timers()

MTimers & timers ( )

Definition at line 19 of file timer.cpp.

19 {
20 static MTimers timers;
21 return timers;
22}
MTimers manages all MAIA Timers and allows primitive profiling.
Definition: timer.h:169
MTimers & timers()
Definition: timer.cpp:19