50#include "Teuchos_FancyOStream.hpp"
51#include "Teuchos_RCP.hpp"
52#include "Teuchos_TestForException.hpp"
53#include "Teuchos_Time.hpp"
54#include "Teuchos_TimeMonitor.hpp"
67 template <
class TagName>
70 timer_(rcp(new
Teuchos::Time(name, false))),
74 if (startFlag ==
true)
timer_->start();
77 template <
class TagName>
82 GetOStream(
Errors) <<
"MutuallyExclusiveTime::~MutuallyExclusiveTime(): Error: destructor called on a paused timer." << std::endl;
89 template <
class TagName>
91 TEUCHOS_TEST_FOR_EXCEPTION(isPaused(),
Exceptions::RuntimeError,
"MueLu::MutuallyExclusiveTime::start(): timer is paused. Use resume().");
93 if (isRunning()) {
return; }
97 if (!timerStack_.empty()) {
98 GetOStream(
Debug) <<
"pausing parent timer " << timerStack_.top()->name_ << std::endl;
99 timerStack_.top()->pause();
100 GetOStream(
Debug) <<
"starting child timer " << this->name_ << std::endl;
101 myParent_[this->name_] = timerStack_.top()->name_;
103 GetOStream(
Debug) <<
"starting orphan timer " << this->name_ << std::endl;
108 timer_->start(reset);
109 timerStack_.push(
this);
112 template <
class TagName>
115 GetOStream(
Errors) <<
"MueLu::MutuallyExclusiveTime::stop(): timer is paused. Use resume()" << std::endl;
117 if (!isRunning()) {
return timer_->stop(); }
123 double r = timer_->stop();
125 if (!timerStack_.empty()) {
126 GetOStream(
Debug) <<
"resuming timer " << timerStack_.top()->name_ << std::endl;
127 timerStack_.top()->resume();
133 template <
class TagName>
144 template <
class TagName>
152 timer_->start(
false);
156 template <
class TagName>
158 if (timer_->isRunning()) {
162 return timer_->isRunning();
165 template <
class TagName>
171 template <
class TagName>
178 template <
class TagName>
181 template <
class TagName>
184 RCP<Teuchos::FancyOStream> fos = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); fos->setOutputToRootOnly(0);
185 *fos <<
"Parent Child Map" << std::endl;
186 std::map<std::string, std::string >::const_iterator iter;
188 *fos <<
"Key: " << iter->first <<
" Value: " << iter->second << std::endl;
192 template <
class TagName>
194 : timer_(timer), isPaused_(false)
197 template <
class TagName>
199 TEUCHOS_TEST_FOR_EXCEPTION(timerStack_.empty(),
Exceptions::RuntimeError,
"MueLu::MutuallyExclusiveTime::TopOfTheStack(): timer is not the head of the stack (stack is empty).");
201 TEUCHOS_TEST_FOR_EXCEPTION(!(isRunning() || isPaused()),
Exceptions::RuntimeError,
"MueLu::MutuallyExclusiveTime::TopOfTheStack(): head of the stack timer is neither active nor paused.");
204 template <
class TagName>
Exception throws to report errors in the internal logical of the program.
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.
MutuallyExclusiveTime(const std::string &name, bool startFlag=false)
Constructor.
void TopOfTheStack()
Check if 'this' is the head of the stack.
~MutuallyExclusiveTime()
Destructor.
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.
@ Debug
Print additional debugging information.
std::map< std::string, std::string > myParent_