Teuchos - Trilinos Tools Package
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
comm
src
Teuchos_CTimeMonitor.cpp
1
// @HEADER
2
// ***********************************************************************
3
//
4
// Teuchos: Common Tools Package
5
// Copyright (2004) Sandia Corporation
6
//
7
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8
// license for use of this work by or on behalf of the U.S. Government.
9
//
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are
12
// met:
13
//
14
// 1. Redistributions of source code must retain the above copyright
15
// notice, this list of conditions and the following disclaimer.
16
//
17
// 2. Redistributions in binary form must reproduce the above copyright
18
// notice, this list of conditions and the following disclaimer in the
19
// documentation and/or other materials provided with the distribution.
20
//
21
// 3. Neither the name of the Corporation nor the names of the
22
// contributors may be used to endorse or promote products derived from
23
// this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38
//
39
// ***********************************************************************
40
// @HEADER
41
42
#include "Teuchos_CTimeMonitor.h"
43
#include "
Teuchos_TimeMonitor.hpp
"
44
#include "Teuchos_implicit_cast.hpp"
45
#include "Teuchos_StandardCatchMacros.hpp"
46
#include "Teuchos_VerboseObject.hpp"
47
#include "Teuchos_CompilerCodeTweakMacros.hpp"
48
49
50
namespace
{
51
52
53
typedef
Teuchos::Array< Teuchos::RCP<Teuchos::Time>
> TimerArray_t;
54
TimerArray_t timerArray;
55
56
57
}
// namespace
58
59
60
int
Teuchos_startTimer(
char
timerName[],
int
timerID )
61
{
62
using
Teuchos::implicit_cast
;
63
bool
success =
true
;
64
try
{
65
if
( timerID < 0 ) {
66
// The timer does not exist so create it!
67
timerArray.push_back(
Teuchos::TimeMonitor::getNewCounter
(timerName));
68
timerArray.back()->start();
69
return
timerArray.size()-1;
70
}
71
// Else, the timer already exists so return it
72
TEUCHOS_TEST_FOR_EXCEPTION
(
73
timerID >= implicit_cast<int>(timerArray.size()), std::logic_error,
74
"Teuchos_startTimer(...): Error, timerID="
<<timerID
75
<<
" is >= timerArray.size()="
<<timerArray.size()
76
<<
" for timerName=\""
<<timerName<<
"\"!"
77
);
78
Teuchos::RCP<Teuchos::Time>
timer = timerArray[timerID];
79
TEUCHOS_TEST_FOR_EXCEPTION
(
80
timer->isRunning(), std::logic_error,
81
"Teuchos_startTimer(...): Error, timerID="
<<timerID
82
<<
", timerName=\""
<<timerName<<
"\" is already running!"
83
);
84
timer->start();
85
}
86
TEUCHOS_STANDARD_CATCH_STATEMENTS
(
true
,
87
*
Teuchos::VerboseObjectBase::getDefaultOStream
(), success);
88
if
(!success) {
89
return
-1;
90
}
91
return
timerID;
92
}
93
94
95
void
Teuchos_stopTimer(
int
timerID )
96
{
97
using
Teuchos::implicit_cast
;
98
bool
success =
true
;
99
try
{
100
TEUCHOS_TEST_FOR_EXCEPTION
(
101
timerID < 0 || timerID >= implicit_cast<int>(timerArray.size()),
102
std::logic_error,
103
"Teuchos_stopTimer(...): Error, timerID="
<<timerID<<
" is invalid!"
104
);
105
Teuchos::RCP<Teuchos::Time>
timer = timerArray[timerID];
106
timer->stop();
107
// Increment the number of times the timer has been used (start to stop).
108
timer->incrementNumCalls();
109
}
110
TEUCHOS_STANDARD_CATCH_STATEMENTS
(
true
,
111
*
Teuchos::VerboseObjectBase::getDefaultOStream
(), success);
112
if
(!success) {}
// Avoid warnings
113
}
Teuchos_TimeMonitor.hpp
Scope guard for Teuchos::Time, with MPI collective timer reporting.
Teuchos::Array
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
Definition
Teuchos_Array.hpp:195
Teuchos::PerformanceMonitorBase< Time >::getNewCounter
static RCP< Time > getNewCounter(const std::string &name)
Definition
Teuchos_PerformanceMonitorBase.hpp:333
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
Teuchos::VerboseObjectBase::getDefaultOStream
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
Definition
Teuchos_VerboseObject.cpp:77
TEUCHOS_TEST_FOR_EXCEPTION
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Definition
Teuchos_TestForException.hpp:178
Teuchos::implicit_cast
TypeTo implicit_cast(const TypeFrom &t)
Perform an implicit cast of concrete types with the casted object returned by value.
Definition
Teuchos_implicit_cast.hpp:81
TEUCHOS_STANDARD_CATCH_STATEMENTS
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
Definition
Teuchos_StandardCatchMacros.hpp:136
Generated by
1.17.0