13#include "Teuchos_FancyOStream.hpp"
14#include "Teuchos_RCP.hpp"
15#include "Teuchos_TestForException.hpp"
16#include "Teuchos_Time.hpp"
17#include "Teuchos_TimeMonitor.hpp"
30template <
class TagName>
33 , timer_(rcp(new
Teuchos::Time(name, false)))
37 if (startFlag ==
true)
timer_->start();
40template <
class TagName>
45 GetOStream(
Errors) <<
"MutuallyExclusiveTime::~MutuallyExclusiveTime(): Error: destructor called on a paused timer." << std::endl;
52template <
class TagName>
54 TEUCHOS_TEST_FOR_EXCEPTION(isPaused(),
Exceptions::RuntimeError,
"MueLu::MutuallyExclusiveTime::start(): timer is paused. Use resume().");
62 if (!timerStack_.empty()) {
63 GetOStream(
Debug) <<
"pausing parent timer " << timerStack_.top()->name_ << std::endl;
64 timerStack_.top()->pause();
65 GetOStream(
Debug) <<
"starting child timer " << this->name_ << std::endl;
66 myParent_[this->name_] = timerStack_.top()->name_;
68 GetOStream(
Debug) <<
"starting orphan timer " << this->name_ << std::endl;
74 timerStack_.push(
this);
77template <
class TagName>
80 GetOStream(
Errors) <<
"MueLu::MutuallyExclusiveTime::stop(): timer is paused. Use resume()" << std::endl;
83 return timer_->stop();
90 double r = timer_->stop();
92 if (!timerStack_.empty()) {
93 GetOStream(
Debug) <<
"resuming timer " << timerStack_.top()->name_ << std::endl;
94 timerStack_.top()->resume();
100template <
class TagName>
111template <
class TagName>
119 timer_->start(
false);
123template <
class TagName>
125 if (timer_->isRunning()) {
129 return timer_->isRunning();
132template <
class TagName>
138template <
class TagName>
145template <
class TagName>
148template <
class TagName>
151 RCP<Teuchos::FancyOStream> fos = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
152 fos->setOutputToRootOnly(0);
153 *fos <<
"Parent Child Map" << std::endl;
154 std::map<std::string, std::string>::const_iterator iter;
156 *fos <<
"Key: " << iter->first <<
" Value: " << iter->second << std::endl;
160template <
class TagName>
163 , isPaused_(false) {}
165template <
class TagName>
167 TEUCHOS_TEST_FOR_EXCEPTION(timerStack_.empty(),
Exceptions::RuntimeError,
"MueLu::MutuallyExclusiveTime::TopOfTheStack(): timer is not the head of the stack (stack is empty).");
169 TEUCHOS_TEST_FOR_EXCEPTION(!(isRunning() || isPaused()),
Exceptions::RuntimeError,
"MueLu::MutuallyExclusiveTime::TopOfTheStack(): head of the stack timer is neither active nor paused.");
172template <
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_