Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_TimerManager.cpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Zoltan2: A package of combinatorial algorithms for scientific computing
4
//
5
// Copyright 2012 NTESS and the Zoltan2 contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
13
14
#include <
Zoltan2_TimerManager.hpp
>
15
16
namespace
Zoltan2
{
17
18
TimerManager::TimerManager
(
const
RCP<
const
Comm<int> > &comm,
19
std::ofstream *os,
TimerType
tt):
20
comm_(comm), myOS_(NULL), fileOS_(os), ttype_(tt),
21
typeSelector_(), timers_(), timerMap_(), stopHint_(-1)
22
{
23
if
(fileOS_ == NULL)
24
ttype_ =
NO_TIMERS
;
25
26
typeSelector_.reset();
27
typeSelector_.set(ttype_);
28
29
if
(ttype_ ==
BOTH_TIMERS
){
30
typeSelector_.set(
MACRO_TIMERS
);
31
typeSelector_.set(
MICRO_TIMERS
);
32
}
33
}
34
35
TimerManager::TimerManager
(
const
RCP<
const
Comm<int> > &comm,
36
std::ostream *os,
TimerType
tt):
37
comm_(comm), myOS_(os), fileOS_(NULL), ttype_(tt),
38
typeSelector_(), timers_(), timerMap_(), stopHint_(-1)
39
{
40
if
(myOS_ == NULL)
41
ttype_ =
NO_TIMERS
;
42
43
typeSelector_.reset();
44
typeSelector_.set(ttype_);
45
46
if
(ttype_ ==
BOTH_TIMERS
){
47
typeSelector_.set(
MACRO_TIMERS
);
48
typeSelector_.set(
MICRO_TIMERS
);
49
}
50
}
51
52
TimerManager::~TimerManager
()
53
{
54
if
(fileOS_ != NULL){
55
fileOS_->close();
56
fileOS_=NULL;
57
}
58
}
59
60
void
TimerManager::stop
(
TimerType
tt,
const
std::string &name)
61
{
62
if
(!typeSelector_[tt])
63
return
;
64
65
if
(stopHint_>0 && timers_[stopHint_]->name() == name){
66
timers_[stopHint_]->stop();
67
stopHint_--;
68
return
;
69
}
70
71
std::map<std::string, int>::iterator curr = timerMap_.find(name);
72
if
(curr != timerMap_.end()){
73
timers_[curr->second]->stop();
74
}
75
else
{
// Stopping a timer that doesn't exist. Just create it.
76
RCP<Teuchos::Time> newTimer = Teuchos::TimeMonitor::getNewTimer(name);
77
newTimer->reset();
// reset to zero
78
timerMap_[name] = timers_.size();
79
timers_.push_back(newTimer);
80
std::cerr << comm_->getRank() <<
": warning, stop with no start:"
81
<< name.c_str() << std::endl;
82
}
83
}
84
85
void
TimerManager::start
(
TimerType
tt,
const
std::string &name)
86
{
87
if
(!typeSelector_[tt])
88
return
;
89
90
std::map<std::string, int>::iterator curr = timerMap_.find(name);
91
int
index = -1;
92
if
(curr == timerMap_.end()){
93
RCP<Teuchos::Time> newTimer = Teuchos::TimeMonitor::getNewTimer(name);
94
index = timers_.size();
95
timerMap_[name] = index;
96
timers_.push_back(newTimer);
97
}
98
else
{
99
index = curr->second;
100
}
101
102
timers_[index]->start();
103
timers_[index]->incrementNumCalls();
104
stopHint_ = index;
105
}
106
107
void
TimerManager::print
()
const
108
{
109
if
(fileOS_)
110
Teuchos::TimeMonitor::summarize(comm_.ptr(), *fileOS_);
111
else
if
(myOS_)
112
Teuchos::TimeMonitor::summarize(comm_.ptr(), *myOS_);
113
}
114
115
void
TimerManager::printAndResetToZero
()
116
{
117
print
();
118
Teuchos::TimeMonitor::zeroOutTimers();
119
if
(fileOS_){
120
fileOS_->close();
121
fileOS_ = NULL;
122
}
123
}
124
125
}
// 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:60
Zoltan2::TimerManager::print
void print() const
Print out global summary, do not reset timers.
Definition
Zoltan2_TimerManager.cpp:107
Zoltan2::TimerManager::start
void start(TimerType tt, const std::string &name)
Start the named timer.
Definition
Zoltan2_TimerManager.cpp:85
Zoltan2::TimerManager::printAndResetToZero
void printAndResetToZero()
Print out global summary of timers and reset timers to zero.
Definition
Zoltan2_TimerManager.cpp:115
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:18
Zoltan2::TimerManager::~TimerManager
~TimerManager()
Destructor.
Definition
Zoltan2_TimerManager.cpp:52
Zoltan2
Created by mbenlioglu on Aug 31, 2020.
Definition
Zoltan2_AlgHybrid2GL.hpp:47
Zoltan2::TimerType
TimerType
The type of timers which should be active.
Definition
Zoltan2_Parameters.hpp:88
Zoltan2::NO_TIMERS
@ NO_TIMERS
No timing data will be collected (the default).
Definition
Zoltan2_Parameters.hpp:89
Zoltan2::MACRO_TIMERS
@ MACRO_TIMERS
Time an algorithm (or other entity) as a whole.
Definition
Zoltan2_Parameters.hpp:90
Zoltan2::MICRO_TIMERS
@ MICRO_TIMERS
Time the substeps of an entity.
Definition
Zoltan2_Parameters.hpp:91
Zoltan2::BOTH_TIMERS
@ BOTH_TIMERS
Run both MACRO and MICRO timers.
Definition
Zoltan2_Parameters.hpp:92
core
src
environment
Zoltan2_TimerManager.cpp
Generated by
1.17.0