MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef TIMER_H
8#define TIMER_H
9
10#include <iomanip>
11#include <string>
12#include <time.h>
13#include "COMM/mpioverride.h"
15#include "INCLUDE/maialikwid.h"
16#include "IO/infoout.h"
17#include "compiler_config.h"
18#include "functions.h"
19#include "globalvariables.h"
20
21#if defined(MAIA_MS_COMPILER)
22#include <Windows.h>
23#else
24#include <sys/time.h>
25#include <sys/times.h>
26#include <unistd.h>
27#endif
28
29// Note: required for writing to m_log
30#ifndef PVPLUGIN
31extern InfoOutFile m_log;
33#else
34extern std::ostream& m_log;
35extern std::ostream& maia_res;
36#endif
37
38#if defined(MAIA_MS_COMPILER)
39static const unsigned __int64 epoch = ((unsigned __int64)116444736000000000ULL);
40#endif
41
42#ifdef MAIA_TIMER_FUNCTION
43#define NEW_TIMER_GROUP(id, groupName) const MInt id = timers().newGroup(groupName)
44#define NEW_TIMER(id, timerName, groupId) const MInt id = timers().newGroupTimer(timerName, groupId)
45#define NEW_SUB_TIMER(id, timerName, timerId) const MInt id = timers().newSubTimer(timerName, timerId)
46#define NEW_TIMER_GROUP_STATIC(id, groupName) static const MInt id = timers().newGroup(groupName)
47#define NEW_TIMER_STATIC(id, timerName, groupId) static const MInt id = timers().newGroupTimer(timerName, groupId)
48#define NEW_SUB_TIMER_STATIC(id, timerName, timerId) static const MInt id = timers().newSubTimer(timerName, timerId)
49#define NEW_TIMER_GROUP_NOCREATE(id, groupName) id = timers().newGroup(groupName)
50#define NEW_TIMER_NOCREATE(id, timerName, groupId) id = timers().newGroupTimer(timerName, groupId)
51#define NEW_SUB_TIMER_NOCREATE(id, timerName, timerId) id = timers().newSubTimer(timerName, timerId)
52#define RECORD_TIMER_START(timerId) timers().recordTimerStart(timerId, AT_)
53#define RECORD_TIMER_STOP(timerId) timers().recordTimerStop(timerId, AT_)
54#define RETURN_TIMER(timerId) timers().returnTimer(timerId, AT_)
55#define RETURN_TIMER_TIME(timerId) timers().returnTimerTime(timerId)
56#define STOP_ALL_TIMERS() timers().stopAllTimers(AT_)
57#define RECORD_TIMER(timerId) timers().recordTimer(timerId, AT_)
58#define RECORD_TIMERS() timers().recordTimers(AT_)
59#define STOP_ALL_RECORD_TIMERS() timers().stopAllRecordTimers(AT_)
60#define DISPLAY_TIMER(timerId) timers().displayTimer(timerId)
61#define DISPLAY_TIMER_INTERM(timerId) timers().displayTimerNoToggleDisplayed(timerId)
62#define DISPLAY_TIMER_OFFSET(timerId, ivl) \
63 if(globalTimeStep % ivl == 0) timers().displayTimerNoToggleDisplayed(timerId)
64#define DISPLAY_ALL_GROUP_TIMERS(groupId) timers().displayAllTimers(groupId)
65#define DISPLAY_ALL_TIMERS() timers().displayAllTimers()
66#define RESET_TIMER(timerId) timers().resetTimer(timerId, AT_)
67#define RESET_TIMERS() timers().resetTimers(AT_)
68#define RESET_RECORD(timerId) timers().resetRecord(timerId)
69#define SET_RECORD(timerId, timerValue) timers().resetRecord(timerId, timerValue)
70#define RESET_ALL_RECORDS() timers().resetRecords()
71#define SET_RECORD(timerId, timerValue) timers().resetRecord(timerId, timerValue)
72#else
73#define NEW_TIMER_GROUP(id, groupName) \
74 do { \
75 } while(false)
76#define NEW_TIMER(id, timerName, groupId) \
77 do { \
78 } while(false)
79#define NEW_SUB_TIMER(id, timerName, timerId) \
80 do { \
81 } while(false)
82#define NEW_TIMER_GROUP_STATIC(id, groupName) \
83 do { \
84 } while(false)
85#define NEW_TIMER_STATIC(id, timerName, groupId) \
86 do { \
87 } while(false)
88#define NEW_SUB_TIMER_STATIC(id, timerName, timerId) \
89 do { \
90 } while(false)
91#define NEW_TIMER_GROUP_NOCREATE(id, groupName) \
92 do { \
93 } while(false)
94#define NEW_TIMER_NOCREATE(id, timerName, groupId) \
95 do { \
96 } while(false)
97#define NEW_SUB_TIMER_NOCREATE(id, timerName, timerId) \
98 do { \
99 } while(false)
100#define RECORD_TIMER_START(timerId) \
101 do { \
102 } while(false)
103#define RECORD_TIMER_STOP(timerId) \
104 do { \
105 } while(false)
106#define RETURN_TIMER(timerId) \
107 do { \
108 } while(false)
109#define STOP_ALL_TIMERS() \
110 do { \
111 } while(false)
112#define RECORD_TIMER(timerId) \
113 do { \
114 } while(false)
115#define DISPLAY_TIMER(timerId) \
116 do { \
117 } while(false)
118#define DISPLAY_ALL_GROUP_TIMERS(groupId) \
119 do { \
120 } while(false)
121#define DISPLAY_ALL_TIMERS() \
122 do { \
123 } while(false)
124#define RESET_TIMER(timerId) \
125 do { \
126 } while(false)
127#define RESET_TIMERS() \
128 do { \
129 } while(false)
130#define RESET_RECORD(timerId) \
131 do { \
132 } while(false)
133#define RESET_ALL_RECORDS() \
134 do { \
135 } while(false)
136#define SET_RECORD(timeValue, timerId) \
137 do { \
138 } while(false)
139#endif
140
169class MTimers {
170 friend MTimers& timers();
171
172 public:
173 inline MInt newGroup(const std::string groupName);
174 inline MInt newGroupTimer(const std::string timerName, const MInt groupId);
175 inline MInt newSubTimer(const std::string timerName, const MInt timerId);
176 inline MFloat returnTimer(const MInt timerId, const MString pos);
177 inline MFloat returnTimerTime(const MInt timerId);
178 inline void resetTimer(const MInt timerId, const MString pos); // reset
179 inline void recordTimer(const MInt timerId, const MString pos); // record
180 inline void recordTimerStart(const MInt timerId, const MString pos); // reset + start
181 inline void recordTimerStop(const MInt timerId, const MString pos); // stop + record
182 inline void recordTimers(const MString pos);
183 inline void stopAllTimers(const MString pos);
184 inline void stopAllRecordTimers(const MString pos); // stop all + record stopped
185 inline void displayTimer(const MInt timerId);
186 inline void displayTimerNoToggleDisplayed(const MInt timerId);
187 inline void displayAllTimers();
188 inline void displayAllTimers(const MInt groupId);
189 inline void resetTimers(const MString pos);
190 inline void resetRecord(const MInt timerId, const MFloat timerValue = 0.0);
191 inline void resetRecords();
192 inline MInt isRunning(const MInt timerId) const { return m_timers[timerId].status == Timer::Running; };
193
194 private:
195 inline void startTimer(const MInt timerId, const MString pos);
196 inline void stopTimer(const MInt timerId, const MString pos);
197
198 private:
200#if defined(MAIA_TIMER_FUNCTION)
201 m_log << "MTimers: timers enabled." << std::endl;
202#endif
203#if defined(MAIA_TIMER_DEBUG)
204 m_log << "MTimers: timer debug enabled." << std::endl;
205#endif
206#if defined(MAIA_TIMER_CHECKS)
207 m_log << "MTimers: timer checks enabled." << std::endl;
208#endif
209#if defined(MAIA_ASSERT_TIMER_CHECKS)
210 m_log << "MTimers: assert timer checks enabled." << std::endl;
211#endif
212 }
214 // delete: copy construction, and copy assignment
217
218 struct Timer {
219 Timer(const MString n, const MInt g, const MInt id, const MInt p)
220 : name(n),
221 group(g),
222 timerId(id),
223 parent(p),
224 cpuTime(0),
225 oldCpuTime(0),
226 recordedTime(0),
228 subTimers(0) {}
230 MInt group = -1;
237 enum { Uninitialized = 0, Running = 1, Stopped = 2 };
238 std::vector<MInt> subTimers{};
240 };
241
242 std::vector<std::string> m_groups;
243 std::vector<Timer> m_timers;
244
245 inline MFloat time();
246 inline void displayTimer_(const MInt timerId,
247 const MBool toggleDisplayed = true,
248 const MInt tIndent = 0,
249 const MFloat superTime = -1.0);
250 inline void displayTimerHeader_();
251 inline void displayTimerGroupHeader_(const MInt groupId);
252 inline MInt indent(const MInt pIndent) const { return pIndent + 2; };
253};
254
255MTimers& timers();
256
262#ifdef MAIA_MPI_TIMER
263 return MPI_Wtime();
264#else
265#if _POSIX_TIMERS > 0
266 timespec t;
267 clock_gettime(CLOCK_REALTIME, &t);
268 return static_cast<MFloat>(t.tv_sec) + static_cast<MFloat>(t.tv_nsec / 1000000000.0);
269#else
270 struct timeval t;
271 gettimeofday(&t, nullptr);
272 return static_cast<MFloat>(t.tv_sec) + static_cast<MFloat>(t.tv_usec / 1000000.0);
273#endif
274#endif
275}
276
277inline void MTimers::resetRecord(const MInt timerId, const MFloat timerValue) {
278 m_timers[timerId].recordedTime = timerValue;
279}
280
282 for(std::size_t timerId = 0, e = m_timers.size(); timerId != e; ++timerId) {
283 resetRecord((MInt)timerId);
284 }
285}
286
287inline void MTimers::recordTimerStop(const MInt timerId, const MString pos) {
288 if(timerId < 0) {
289 return;
290 }
291#ifdef MAIA_SYNCHRONIZE_TIMERS
292 MPI_Barrier(MPI_COMM_WORLD);
293#endif
294 stopTimer(timerId, pos);
295 recordTimer(timerId, pos);
296}
297
298inline void MTimers::recordTimer(const MInt timerId, const MString pos) {
299 m_timers[timerId].recordedTime += returnTimer(timerId, pos);
300}
301
302inline void MTimers::recordTimers(const MString pos) {
303 for(std::size_t timerId = 0, e = m_timers.size(); timerId != e; ++timerId) {
304 recordTimer(timerId, pos);
305 }
306}
307
308inline void MTimers::resetTimer(const MInt timerId, [[maybe_unused]] const MString pos) {
309#if defined(MAIA_TIMER_CHECKS)
310 if(m_timers[timerId].status == Timer::Running) {
311 const MString msg = "The timer #" + std::to_string(timerId) + " '" + m_timers[timerId].name
312 + "' can't be reset because it is running! " + pos;
313 m_log << msg << std::endl;
314 std::cerr << msg << std::endl;
315#if defined(MAIA_ASSERT_TIMER_CHECKS)
316 TERMM(1, msg);
317#endif
318 }
319#endif
320
321 m_timers[timerId].cpuTime = 0.0;
322 m_timers[timerId].status = Timer::Stopped;
323}
324
325inline void MTimers::resetTimers(const MString pos) {
326 for(std::size_t timerId = 0, e = m_timers.size(); timerId != e; ++timerId) {
327 resetTimer(timerId, pos);
328 }
329}
330
332inline MInt MTimers::newGroup(const std::string name) {
333 m_groups.push_back(name);
334#if defined(MAIA_TIMER_DEBUG)
335 m_log << "New timer group " << m_groups.size() - 1 << " '" << name << "' " << std::endl;
336#endif
337 return m_groups.size() - 1;
338}
339
341inline MInt MTimers::newGroupTimer(const std::string name, const MInt groupId) {
342 ASSERT(static_cast<std::size_t>(groupId) < m_groups.size() && groupId > -1,
343 "groupId: " << groupId << " does not exists | name: " << name);
344 const MInt newTimerId = m_timers.size();
345 m_timers.push_back(Timer(name, groupId, newTimerId, -1));
346#if defined(MAIA_TIMER_DEBUG)
347 m_log << "New group timer " << newTimerId << " '" << name << "' " << groupId << std::endl;
348#endif
349 return newTimerId;
350}
351
353inline MInt MTimers::newSubTimer(const std::string name, const MInt timerId) {
354 if(timerId < 0) {
355#if defined(MAIA_TIMER_DEBUG)
356 m_log << "cannot create subTimer '" << name << "'" << std::endl;
357#endif
358 return -1;
359 }
360
361 ASSERT(static_cast<std::size_t>(timerId) < m_timers.size(),
362 "timerId " << timerId << " does not exist when trying to create subtimer with name " << name);
363
364 const MInt groupId = m_timers[timerId].group;
365 const MInt newTimerId = m_timers.size();
366 m_timers.push_back(Timer(name, groupId, newTimerId, timerId));
367#if defined(MAIA_TIMER_DEBUG)
368 m_log << "New subtimer " << newTimerId << " '" << name << "' " << groupId << " " << timerId << std::endl;
369#endif
370 m_timers[timerId].subTimers.push_back(newTimerId);
371 return newTimerId;
372}
373
374inline void MTimers::recordTimerStart(const MInt timerId, const MString pos) {
375 if(timerId < 0) {
376 return;
377 }
378#ifdef MAIA_SYNCHRONIZE_TIMERS
379 MPI_Barrier(MPI_COMM_WORLD);
380#endif
381 resetTimer(timerId, pos);
382 startTimer(timerId, pos);
383}
384
385inline void MTimers::startTimer(const MInt timerId, [[maybe_unused]] const MString pos) {
386 ASSERT(m_timers[timerId].status != Timer::Running,
387 "The timer " << m_timers[timerId].name << " with id: " << timerId
388 << " can't be started because it is already running! " << pos);
389
390#if defined(MAIA_TIMER_CHECKS)
391 const MInt parent = m_timers[timerId].parent;
392 if(parent != -1) {
393 if(m_timers[parent].status != Timer::Running) {
394 const MString msg = "The timer #" + std::to_string(timerId) + " '" + m_timers[timerId].name
395 + "' can't be started because its parent timer #" + std::to_string(parent) + " '"
396 + m_timers[parent].name + "' is not running! " + pos;
397 m_log << msg << std::endl;
398 std::cerr << msg << std::endl;
399#if defined(MAIA_ASSERT_TIMER_CHECKS)
400 TERMM(1, msg);
401#endif
402 }
403 }
404#endif
405
406#if defined(MAIA_TIMER_DEBUG)
407 m_log << "start timer #" + std::to_string(timerId) + " '" + m_timers[timerId].name + "' " << pos << std::endl;
408#endif
409
410 const MFloat t = time();
411 m_timers[timerId].oldCpuTime = m_timers[timerId].cpuTime;
412 m_timers[timerId].cpuTime = t;
413 m_timers[timerId].status = Timer::Running;
414
415 // Enable likwid counter if likwid is enabled
416#ifdef WITH_LIKWID
417 LIKWID_MARKER_START(std::to_string(timerId).c_str());
418#endif
419}
420
421
423inline MFloat MTimers::returnTimer(const MInt timerId, [[maybe_unused]] const MString pos) {
424 if(timerId < 0) {
425 TERMM(1, "Invalid timer id");
426 return 0.0;
427 }
428
429#if defined(MAIA_TIMER_CHECKS)
430 if(m_timers[timerId].status != Timer::Stopped) {
431 const MString msg = "The timer #" + std::to_string(timerId) + " '" + m_timers[timerId].name
432 + "' needs to be stopped before returnTimer() is called! " + pos;
433 m_log << msg << std::endl;
434 std::cerr << msg << std::endl;
435#if defined(MAIA_ASSERT_TIMER_CHECKS)
436 TERMM(1, msg);
437#endif
438 }
439#endif
440
441#if MAIA_TIMERS_AVERAGE_OVER_DOMAINS
442 const MFloat t = m_timers[timerId].cpuTime;
443 MFloat tmp_rcv = 0.0;
444 MPI_Reduce(&t, &tmp_rcv, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
445 return tmp_rcv / globalNoDomains();
446#else
447 return m_timers[timerId].cpuTime;
448#endif
449}
450
451// Returns the recorded time
452inline MFloat MTimers::returnTimerTime(const MInt timerId) { return m_timers[timerId].recordedTime; }
453
455inline void MTimers::stopTimer(const MInt timerId, [[maybe_unused]] const MString pos) {
456 if(timerId < 0) {
457#if defined(MAIA_TIMER_DEBUG)
458 m_log << "cannot stop timer " << timerId << " " << pos << std::endl;
459#endif
460 return;
461 }
462
463 if(m_timers[timerId].status == Timer::Running) {
464 const MFloat t = time();
465 m_timers[timerId].cpuTime = t - m_timers[timerId].cpuTime + m_timers[timerId].oldCpuTime;
466 m_timers[timerId].status = Timer::Stopped;
467
468#if defined(MAIA_TIMER_CHECKS)
469 for(auto subTimerId : m_timers[timerId].subTimers) {
470 if(m_timers[subTimerId].status == Timer::Running) {
471 const MString msg = "The timer #" + std::to_string(timerId) + " '" + m_timers[timerId].name
472 + "' can't be stopped because its sub-timer #" + std::to_string(subTimerId) + " '"
473 + m_timers[subTimerId].name + "' is still running! " + pos;
474 m_log << msg << std::endl;
475 std::cerr << msg << std::endl;
476#if defined(MAIA_ASSERT_TIMER_CHECKS)
477 TERMM(1, msg);
478#endif
479 }
480 }
481#endif
482
483#if defined(MAIA_TIMER_DEBUG)
484 m_log << "stop timer #" + std::to_string(timerId) + " '" + m_timers[timerId].name + "' " << pos << std::endl;
485#endif
486
487 // Stop likwid counter if likwid is enabled
488#ifdef WITH_LIKWID
489 LIKWID_MARKER_STOP(std::to_string(timerId).c_str());
490#endif
491 } else {
492#if defined(MAIA_TIMER_CHECKS)
493 const MString msg = "The timer '" + m_timers[timerId].name + "' can't be stopped because it is not running! " + pos;
494 m_log << msg << std::endl;
495 std::cerr << msg << std::endl;
496#if defined(MAIA_ASSERT_TIMER_CHECKS)
497 TERMM(1, msg);
498#endif
499#endif
500 }
501}
502
503
504// Stops all timers.
505inline void MTimers::stopAllTimers(const MString pos) {
506 for(std::size_t i = 0, e = m_timers.size(); i != e; ++i) {
507 if(m_timers[i].status == Timer::Running) {
508 stopTimer(i, pos);
509 }
510 }
511}
512
513// Stops all timers and record the timers that were stopped
514inline void MTimers::stopAllRecordTimers(const MString pos) {
515 // for(std::size_t i = 0, e = m_timers.size(); i != e; ++i) {
516 for(MInt i = m_timers.size() - 1; i >= 0; i--) {
517 if(m_timers[i].status == Timer::Running) {
518#ifdef MAIA_SYNCHRONIZE_TIMERS
519 MPI_Barrier(MPI_COMM_WORLD);
520#endif
521 stopTimer(i, pos);
522 recordTimer(i, pos);
523 }
524 }
525}
526
527
528inline void MTimers::displayTimer_(const MInt timerId, const MBool toggleDisplayed, const MInt tIndent,
529 const MFloat superTime) {
530 if(m_timers[timerId].displayed) {
531 return;
532 }
533
534 /* MBool running = false; */
535 if(m_timers[timerId].status == Timer::Running) {
536 // NOTE: test this if needed, but not used at the moment
537 TERMM(1, "Timer is still running");
538 /* running = true; */
539 /* stopTimer(timerId, AT_); */
540 }
541 m_log.width(50);
542 m_log.setf(std::ios::left);
543 std::stringstream indentedName;
544
545 // Calculate time relative to the parent timer
546 MFloat percentage;
547 if(superTime < F0) {
548 // If the parent time is less than zero, that means that there is no parent timer
549 // and the percentage should be 100%
550 percentage = 100.0;
551 } else if(approx(superTime, F0, MFloatEps)) {
552 // If the parent time is approximately zero, that probably means that the timer was never
553 // run - therefore the percentage is set to 0%
554 percentage = F0;
555 } else {
556 // Otherwise calculate the percentage as the fraction of this timer vs. the parent timer times 100%
557 percentage = 100.0 * m_timers[timerId].recordedTime / superTime;
558 }
559
560 indentedName << std::string(tIndent, ' ');
561 indentedName << "[" << std::fixed << std::setprecision(1) << std::setw(4) << std::setfill('0') << std::right
562 << percentage << std::left << "%] ";
563 indentedName << m_timers[timerId].name;
564 m_log << indentedName.str() << std::right;
565 m_log.precision(6);
566 m_log.width(20);
567 m_log << m_timers[timerId].recordedTime << std::left << " [sec]";
568 // Show output of likwid performance counters if likwid is enabled
569#ifdef WITH_LIKWID
570 // If the timer wasn't called set the MFLops to 0.00
571 m_log << " ";
572 if(approx(m_timers[timerId].recordedTime, F0, MFloatEps)) {
573 m_log << "0.00";
574 } else {
575 m_log << "${timer_" << timerId << "}";
576 }
577 m_log << " [DP MFlops/s]";
578#endif
579 if(toggleDisplayed) m_timers[timerId].displayed = true;
580 m_log << std::endl;
581 for(std::size_t sub = 0, last = m_timers[timerId].subTimers.size(); sub < last; ++sub) {
582 const MInt new_indent = indent(tIndent);
583 displayTimer_(m_timers[timerId].subTimers[sub], toggleDisplayed, new_indent, m_timers[timerId].recordedTime);
584 }
585 /* if(running) { */
586 /* startTimer(timerId, AT_); */
587 /* } */
588}
589
591
592inline void MTimers::displayTimerGroupHeader_(const MInt groupId) {
593 m_log << "--------------------------------------------------------------------------------" << std::endl;
594 m_log.width(50);
595 m_log.precision(12);
596 m_log.setf(std::ios::left);
597 m_log << "Group";
598 m_log.width(40);
599 m_log << m_groups[groupId] << std::endl;
600}
601
603 ASSERT(m_timers.size() > 0, "ERROR: no timers have been created!");
604 for(std::size_t groupId = 0, e = m_groups.size(); groupId != e; ++groupId) {
605 displayAllTimers(groupId);
606 }
607}
608
609inline void MTimers::displayAllTimers(const MInt groupId) {
610 ASSERT(m_timers.size() > 0, "ERROR: no timers have been created!");
611 ASSERT(static_cast<std::size_t>(groupId) < m_groups.size() && groupId > -1, "ERROR: groupId does not exists");
612 for(std::size_t timerId = 0, e = m_timers.size(); timerId != e; ++timerId) {
613 m_timers[timerId].displayed = false;
614 }
617 for(std::size_t timerId = 0, e = m_timers.size(); timerId != e; ++timerId) {
618 if(m_timers[timerId].group == groupId) {
619 displayTimer_(timerId);
620 }
621 }
622 for(std::size_t timerId = 0, e = m_timers.size(); timerId != e; ++timerId) {
623 m_timers[timerId].displayed = false;
624 }
625}
626
627inline void MTimers::displayTimer(const MInt timerId) {
628 ASSERT(static_cast<std::size_t>(timerId) < m_timers.size(), "ERROR: timer timerId does not exist");
630 displayTimer_(timerId);
631}
632
634 ASSERT(static_cast<std::size_t>(timerId) < m_timers.size(), "ERROR: timer timerId does not exist");
636 displayTimer_(timerId, false);
637}
638
639//------------------------------------------------------------------------------
640
641class Profile;
642class FunctionTiming;
643
650 public:
651 explicit FunctionTiming(std::string name);
654 void in();
655 void out();
660 MString getName() const { return m_name; }
661
662 private:
670};
671
673
679class Profile {
680 public:
681 explicit Profile(const std::string& name) : m_initCpuTime(cpuTime()), m_initWallTime(wallTime()), m_name(name) {}
682 ~Profile();
683 static MInt getTimingId(std::string name);
684 static MString printTime(MFloat secs);
685 static std::vector<FunctionTiming> s_functionTimings;
686
687 private:
691};
692
693
694void logDuration_(const MFloat timeStart,
695 const MString module,
696 const MString comment,
697 const MPI_Comm comm,
698 const MInt domainId,
699 const MInt noDomains);
700
701void logDurations(std::vector<std::pair<MFloat, MString>>& durations, const MString module, const MPI_Comm comm,
702 const MInt domainId, const MInt noDomains);
703
704#endif // TIMER_H
This class counts the static execution time of a function.
Definition: timer.h:649
MFloat getDeltaWallTime() const
Definition: timer.h:659
FunctionTiming & operator=(const FunctionTiming &t)
Definition: timer.cpp:142
MFloat m_initWallTime
Definition: timer.h:666
MFloat m_deltaWallTime
Definition: timer.h:667
MFloat m_deltaCpuTime
Definition: timer.h:664
MString m_name
Definition: timer.h:669
MString getName() const
Definition: timer.h:660
MFloat getDeltaCpuTime() const
Definition: timer.h:657
MFloat m_tmpCpuTime
Definition: timer.h:665
void in()
Definition: timer.cpp:153
MFloat m_tmpWallTime
Definition: timer.h:668
void out()
Definition: timer.cpp:158
MFloat m_initCpuTime
Definition: timer.h:663
MFloat getInitCpuTime() const
Definition: timer.h:656
MFloat getInitWallTime() const
Definition: timer.h:658
Class to create a create an output stream for a writable file, using either MPI I/O or a physical fil...
Definition: infoout.h:217
MTimers manages all MAIA Timers and allows primitive profiling.
Definition: timer.h:169
void recordTimerStart(const MInt timerId, const MString pos)
Definition: timer.h:374
void stopTimer(const MInt timerId, const MString pos)
Stops the timer and sets its final value.
Definition: timer.h:455
MFloat returnTimer(const MInt timerId, const MString pos)
Returns the timer Value.
Definition: timer.h:423
MInt newSubTimer(const std::string timerName, const MInt timerId)
Creates a new timer and returns its timerId.
Definition: timer.h:353
void stopAllRecordTimers(const MString pos)
Definition: timer.h:514
void resetTimer(const MInt timerId, const MString pos)
Definition: timer.h:308
void recordTimers(const MString pos)
Definition: timer.h:302
void displayTimerHeader_()
Definition: timer.h:590
MTimers & operator=(const MTimers &)
MFloat returnTimerTime(const MInt timerId)
Definition: timer.h:452
MFloat time()
Returns Wall-Clock time in seconds.
Definition: timer.h:258
void resetRecords()
Definition: timer.h:281
void resetRecord(const MInt timerId, const MFloat timerValue=0.0)
Definition: timer.h:277
MInt newGroupTimer(const std::string timerName, const MInt groupId)
Creates a new timer and returns its timerId.
Definition: timer.h:341
MInt newGroup(const std::string groupName)
Creates a new timer group and returns its groupId.
Definition: timer.h:332
MTimers(MTimers &)
void displayAllTimers()
Definition: timer.h:602
friend MTimers & timers()
Definition: timer.cpp:19
MTimers()
Definition: timer.h:199
void recordTimerStop(const MInt timerId, const MString pos)
Definition: timer.h:287
void recordTimer(const MInt timerId, const MString pos)
Definition: timer.h:298
void displayTimer(const MInt timerId)
Definition: timer.h:627
void displayTimerGroupHeader_(const MInt groupId)
Definition: timer.h:592
void stopAllTimers(const MString pos)
Definition: timer.h:505
void displayTimer_(const MInt timerId, const MBool toggleDisplayed=true, const MInt tIndent=0, const MFloat superTime=-1.0)
Definition: timer.h:528
std::vector< Timer > m_timers
Definition: timer.h:243
void resetTimers(const MString pos)
Definition: timer.h:325
void displayTimerNoToggleDisplayed(const MInt timerId)
Definition: timer.h:633
MInt isRunning(const MInt timerId) const
Definition: timer.h:192
~MTimers()
Definition: timer.h:213
std::vector< std::string > m_groups
Definition: timer.h:242
void startTimer(const MInt timerId, const MString pos)
Definition: timer.h:385
MInt indent(const MInt pIndent) const
Definition: timer.h:252
This class collects all function timings and produces a profiling for certain areas of the code.
Definition: timer.h:679
static MString printTime(MFloat secs)
Definition: timer.cpp:106
static MInt getTimingId(std::string name)
Definition: timer.cpp:88
const MFloat m_initWallTime
Definition: timer.h:689
~Profile()
Definition: timer.cpp:32
Profile(const std::string &name)
Definition: timer.h:681
const MString m_name
Definition: timer.h:690
static std::vector< FunctionTiming > s_functionTimings
Definition: timer.h:685
const MFloat m_initCpuTime
Definition: timer.h:688
MBool approx(const T &, const U &, const T)
Definition: functions.h:272
MFloat cpuTime()
Return the process cpu time (user time) (high-resolution timer - do not use clock())
Definition: functions.h:73
MFloat wallTime()
Definition: functions.h:80
MInt globalNoDomains()
Return global number of domains.
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
MInt id
Definition: maiatypes.h:71
int MPI_Barrier(MPI_Comm comm, const MString &name)
same as MPI_Barrier
int MPI_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm, const MString &name, const MString &sndvarname, const MString &rcvvarname)
same as MPI_Reduce
MInt status
Timer's status, see enum:
Definition: timer.h:236
@ Uninitialized
Definition: timer.h:237
std::vector< MInt > subTimers
Definition: timer.h:238
MFloat recordedTime
Time recorded on the timer.
Definition: timer.h:235
MString name
Timer Name.
Definition: timer.h:229
MInt parent
Parent timer id.
Definition: timer.h:232
MInt group
Group Id.
Definition: timer.h:230
MFloat oldCpuTime
Old CPU time (for timer restart)
Definition: timer.h:234
MFloat cpuTime
CPU time.
Definition: timer.h:233
MInt timerId
Definition: timer.h:231
Timer(const MString n, const MInt g, const MInt id, const MInt p)
Definition: timer.h:219
MBool displayed
Definition: timer.h:239
Definition: contexttypes.h:19
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...
Definition: timer.cpp:171
InfoOutFile m_log
Definition: timer.h:34
MTimers & timers()
Definition: timer.cpp:19
InfoOutFile maia_res
Definition: timer.h:35
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
MBool operator<(const FunctionTiming &a, const FunctionTiming &b)
Definition: timer.cpp:27