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
// Teuchos: Common Tools Package
4
//
5
// Copyright 2004 NTESS and the Teuchos contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#include "Teuchos_CTimeMonitor.h"
11
#include "
Teuchos_TimeMonitor.hpp
"
12
#include "Teuchos_implicit_cast.hpp"
13
#include "Teuchos_StandardCatchMacros.hpp"
14
#include "Teuchos_VerboseObject.hpp"
15
#include "Teuchos_CompilerCodeTweakMacros.hpp"
16
17
18
namespace
{
19
20
21
typedef
Teuchos::Array< Teuchos::RCP<Teuchos::Time>
> TimerArray_t;
22
TimerArray_t timerArray;
23
24
25
}
// namespace
26
27
28
int
Teuchos_startTimer(
char
timerName[],
int
timerID )
29
{
30
using
Teuchos::implicit_cast
;
31
bool
success =
true
;
32
try
{
33
if
( timerID < 0 ) {
34
// The timer does not exist so create it!
35
timerArray.push_back(
Teuchos::TimeMonitor::getNewCounter
(timerName));
36
timerArray.back()->start();
37
return
timerArray.size()-1;
38
}
39
// Else, the timer already exists so return it
40
TEUCHOS_TEST_FOR_EXCEPTION
(
41
timerID >= implicit_cast<int>(timerArray.size()), std::logic_error,
42
"Teuchos_startTimer(...): Error, timerID="
<<timerID
43
<<
" is >= timerArray.size()="
<<timerArray.size()
44
<<
" for timerName=\""
<<timerName<<
"\"!"
45
);
46
Teuchos::RCP<Teuchos::Time>
timer = timerArray[timerID];
47
TEUCHOS_TEST_FOR_EXCEPTION
(
48
timer->isRunning(), std::logic_error,
49
"Teuchos_startTimer(...): Error, timerID="
<<timerID
50
<<
", timerName=\""
<<timerName<<
"\" is already running!"
51
);
52
timer->start();
53
}
54
TEUCHOS_STANDARD_CATCH_STATEMENTS
(
true
,
55
*
Teuchos::VerboseObjectBase::getDefaultOStream
(), success);
56
if
(!success) {
57
return
-1;
58
}
59
return
timerID;
60
}
61
62
63
void
Teuchos_stopTimer(
int
timerID )
64
{
65
using
Teuchos::implicit_cast
;
66
bool
success =
true
;
67
try
{
68
TEUCHOS_TEST_FOR_EXCEPTION
(
69
timerID < 0 || timerID >= implicit_cast<int>(timerArray.size()),
70
std::logic_error,
71
"Teuchos_stopTimer(...): Error, timerID="
<<timerID<<
" is invalid!"
72
);
73
Teuchos::RCP<Teuchos::Time>
timer = timerArray[timerID];
74
timer->stop();
75
// Increment the number of times the timer has been used (start to stop).
76
timer->incrementNumCalls();
77
}
78
TEUCHOS_STANDARD_CATCH_STATEMENTS
(
true
,
79
*
Teuchos::VerboseObjectBase::getDefaultOStream
(), success);
80
if
(!success) {}
// Avoid warnings
81
}
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:163
Teuchos::PerformanceMonitorBase< Time >::getNewCounter
static RCP< Time > getNewCounter(const std::string &name)
Definition
Teuchos_PerformanceMonitorBase.hpp:303
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:397
Teuchos::VerboseObjectBase::getDefaultOStream
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
Definition
Teuchos_VerboseObject.cpp:45
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:146
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:49
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:104
Generated by
1.17.0