Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
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
10
//
11
// Testing the TimerManager class.
12
// TODO we only test that it doesn't crash.
13
14
#include <
Zoltan2_TestHelpers.hpp
>
15
#include <
Zoltan2_PartitioningProblem.hpp
>
16
#include <
Zoltan2_BasicIdentifierAdapter.hpp
>
17
#include <
Zoltan2_TimerManager.hpp
>
18
19
#include <Teuchos_DefaultComm.hpp>
20
21
#ifdef _MSC_VER
22
#define NOMINMAX
23
#include <windows.h>
24
#else
25
#include <unistd.h>
26
#endif
27
28
29
using
Zoltan2::TimerManager
;
30
using
Zoltan2::MACRO_TIMERS
;
31
using
Zoltan2::MICRO_TIMERS
;
32
using
Zoltan2::BOTH_TIMERS
;
33
34
35
static
void
sleep_wrap
(
unsigned
int
seconds)
36
{
37
#ifdef _MSC_VER
38
Sleep(1000*seconds);
39
#else
40
sleep(seconds);
41
#endif
42
}
43
44
void
goToSleep
(
const
RCP<const Zoltan2::Environment> &env)
45
{
46
env->timerStart(
MICRO_TIMERS
,
string
(
"sleep for 5 seconds"
));
47
sleep_wrap
(5);
48
env->timerStop(
MICRO_TIMERS
,
string
(
"sleep for 5 seconds"
));
49
50
env->timerStart(
MICRO_TIMERS
,
string
(
"sleep for 3 seconds (twice)"
));
51
sleep_wrap
(3);
52
env->timerStop(
MICRO_TIMERS
,
string
(
"sleep for 3 seconds (twice)"
));
53
54
env->timerStart(
MICRO_TIMERS
,
string
(
"sleep for 2 seconds"
));
55
sleep_wrap
(2);
56
env->timerStop(
MICRO_TIMERS
,
string
(
"sleep for 2 seconds"
));
57
58
env->timerStart(
MICRO_TIMERS
,
string
(
"sleep for 3 seconds (twice)"
));
59
sleep_wrap
(3);
60
env->timerStop(
MICRO_TIMERS
,
string
(
"sleep for 3 seconds (twice)"
));
61
}
62
63
64
int
main
(
int
narg,
char
*arg[])
65
{
66
Tpetra::ScopeGuard tscope(&narg, &arg);
67
Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
68
69
// Create a problem, requesting that Timing be enabled.
70
71
Teuchos::ParameterList pl(
"test list"
);
72
pl.set(
"timer_output_stream"
,
"std::cout"
);
73
pl.set(
"timer_type"
,
"both_timers"
);
74
std::vector<const zscalar_t * >
weights
;
75
std::vector<int> strides;
76
Array<zgno_t> someIds(10,1);
77
typedef
Zoltan2::BasicUserTypes<zscalar_t, zlno_t, zgno_t>
myTypes_t
;
78
typedef
Zoltan2::BasicIdentifierAdapter<myTypes_t>
inputAdapter_t;
79
inputAdapter_t ia(10, someIds.getRawPtr(),
weights
, strides);
80
81
Zoltan2::PartitioningProblem<inputAdapter_t>
problem(&ia, &pl, comm);
82
83
// Use the timers through the environment.
84
85
const
RCP<const Zoltan2::Environment> &env = problem.
getEnvironment
();
86
87
if
(comm->getRank() == 0)
88
std::cout <<
"Sleeping..."
<< std::endl;
89
90
env->timerStart(
MACRO_TIMERS
,
string
(
"Do the sleep test"
));
91
goToSleep
(env);
92
env->timerStop(
MACRO_TIMERS
,
string
(
"Do the sleep test"
));
93
94
comm->barrier();
95
96
// Should show an error
97
env->timerStop(
MACRO_TIMERS
,
string
(
"unstarted timer"
));
98
99
problem.
printTimers
();
100
101
if
(comm->getRank() == 0)
102
std::cout <<
"PASS"
<< std::endl;
103
}
MACRO_TIMERS
@ MACRO_TIMERS
Time an algorithm (or other entity) as a whole.
Definition
Zoltan2_Parameters.hpp:90
MICRO_TIMERS
@ MICRO_TIMERS
Time the substeps of an entity.
Definition
Zoltan2_Parameters.hpp:91
goToSleep
void goToSleep(const RCP< const Zoltan2::Environment > &env)
Definition
TimerManager.cpp:44
sleep_wrap
static void sleep_wrap(unsigned int seconds)
Definition
TimerManager.cpp:35
Zoltan2_BasicIdentifierAdapter.hpp
Defines the BasicIdentifierAdapter class.
myTypes_t
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > myTypes_t
Definition
Zoltan2_MeshCoordinateTest.hpp:31
Zoltan2_PartitioningProblem.hpp
Defines the PartitioningProblem class.
Zoltan2_TestHelpers.hpp
common code used by tests
Zoltan2_TimerManager.hpp
Declarations for TimerManager.
main
int main()
Definition
absdefinitiontest.cpp:15
Zoltan2::BasicIdentifierAdapter
This class represents a collection of global Identifiers and their associated weights,...
Definition
Zoltan2_BasicIdentifierAdapter.hpp:46
Zoltan2::BasicUserTypes
A simple class that can be the User template argument for an InputAdapter.
Definition
Zoltan2_InputTraits.hpp:103
Zoltan2::PartitioningProblem
PartitioningProblem sets up partitioning problems for the user.
Definition
Zoltan2_PartitioningProblem.hpp:69
Zoltan2::Problem::getEnvironment
const RCP< const Environment > & getEnvironment() const
Get the current Environment. Useful for testing.
Definition
Zoltan2_Problem.hpp:142
Zoltan2::Problem::printTimers
void printTimers() const
Return the communicator passed to the problem.
Definition
Zoltan2_Problem.hpp:99
Zoltan2::TimerManager
Definition
Zoltan2_TimerManager.hpp:28
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
weights
static ArrayRCP< ArrayRCP< zscalar_t > > weights
Definition
partition/rcbPerformanceZ1.cpp:46
test
core
unit
environment
TimerManager.cpp
Generated by
1.17.0