MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_TimeMonitor.cpp
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#include "MueLu_ConfigDefs.hpp"
11#include "MueLu_TimeMonitor.hpp"
12#include "MueLu_FactoryBase.hpp"
13#include "MueLu_Level.hpp"
14
15namespace MueLu {
16
17namespace {
19std::string cleanupLabel(const std::string& label) {
20 // Our main interest is to remove double quotes from the label
21 // since tracing formats can be written in JSON/YAML
22 auto clean_label = label;
23 std::vector<std::string> bad_values = {"\""};
24 std::vector<std::string> good_values = {"'"};
25 for (size_t i = 0; i < bad_values.size(); ++i) {
26 const auto& bad_value = bad_values[i];
27 const auto& good_value = good_values[i];
28 size_t pos = 0;
29 while ((pos = clean_label.find(bad_value, pos)) != std::string::npos) {
30 clean_label.replace(pos, bad_value.size(), good_value);
31 pos += good_value.size();
32 }
33 }
34 return clean_label;
35}
36} // namespace
37
38TimeMonitor::TimeMonitor(const BaseClass& object, const std::string& msg, MsgType timerLevel) {
39 // Inherit props from 'object'
40 SetVerbLevel(object.GetVerbLevel());
42
43 if (IsPrint(timerLevel) &&
44 /* disable timer if never printed: */ (IsPrint(RuntimeTimings) || (!IsPrint(NoTimeReport)))) {
45 label_ = cleanupLabel("MueLu: " + msg);
46
47 if (!IsPrint(NoTimeReport)) {
48 timer_ = rcp(new Teuchos::TimeMonitor(*Teuchos::TimeMonitor::getNewTimer(label_)));
49 }
50 }
51} // TimeMonitor::TimeMonitor()
52
54
56
57} // namespace MueLu
Base class for MueLu classes.
RCP< Teuchos::TimeMonitor > timer_
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...