Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
comm
test
StackedTimer
stacked_timer4.cpp
Go to the documentation of this file.
1
// @HEADER
2
// @HEADER
3
4
#include "
Teuchos_UnitTestHarness.hpp
"
5
#include "
Teuchos_UnitTestRepository.hpp
"
6
#include "
Teuchos_GlobalMPISession.hpp
"
7
#include "
Teuchos_PerformanceMonitorBase.hpp
"
8
#include "
Teuchos_TimeMonitor.hpp
"
9
#include "
Teuchos_StackedTimer.hpp
"
10
#include "
Teuchos_DefaultComm.hpp
"
11
#include <sstream>
12
#include <thread>
// std::this_thread::sleep_for;
13
#include <tuple>
14
#include <regex>
15
#include <iterator>
16
#include <limits>
17
18
#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
19
#include "Kokkos_Core.hpp"
20
#endif
21
22
23
TEUCHOS_UNIT_TEST
(StackedTimer, minmax_hist)
24
{
25
26
Teuchos::StackedTimer
timer(
"L0"
);
27
timer.
stopBaseTimer
();
28
29
const
Teuchos::RCP<const Teuchos::Comm<int>
> comm =
Teuchos::DefaultComm<int>::getComm
();
30
if
(comm->getSize() != 4)
31
return
;
32
const
int
myRank =
Teuchos::rank
(*comm);
33
34
if
((myRank == 1) || (myRank == 2)) {
35
timer.
start
(
"T0"
);
36
timer.
stop
(
"T0"
);
37
const_cast<
Teuchos::BaseTimer
*
>
(timer.
findBaseTimer
(
"L0@T0"
))->
setAccumulatedTime
(
Teuchos::as<double>
(myRank));
38
}
else
{
39
timer.
start
(
"T1"
);
40
timer.
stop
(
"T1"
);
41
const_cast<
Teuchos::BaseTimer
*
>
(timer.
findBaseTimer
(
"L0@T1"
))->
setAccumulatedTime
(
Teuchos::as<double>
(myRank));
42
}
43
44
Teuchos::StackedTimer::OutputOptions
options;
45
46
out <<
"\n### Printing default report ###"
<< std::endl;
47
options.
output_minmax
=
true
;
48
options.
output_proc_minmax
=
true
;
49
options.
output_histogram
=
true
;
50
options.
num_histogram
=2;
51
options.
output_fraction
=
false
;
52
timer.
report
(out, comm, options);
53
{
54
std::ostringstream os;
55
timer.
report
(os, comm, options);
56
if
(myRank == 0) {
57
TEST_ASSERT
(os.str().find(
"min=1, max=2, proc min=1, proc max=2"
) != std::string::npos);
58
TEST_ASSERT
(os.str().find(
"<1, 1>"
) != std::string::npos);
59
TEST_ASSERT
(os.str().find(
"min=0, max=3, proc min=0, proc max=3"
) != std::string::npos);
60
}
61
}
62
}
63
64
// Use our own main to initialize kokkos before calling
65
// runUnitTestsFromMain(). The kokkos space_time_stack profiler seg
66
// faults due to inconsistent push/pop of timers in the teuchos unit
67
// test startup code. By calling initialize here we can use the
68
// space_time_stack profiler with this unit test.
69
int
main
(
int
argc,
char
* argv[] )
70
{
71
// Note that the dtor for GlobalMPISession will call
72
// Kokkos::finalize().
73
Teuchos::GlobalMPISession
mpiSession(&argc, &argv);
74
#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
75
Kokkos::initialize(argc,argv);
76
#endif
77
{
78
Teuchos::FancyOStream
out(
Teuchos::rcpFromRef
(std::cout));
79
out.
setOutputToRootOnly
(0);
80
}
81
Teuchos::UnitTestRepository::setGloballyReduceTestResult
(
true
);
82
83
auto
return_val =
Teuchos::UnitTestRepository::runUnitTestsFromMain
(argc, argv);
84
#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
85
if
(Kokkos::is_initialized())
86
Kokkos::finalize();
87
#endif
88
return
return_val;
89
}
Teuchos_DefaultComm.hpp
Teuchos_GlobalMPISession.hpp
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
TEST_ASSERT
#define TEST_ASSERT(v1)
Assert the given statement is true.
Definition
Teuchos_LocalTestingHelpers.hpp:71
Teuchos_PerformanceMonitorBase.hpp
Common capabilities for collecting and reporting performance data collectively across MPI processes.
Teuchos_StackedTimer.hpp
Teuchos_TimeMonitor.hpp
Scope guard for Teuchos::Time, with MPI collective timer reporting.
Teuchos_UnitTestHarness.hpp
Unit testing support.
TEUCHOS_UNIT_TEST
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Definition
Teuchos_UnitTestHelpers.hpp:83
Teuchos_UnitTestRepository.hpp
Unit testing support.
Teuchos::BaseTimer
the basic timer used elsewhere, uses MPI_Wtime for time
Definition
Teuchos_StackedTimer.hpp:83
Teuchos::BaseTimer::setAccumulatedTime
void setAccumulatedTime(double accum=0)
Setter for accumulated time.
Definition
Teuchos_StackedTimer.hpp:116
Teuchos::Comm::rank
int rank(const Comm< Ordinal > &comm)
Get the process rank.
Definition
Teuchos_CommHelpers.hpp:1169
Teuchos::DefaultComm::getComm
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Definition
Teuchos_DefaultComm.hpp:212
Teuchos::GlobalMPISession
Initialize, finalize, and query the global MPI session.
Definition
Teuchos_GlobalMPISession.hpp:114
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
Teuchos::RCP::rcpFromRef
RCP< T > rcpFromRef(T &r)
Return a non-owning weak RCP object from a raw object reference for a defined type.
Teuchos::StackedTimer
This class allows one to push and pop timers on and off a stack.
Definition
Teuchos_StackedTimer.hpp:222
Teuchos::StackedTimer::start
void start(const std::string name, const bool push_kokkos_profiling_region=true)
Definition
Teuchos_StackedTimer.hpp:518
Teuchos::StackedTimer::stop
void stop(const std::string &name, const bool pop_kokkos_profiling_region=true)
Definition
Teuchos_StackedTimer.hpp:557
Teuchos::StackedTimer::findBaseTimer
const BaseTimer * findBaseTimer(const std::string &name) const
Definition
Teuchos_StackedTimer.hpp:640
Teuchos::StackedTimer::report
void report(std::ostream &os)
Definition
Teuchos_StackedTimer.hpp:660
Teuchos::StackedTimer::stopBaseTimer
void stopBaseTimer()
Definition
Teuchos_StackedTimer.hpp:506
Teuchos::UnitTestRepository::runUnitTestsFromMain
static int runUnitTestsFromMain(int argc, char *argv[])
Run the unit tests from main() passing in (argc, argv).
Definition
Teuchos_UnitTestRepository.cpp:409
Teuchos::UnitTestRepository::setGloballyReduceTestResult
static void setGloballyReduceTestResult(const bool globallyReduceUnitTestResult)
Set if the unit tests should reduce pass/fail across processes.
Definition
Teuchos_UnitTestRepository.cpp:215
Teuchos::basic_FancyOStream::setOutputToRootOnly
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Set the stream to print only on the (MPI) process with the given rank.
Definition
Teuchos_FancyOStream.hpp:1381
main
int main()
Definition
evilMain.cpp:75
Teuchos::as
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
Definition
Teuchos_as.hpp:2840
Teuchos::FancyOStream
basic_FancyOStream< char > FancyOStream
Definition
Teuchos_FancyOStream.hpp:845
Teuchos::StackedTimer::OutputOptions
Definition
Teuchos_StackedTimer.hpp:677
Teuchos::StackedTimer::OutputOptions::num_histogram
int num_histogram
Definition
Teuchos_StackedTimer.hpp:687
Teuchos::StackedTimer::OutputOptions::output_histogram
bool output_histogram
Definition
Teuchos_StackedTimer.hpp:684
Teuchos::StackedTimer::OutputOptions::output_fraction
bool output_fraction
Definition
Teuchos_StackedTimer.hpp:682
Teuchos::StackedTimer::OutputOptions::output_minmax
bool output_minmax
Definition
Teuchos_StackedTimer.hpp:685
Teuchos::StackedTimer::OutputOptions::output_proc_minmax
bool output_proc_minmax
Definition
Teuchos_StackedTimer.hpp:686
Generated by
1.17.0