MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_TimeMonitor.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_TIMEMONITOR_HPP
11 #define MUELU_TIMEMONITOR_HPP
12 
13 #include <string>
14 #include <Teuchos_DefaultComm.hpp>
15 #include <Teuchos_Time.hpp>
16 #include <Teuchos_TimeMonitor.hpp>
17 #include "MueLu_ConfigDefs.hpp"
18 #include "MueLu_BaseClass.hpp"
19 #include "MueLu_VerboseObject.hpp"
21 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
22 #include "Teuchos_StackedTimer.hpp"
23 #include <sstream>
24 #endif
25 
26 namespace MueLu {
27 
32 class TimeMonitor : public BaseClass {
33  public:
34  TimeMonitor(const BaseClass& object, const std::string& msg, MsgType timerLevel = Timings0);
35 
36  ~TimeMonitor();
37 
38  protected:
39  TimeMonitor();
40 
41  private:
43 }; // class TimeMonitor
44 
45 // TODO: code duplication MutuallyExclusiveTimeMonitor / TimeMonitor
46 
52 template <class TagName>
54  public:
61  MutuallyExclusiveTimeMonitor(const BaseClass& object, const std::string& msg, MsgType timerLevel = Timings0) {
62  // Inherit props from 'object'
63  SetVerbLevel(object.GetVerbLevel());
65 
66  if (IsPrint(timerLevel) &&
67  /* disable timer if never printed: */ (IsPrint(RuntimeTimings) || (!IsPrint(NoTimeReport)))) {
68  if (!IsPrint(NoTimeReport)) {
69  timer_ = MutuallyExclusiveTime<TagName>::getNewTimer("MueLu: " + msg /*+ " (MutuallyExclusive)" */);
70  } else {
71  timer_ = rcp(new MutuallyExclusiveTime<TagName>("MueLu: " + msg /*+ " (MutuallyExclusive)" */));
72  }
73 
74  timer_->start();
75  timer_->incrementNumCalls();
76  }
77  }
78 
80  // Stop the timer if present
81  if (timer_ != Teuchos::null)
82  timer_->stop();
83  }
84 
85  protected:
87 
88  private:
89  RCP<MutuallyExclusiveTime<TagName> > timer_; // keep a reference on the timer to print stats if RuntimeTimings=ON //TODO:use base class instead
90 };
91 
92 extern template class MutuallyExclusiveTimeMonitor<FactoryBase>;
93 extern template class MutuallyExclusiveTimeMonitor<Level>;
94 
95 } // namespace MueLu
96 
97 #endif // MUELU_TIMEMONITOR_HPP
High level timing information (use Teuchos::TimeMonitor::summarize() to print)
RCP< Teuchos::Time > timer_
static RCP< MutuallyExclusiveTime< TagName > > getNewTimer(const std::string &name)
Return a new MutuallyExclusiveTime that is registered with the Teuchos::TimeMonitor (for timer summar...
Integrates Teuchos::TimeMonitor with MueLu verbosity system.
MutuallyExclusiveTimeMonitor(const BaseClass &object, const std::string &msg, MsgType timerLevel=Timings0)
Constructor.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int GetProcRankVerbose() const
Get proc rank used for printing. Do not use this information for any other purpose.
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
VerbLevel GetVerbLevel() const
Get the verbosity level.
Similar to TimeMonitor, but uses MutuallyExclusiveTime objects.
By default, enabled timers appears in the teuchos time monitor summary. Use this option if you do not...
RCP< MutuallyExclusiveTime< TagName > > timer_
Timers that are enabled (using Timings0/Timings1) will be printed during the execution.
Base class for MueLu classes.
This class wraps a Teuchos::Time and maintains a mutually exclusive property between wrapped timers...
int SetProcRankVerbose(int procRank) const
Set proc rank used for printing.
void SetVerbLevel(const VerbLevel verbLevel)
Set the verbosity level of this object.