60 TERMM(1,
"Error: load balancing timers already enabled.");
73 TERMM(1,
"Error: load balancing timers not enabled.");
80 TERMM(1,
"Error: load balancing timers already enabled.");
96 TERMM(1, name +
"; Error: cannot start load timer while idle timer still running.");
114#ifdef MAIA_DEBUG_DLB_TIMER
118 <<
" diff " << diff << std::endl;
129 TERMM(1, name +
"; Error: cannot start idle timer while load timer still running.");
147#ifdef MAIA_DEBUG_DLB_TIMER
151 <<
" diff " << diff << std::endl;
166 TERMM(1, name +
"; error in startSolverTimer(" + std::to_string(timerId) +
"): timer already running, dlbTimerId "
173#ifdef MAIA_DEBUG_DLB_TIMER
174 m_log <<
"DLB timer #" <<
m_dlbTimerId <<
" startSolverTimer #" << timerId <<
" at time "
183 TERMM(1, name +
"; error in stopSolverTimer(" + std::to_string(timerId) +
"): timer not running, dlbTimerId "
186 const MFloat t_stop = MPI_Wtime();
195#ifdef MAIA_DEBUG_DLB_TIMER
196 m_log <<
"DLB timer #" <<
m_dlbTimerId <<
" stopSolverTimer #" << timerId <<
" at time "
197 <<
m_timerWallTime[timerId] <<
" with t_diff " << t_diff <<
" user time diff " << t_user_diff <<
" from "
198 << name << std::endl;
206 TERMM(1,
"error in resetSolverTimer(" + std::to_string(timerId) +
"): timer still running, dlbTimerId "
211#ifdef MAIA_DEBUG_DLB_TIMER
212 m_log <<
"DLB timer #" <<
m_dlbTimerId <<
" resetSolverTimer #" << timerId << std::endl;
224#define ENSURE_VALID_TIMERID(timerId, at) \
226 ASSERT(timerId >= 0 && timerId < noDlbTimers(), "invalid dlbTimerId: " + std::to_string(timerId)); \
228#define ENSURE_VALID_TIMERMODE(mode, at) \
230 ASSERT(mode >= 0 && mode <= 1, "invalid timer mode: " + std::to_string(mode)); \
237 TERMM(1,
"createDlbTimers should only be called once!");
242 clock_getres(CLOCK_PROCESS_CPUTIME_ID, &tp);
243 m_log <<
"DLB timer: CLOCK PROCESS CPUTIME RESOLUTION " << tp.tv_sec <<
"s " << tp.tv_nsec <<
"nsec" << std::endl;
245 for(
MInt i = 0; i < noTimers; i++) {
259 ENSURE_VALID_TIMERID(dlbTimerId, AT_);
272 MBool enableTimers =
true;
273 if(wasEnabled !=
nullptr) {
274 enableTimers = wasEnabled[i];
289 ENSURE_VALID_TIMERID(dlbTimerId, AT_);
292 MBool anyEnabled =
false;
294 anyEnabled |=
m_dlbTimers[dlbTimerId].dlbTimersEnabled();
306 TERMM(1,
"Cannot disable all DLB timers, timer " + std::to_string(
m_runningTimerId) +
" still running.");
312 if(wasEnabled !=
nullptr) {
313 wasEnabled[i] = timersEnabled;
329 ENSURE_VALID_TIMERID(dlbTimerId, AT_);
338 ENSURE_VALID_TIMERID(dlbTimerId, name);
346 TERMM(1,
"Cannot start load timer " + std::to_string(dlbTimerId) +
", timer " + std::to_string(
m_runningTimerId)
347 +
" already running.");
359 ENSURE_VALID_TIMERID(dlbTimerId, name);
365 ASSERT(dlbTimerId ==
m_runningTimerId,
"timer id does not match the running timer id");
375 ENSURE_VALID_TIMERID(dlbTimerId, name);
383 TERMM(1,
"Cannot start idle timer " + std::to_string(dlbTimerId) +
", timer " + std::to_string(
m_runningTimerId)
384 +
" already running.");
396 ENSURE_VALID_TIMERID(dlbTimerId, name);
402 ASSERT(dlbTimerId ==
m_runningTimerId,
"timer id does not match the running timer id");
414 TERMM(1,
"Cannot stop load and start idle timer, the running timer is: " + std::to_string(
m_runningTimerId) +
'/'
429 TERMM(1,
"Cannot stop idle and start load timer, the running timer is: " + std::to_string(
m_runningTimerId));
468 ENSURE_VALID_TIMERID(dlbTimerId, name);
469 ENSURE_VALID_TIMERMODE(mode, name);
470 return m_dlbTimers[dlbTimerId].returnLoadRecord(mode);
478 ENSURE_VALID_TIMERID(dlbTimerId, name);
479 ENSURE_VALID_TIMERMODE(mode, name);
480 return m_dlbTimers[dlbTimerId].returnIdleRecord(mode);
Controller class for all DLB timers.
void stopIdleTimer(const MInt dlbTimerId, const MString &name)
Stop the idle timer for the given DLB timer id.
MInt noDlbTimers() const
Return the number of DLB timers.
void startIdleTimer(const MInt dlbTimerId, const MString &name)
Start the idle timer for the given DLB timer id.
void startLoadTimer(const MInt dlbTimerId, const MString &name)
Start the load timer for the given DLB timer id.
void createDlbTimers(const MInt noTimers, const MBool ignore=false)
Create the given number of DLB timers.
MInt noSubTimers() const
Return the number of (sub-)timers for each DLB timer.
MInt m_runningTimerId
Id of the currently running DLB load/idle timer.
MFloat returnLoadRecord(const MInt dlbTimerId, const MInt mode=0)
Return the load record of a DLB timer.
void stopLoadTimer(const MInt dlbTimerId, const MString &name)
Stop the load timer for the given DLB timer id.
void stopIdleStartLoadTimer(const MString &name)
Stop the currently running idle timer and start the corresponding load timer.
MBool m_enabled
Current status of all timers; false: all timers disabled; true: at least one timer enabled.
void enableDlbTimers(const MInt dlbTimerId)
Enable the given DLB timer.
void reEnableDlbTimer(const MInt dlbTimerId)
MBool isTimerRunning() const
Return if a timer is running.
MInt whichTimerIsRunning() const
void disableDlbTimers(const MInt dlbTimerId)
Disable the given DLB timer.
void checkIOTimerStatus(const MString &name) const
Check the timer status during IO (no timer running and timers not enabled)
void enableAllDlbTimers(const MBool *const wasEnabled=nullptr)
Enable all DLB timers (or those given by the array wasEnabled)
MBool m_ignoreDlbTimers
Global switch in createDlbTimers() to ignore all DLB timers, i.e. they cannot be enabled.
void resetRecords()
Reset the records of all DLB timers.
MFloat returnIdleRecord(const MInt dlbTimerId, const MInt mode=0)
Return the idle record of a DLB timer.
MBool dlbTimersEnabled(const MInt dlbTimerId)
Return if the given DLB timer is enabled.
void stopLoadStartIdleTimer(const MString &name)
Stop the currently running load timer and start the corresponding idle timer.
void disableAllDlbTimers(MBool *const wasEnabled=nullptr)
Disable all (enabled) DLB timers.
MBool isLoadTimerRunning(const MInt dlbTimerId)
std::vector< maia::dlbTimer::DlbTimer > m_dlbTimers
Storage of DLB timers for all solvers/couplers/...
Class to create a create an output stream for a writable file, using either MPI I/O or a physical fil...
DlbTimer(const MInt timerId)
Constructor, just set the timer id.
void resetIdleRecord()
Reset the idle record.
MFloat returnIdleRecord(const MInt mode=0) const
Return the idle record.
const MInt m_dlbTimerId
Unique DLB timer id among all DLB timers.
void startLoadTimer(const MString &name)
Start the load timer.
MFloat m_timerUserTime[2]
MFloat m_timerWallTime[2]
Current time when the timers were started.
void disableDlbTimers()
Temporarily disable timers, e.g. during adaptation.
MFloat returnLoadRecord(const MInt mode=0) const
Return the load record.
void stopSolverTimer(const MInt timerId, const MString &name)
Stop the timer with the given id.
void startIdleTimer(const MString &name)
Start the idle timer.
MFloat m_recordedWallTime[2]
Recorded time of the timers.
void resetSolverTimer(const MInt timerId)
Reset the timer with the given id.
void stopIdleTimer(const MString &name)
Stop the idle timer.
MBool m_timerRunning[2]
Status of the timers.
const MInt m_loadTimerId
Timer indices.
void stopLoadTimer(const MString &name)
Stop the load timer.
MBool dlbTimersEnabled() const
Return if timers are enabled.
MFloat m_recordedUserTime[2]
void startSolverTimer(const MInt timerId, const MString &name)
Start the timer with the given id.
MBool m_dlbTimersEnabled
Stores if the timers are enabled.
void resetLoadRecord()
Reset the load record.
MBool isLoadTimerRunning() const
MFloat cpuTime()
Return the process cpu time (user time) (high-resolution timer - do not use clock())
std::basic_string< char > MString
Namespace for auxiliary functions/classes.