Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_TimerManager.cpp
Go to the documentation of this file.
1
// @HEADER
2
//
3
// ***********************************************************************
4
//
5
// Zoltan2: A package of combinatorial algorithms for scientific computing
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 Karen Devine (kddevin@sandia.gov)
39
// Erik Boman (egboman@sandia.gov)
40
// Siva Rajamanickam (srajama@sandia.gov)
41
//
42
// ***********************************************************************
43
//
44
// @HEADER
45
49
50
#include <
Zoltan2_TimerManager.hpp
>
51
52
namespace
Zoltan2
{
53
54
TimerManager::TimerManager
(
const
RCP<
const
Comm<int> > &comm,
55
std::ofstream *os,
TimerType
tt):
56
comm_(comm), myOS_(NULL), fileOS_(os), ttype_(tt),
57
typeSelector_(), timers_(), timerMap_(), stopHint_(-1)
58
{
59
if
(fileOS_ == NULL)
60
ttype_ =
NO_TIMERS
;
61
62
typeSelector_.reset();
63
typeSelector_.set(ttype_);
64
65
if
(ttype_ ==
BOTH_TIMERS
){
66
typeSelector_.set(
MACRO_TIMERS
);
67
typeSelector_.set(
MICRO_TIMERS
);
68
}
69
}
70
71
TimerManager::TimerManager
(
const
RCP<
const
Comm<int> > &comm,
72
std::ostream *os,
TimerType
tt):
73
comm_(comm), myOS_(os), fileOS_(NULL), ttype_(tt),
74
typeSelector_(), timers_(), timerMap_(), stopHint_(-1)
75
{
76
if
(myOS_ == NULL)
77
ttype_ =
NO_TIMERS
;
78
79
typeSelector_.reset();
80
typeSelector_.set(ttype_);
81
82
if
(ttype_ ==
BOTH_TIMERS
){
83
typeSelector_.set(
MACRO_TIMERS
);
84
typeSelector_.set(
MICRO_TIMERS
);
85
}
86
}
87
88
TimerManager::~TimerManager
()
89
{
90
if
(fileOS_ != NULL){
91
fileOS_->close();
92
fileOS_=NULL;
93
}
94
}
95
96
void
TimerManager::stop
(
TimerType
tt,
const
std::string &name)
97
{
98
if
(!typeSelector_[tt])
99
return
;
100
101
if
(stopHint_>0 && timers_[stopHint_]->name() == name){
102
timers_[stopHint_]->stop();
103
stopHint_--;
104
return
;
105
}
106
107
std::map<std::string, int>::iterator curr = timerMap_.find(name);
108
if
(curr != timerMap_.end()){
109
timers_[curr->second]->stop();
110
}
111
else
{
// Stopping a timer that doesn't exist. Just create it.
112
RCP<Teuchos::Time> newTimer = Teuchos::TimeMonitor::getNewTimer(name);
113
newTimer->reset();
// reset to zero
114
timerMap_[name] = timers_.size();
115
timers_.push_back(newTimer);
116
std::cerr << comm_->getRank() <<
": warning, stop with no start:"
117
<< name.c_str() << std::endl;
118
}
119
}
120
121
void
TimerManager::start
(
TimerType
tt,
const
std::string &name)
122
{
123
if
(!typeSelector_[tt])
124
return
;
125
126
std::map<std::string, int>::iterator curr = timerMap_.find(name);
127
int
index = -1;
128
if
(curr == timerMap_.end()){
129
RCP<Teuchos::Time> newTimer = Teuchos::TimeMonitor::getNewTimer(name);
130
index = timers_.size();
131
timerMap_[name] = index;
132
timers_.push_back(newTimer);
133
}
134
else
{
135
index = curr->second;
136
}
137
138
timers_[index]->start();
139
timers_[index]->incrementNumCalls();
140
stopHint_ = index;
141
}
142
143
void
TimerManager::print
()
const
144
{
145
if
(fileOS_)
146
Teuchos::TimeMonitor::summarize(comm_.ptr(), *fileOS_);
147
else
if
(myOS_)
148
Teuchos::TimeMonitor::summarize(comm_.ptr(), *myOS_);
149
}
150
151
void
TimerManager::printAndResetToZero
()
152
{
153
print
();
154
Teuchos::TimeMonitor::zeroOutTimers();
155
if
(fileOS_){
156
fileOS_->close();
157
fileOS_ = NULL;
158
}
159
}
160
161
}
// namespace Zoltan2
Zoltan2_TimerManager.hpp
Declarations for TimerManager.
Zoltan2::TimerManager::stop
void stop(TimerType tt, const std::string &name)
Stop the named timer.
Definition
Zoltan2_TimerManager.cpp:96
Zoltan2::TimerManager::print
void print() const
Print out global summary, do not reset timers.
Definition
Zoltan2_TimerManager.cpp:143
Zoltan2::TimerManager::start
void start(TimerType tt, const std::string &name)
Start the named timer.
Definition
Zoltan2_TimerManager.cpp:121
Zoltan2::TimerManager::printAndResetToZero
void printAndResetToZero()
Print out global summary of timers and reset timers to zero.
Definition
Zoltan2_TimerManager.cpp:151
Zoltan2::TimerManager::TimerManager
TimerManager(const RCP< const Comm< int > > &comm, std::ofstream *of, TimerType tt)
Constructor for output to a file.
Definition
Zoltan2_TimerManager.cpp:54
Zoltan2::TimerManager::~TimerManager
~TimerManager()
Destructor.
Definition
Zoltan2_TimerManager.cpp:88
Zoltan2
Created by mbenlioglu on Aug 31, 2020.
Definition
Zoltan2_AlgHybrid2GL.hpp:38
Zoltan2::TimerType
TimerType
The type of timers which should be active.
Definition
Zoltan2_Parameters.hpp:118
Zoltan2::NO_TIMERS
@ NO_TIMERS
No timing data will be collected (the default).
Definition
Zoltan2_Parameters.hpp:119
Zoltan2::MACRO_TIMERS
@ MACRO_TIMERS
Time an algorithm (or other entity) as a whole.
Definition
Zoltan2_Parameters.hpp:120
Zoltan2::MICRO_TIMERS
@ MICRO_TIMERS
Time the substeps of an entity.
Definition
Zoltan2_Parameters.hpp:121
Zoltan2::BOTH_TIMERS
@ BOTH_TIMERS
Run both MACRO and MICRO timers.
Definition
Zoltan2_Parameters.hpp:122
core
src
environment
Zoltan2_TimerManager.cpp
Generated by
1.17.0