MueLu Version of the Day
Loading...
Searching...
No Matches
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"
21#ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
22#include "Teuchos_StackedTimer.hpp"
23#include <sstream>
24#endif
25
26namespace MueLu {
27
32class TimeMonitor : public BaseClass {
33 public:
34 TimeMonitor(const BaseClass& object, const std::string& msg, MsgType timerLevel = Timings0);
35
37
38 protected:
40
41 private:
42 RCP<Teuchos::Time> timer_;
43}; // class TimeMonitor
44
45// TODO: code duplication MutuallyExclusiveTimeMonitor / TimeMonitor
46
52template <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
93extern template class MutuallyExclusiveTimeMonitor<Level>;
94
95} // namespace MueLu
96
97#endif // MUELU_TIMEMONITOR_HPP
Base class for MueLu classes.
Similar to TimeMonitor, but uses MutuallyExclusiveTime objects.
RCP< MutuallyExclusiveTime< TagName > > timer_
MutuallyExclusiveTimeMonitor(const BaseClass &object, const std::string &msg, MsgType timerLevel=Timings0)
Constructor.
This class wraps a Teuchos::Time and maintains a mutually exclusive property between wrapped timers.
static RCP< MutuallyExclusiveTime< TagName > > getNewTimer(const std::string &name)
Return a new MutuallyExclusiveTime that is registered with the Teuchos::TimeMonitor (for timer summar...
RCP< Teuchos::Time > timer_
TimeMonitor(const BaseClass &object, const std::string &msg, MsgType timerLevel=Timings0)
VerbLevel GetVerbLevel() const
Get the verbosity level.
int SetProcRankVerbose(int procRank) const
Set proc rank used for printing.
void SetVerbLevel(const VerbLevel verbLevel)
Set the verbosity level of this object.
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
int GetProcRankVerbose() const
Get proc rank used for printing. Do not use this information for any other purpose....
Namespace for MueLu classes and methods.
@ RuntimeTimings
Timers that are enabled (using Timings0/Timings1) will be printed during the execution.
@ NoTimeReport
By default, enabled timers appears in the teuchos time monitor summary. Use this option if you do not...
@ Timings0
High level timing information (use Teuchos::TimeMonitor::summarize() to print).