Zoltan2
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
15
16namespace Zoltan2{
17
18TimerManager::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
35TimerManager::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
53{
54 if (fileOS_ != NULL){
55 fileOS_->close();
56 fileOS_=NULL;
57 }
58}
59
60void 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
85void 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
108{
109 if (fileOS_)
110 Teuchos::TimeMonitor::summarize(comm_.ptr(), *fileOS_);
111 else if (myOS_)
112 Teuchos::TimeMonitor::summarize(comm_.ptr(), *myOS_);
113}
114
116{
117 print();
118 Teuchos::TimeMonitor::zeroOutTimers();
119 if (fileOS_){
120 fileOS_->close();
121 fileOS_ = NULL;
122 }
123}
124
125} // namespace Zoltan2
Declarations for TimerManager.
void stop(TimerType tt, const std::string &name)
Stop the named timer.
void print() const
Print out global summary, do not reset timers.
void start(TimerType tt, const std::string &name)
Start the named timer.
void printAndResetToZero()
Print out global summary of timers and reset timers to zero.
TimerManager(const RCP< const Comm< int > > &comm, std::ofstream *of, TimerType tt)
Constructor for output to a file.
Created by mbenlioglu on Aug 31, 2020.
TimerType
The type of timers which should be active.
@ NO_TIMERS
No timing data will be collected (the default).
@ MACRO_TIMERS
Time an algorithm (or other entity) as a whole.
@ MICRO_TIMERS
Time the substeps of an entity.
@ BOTH_TIMERS
Run both MACRO and MICRO timers.