MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
22 namespace MueLu {
23 
38 template <class TagName>
40  public:
42 
43  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:
105 
106  // MutuallyExclusiveTime() { }
107 
110  bool isPaused_;
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 
127 extern template class MutuallyExclusiveTime<FactoryBase>;
128 extern template class MutuallyExclusiveTime<Level>;
129 extern template class MutuallyExclusiveTime<BaseClass>;
130 
131 } // namespace MueLu
132 
133 #endif // MUELU_MUTUALLYEXCLUSIVETIME_HPP
void TopOfTheStack()
Check if &#39;this&#39; is the head of the stack.
static std::stack< MutuallyExclusiveTime< TagName > * > timerStack_
Stack of created timers (active or paused timers).
void reset()
static RCP< MutuallyExclusiveTime< TagName > > getNewTimer(const std::string &name)
Return a new MutuallyExclusiveTime that is registered with the Teuchos::TimeMonitor (for timer summar...
static void PrintParentChildPairs()
Print std::map of (child,parent) pairs for post-run analysis.
void start(bool reset=false)
Starts the timer. If a MutuallyExclusiveTime timer is running, it will be stopped.
double stop()
Stops the timer. The previous MutuallyExclusiveTime that has been paused when this timer was started ...
std::string name_
Name of this mutually exclusive timer.
void incrementNumCalls()
Increment the number of times this timer has been called.
RCP< Teuchos::Time > timer_
Using an RCP allows to use Teuchos::TimeMonitor to keep track of the timer.
void pause()
Pause running timer. Used internally by start().
Base class for MueLu classes.
void resume()
Resume paused timer. Used internally by stop(). Timer is not reset.
This class wraps a Teuchos::Time and maintains a mutually exclusive property between wrapped timers...
MutuallyExclusiveTime(const std::string &name, bool startFlag=false)
Constructor.