MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_MutuallyExclusiveTime.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// MueLu: A package for multigrid based preconditioning
4//
5// Copyright 2012 NTESS and the MueLu contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef MUELU_MUTUALLYEXCLUSIVETIME_HPP
11#define MUELU_MUTUALLYEXCLUSIVETIME_HPP
12
13#include <string>
14#include <stack>
15#include "Teuchos_RCPDecl.hpp" // for RCP
16
17// types for explicit instantiation
19#include "MueLu_Level_fwd.hpp"
20#include "MueLu_BaseClass.hpp"
21
22namespace MueLu {
23
38template <class TagName>
40 public:
42
43
44 MutuallyExclusiveTime(const std::string& name, bool startFlag = false);
45
49
53 void start(bool reset = false);
54
56
57
61 double stop();
62
64 void pause();
65
69
70 void resume();
71
73
75
76
77 bool isRunning();
78
79 bool isPaused();
80
82
84 // Note: this function is provided by the timer class, not by a monitor (!= Teuchos)
85 static RCP<MutuallyExclusiveTime<TagName> > getNewTimer(const std::string& name);
86
88 void incrementNumCalls();
89
91 std::string name_;
92
99 static void PrintParentChildPairs();
100
101 private:
104 MutuallyExclusiveTime(RCP<Teuchos::Time> timer);
105
106 // MutuallyExclusiveTime() { }
107
109 RCP<Teuchos::Time> timer_;
111
113 // - empty when no active timer
114 // - head is the active timer
115 // - other timers are timers paused to enforce the mutually exclusive property of the timer set.
116 static std::stack<MutuallyExclusiveTime<TagName>*> timerStack_;
117 // static std::map<std::string,std::string> myParent_;
118
120 void TopOfTheStack();
121
122 // TODO: test integrity of the stack:
123 // Head = running or paused
124 // Other timers of the stack = paused
125};
126
127extern template class MutuallyExclusiveTime<FactoryBase>;
128extern template class MutuallyExclusiveTime<Level>;
129extern template class MutuallyExclusiveTime<BaseClass>;
130
131} // namespace MueLu
132
133#endif // MUELU_MUTUALLYEXCLUSIVETIME_HPP
Base class for MueLu classes.
This class wraps a Teuchos::Time and maintains a mutually exclusive property between wrapped timers.
void pause()
Pause running timer. Used internally by start().
void resume()
Resume paused timer. Used internally by stop(). Timer is not reset.
std::string name_
Name of this mutually exclusive timer.
static std::stack< MutuallyExclusiveTime< TagName > * > timerStack_
Stack of created timers (active or paused timers).
void TopOfTheStack()
Check if 'this' is the head of the stack.
double stop()
Stops the timer. The previous MutuallyExclusiveTime that has been paused when this timer was started ...
static void PrintParentChildPairs()
Print std::map of (child,parent) pairs for post-run analysis.
static RCP< MutuallyExclusiveTime< TagName > > getNewTimer(const std::string &name)
Return a new MutuallyExclusiveTime that is registered with the Teuchos::TimeMonitor (for timer summar...
void incrementNumCalls()
Increment the number of times this timer has been called.
void start(bool reset=false)
Starts the timer. If a MutuallyExclusiveTime timer is running, it will be stopped.
RCP< Teuchos::Time > timer_
Using an RCP allows to use Teuchos::TimeMonitor to keep track of the timer.
Namespace for MueLu classes and methods.