MueLu
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
MueLu_TimeMonitor.cpp
Go to the documentation of this file.
1
// @HEADER
2
//
3
// ***********************************************************************
4
//
5
// MueLu: A package for multigrid based preconditioning
6
// Copyright 2012 Sandia Corporation
7
//
8
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9
// the U.S. Government retains certain rights in this software.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact
39
// Jonathan Hu (jhu@sandia.gov)
40
// Andrey Prokopenko (aprokop@sandia.gov)
41
// Ray Tuminaro (rstumin@sandia.gov)
42
//
43
// ***********************************************************************
44
//
45
// @HEADER
46
47
#include "
MueLu_ConfigDefs.hpp
"
48
#include "
MueLu_TimeMonitor.hpp
"
49
#include "
MueLu_FactoryBase.hpp
"
50
#include "
MueLu_Level.hpp
"
51
52
namespace
MueLu
{
53
54
namespace
{
56
std::string cleanupLabel(
const
std::string& label) {
57
// Our main interest is to remove double quotes from the label
58
// since tracing formats can be written in JSON/YAML
59
auto
clean_label = label;
60
std::vector<std::string> bad_values = {
"\""
};
61
std::vector<std::string> good_values = {
"'"
};
62
for
(
size_t
i=0; i<bad_values.size(); ++i){
63
const
auto
& bad_value = bad_values[i];
64
const
auto
& good_value = good_values[i];
65
size_t
pos = 0;
66
while
( ( pos = clean_label.find( bad_value, pos ) ) != std::string::npos ){
67
clean_label.replace( pos, bad_value.size(), good_value );
68
pos += good_value.size();
69
}
70
}
71
return
clean_label;
72
}
73
}
74
75
TimeMonitor::TimeMonitor
(
const
BaseClass
&
object
,
const
std::string& msg,
MsgType
timerLevel) {
76
// Inherit props from 'object'
77
SetVerbLevel
(
object
.
GetVerbLevel
());
78
SetProcRankVerbose
(
object
.
GetProcRankVerbose
());
79
80
if
(
IsPrint
(timerLevel) &&
81
/* disable timer if never printed: */
(
IsPrint
(
RuntimeTimings
) || (!
IsPrint
(
NoTimeReport
)))) {
82
83
if
(!
IsPrint
(
NoTimeReport
)) {
84
// TODO: there is no function to register a timer in Teuchos::TimeMonitor after the creation of the timer. But would be useful...
85
timer_
= Teuchos::TimeMonitor::getNewTimer(cleanupLabel(
"MueLu: "
+ msg));
86
}
else
{
87
timer_
= rcp(
new
Teuchos::Time(cleanupLabel(
"MueLu: "
+ msg)));
88
}
89
90
// Start the timer (this is what is done by Teuchos::TimeMonitor)
91
timer_
->start();
92
timer_
->incrementNumCalls();
93
#ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
94
const
auto
stackedTimer = Teuchos::TimeMonitor::getStackedTimer();
95
if
(nonnull(stackedTimer))
96
stackedTimer->start(
timer_
->name());
97
#endif
98
}
99
}
//TimeMonitor::TimeMonitor()
100
101
TimeMonitor::TimeMonitor
() {}
102
103
TimeMonitor::~TimeMonitor
() {
104
// Stop the timer if present
105
if
(
timer_
!= Teuchos::null) {
106
timer_
->stop();
107
#ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
108
try
{
109
const
auto
stackedTimer = Teuchos::TimeMonitor::getStackedTimer();
110
if
(nonnull(stackedTimer))
111
stackedTimer->stop(
timer_
->name());
112
}
113
catch
(std::runtime_error&) {
114
std::ostringstream warning;
115
warning <<
116
"\n*********************************************************************\n"
117
"WARNING: Overlapping timers detected!\n"
118
"A TimeMonitor timer was stopped before a nested subtimer was\n"
119
"stopped. This is not allowed by the StackedTimer. This corner case\n"
120
"typically occurs if the TimeMonitor is stored in an RCP and the RCP is\n"
121
"assigned to a new timer. To disable this warning, either fix the\n"
122
"ordering of timer creation and destuction or disable the StackedTimer\n"
;
123
std::cout << warning.str() << std::endl;
124
Teuchos::TimeMonitor::setStackedTimer(Teuchos::null);
125
}
126
#endif
127
}
128
}
//TimeMonitor::~TimeMonitor()
129
130
template
class
MutuallyExclusiveTimeMonitor<FactoryBase>
;
131
template
class
MutuallyExclusiveTimeMonitor<Level>
;
132
133
}
// namespace MueLu
MueLu_ConfigDefs.hpp
MueLu_FactoryBase.hpp
MueLu_Level.hpp
MueLu_TimeMonitor.hpp
MueLu::BaseClass
Base class for MueLu classes.
Definition
MueLu_BaseClass.hpp:63
MueLu::MutuallyExclusiveTimeMonitor
Similar to TimeMonitor, but uses MutuallyExclusiveTime objects.
Definition
MueLu_TimeMonitor.hpp:91
MueLu::TimeMonitor::TimeMonitor
TimeMonitor()
Definition
MueLu_TimeMonitor.cpp:101
MueLu::TimeMonitor::~TimeMonitor
~TimeMonitor()
Definition
MueLu_TimeMonitor.cpp:103
MueLu::TimeMonitor::timer_
RCP< Teuchos::Time > timer_
Definition
MueLu_TimeMonitor.hpp:80
MueLu::VerboseObject::GetVerbLevel
VerbLevel GetVerbLevel() const
Get the verbosity level.
Definition
MueLu_VerboseObject.cpp:85
MueLu::VerboseObject::SetProcRankVerbose
int SetProcRankVerbose(int procRank) const
Set proc rank used for printing.
Definition
MueLu_VerboseObject.cpp:97
MueLu::VerboseObject::SetVerbLevel
void SetVerbLevel(const VerbLevel verbLevel)
Set the verbosity level of this object.
Definition
MueLu_VerboseObject.cpp:89
MueLu::VerboseObject::IsPrint
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
Definition
MueLu_VerboseObject.cpp:103
MueLu::VerboseObject::GetProcRankVerbose
int GetProcRankVerbose() const
Get proc rank used for printing. Do not use this information for any other purpose....
Definition
MueLu_VerboseObject.cpp:93
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:78
MueLu::MsgType
MsgType
Definition
MueLu_VerbosityLevel.hpp:54
MueLu::RuntimeTimings
@ RuntimeTimings
Timers that are enabled (using Timings0/Timings1) will be printed during the execution.
Definition
MueLu_VerbosityLevel.hpp:64
MueLu::NoTimeReport
@ NoTimeReport
By default, enabled timers appears in the teuchos time monitor summary. Use this option if you do not...
Definition
MueLu_VerbosityLevel.hpp:65
src
Utils
MueLu_TimeMonitor.cpp
Generated by
1.17.0