Zoltan2
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
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
33
34
35static void sleep_wrap(unsigned int seconds)
36{
37#ifdef _MSC_VER
38 Sleep(1000*seconds);
39#else
40 sleep(seconds);
41#endif
42}
43
44void 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
64int 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);
78 typedef Zoltan2::BasicIdentifierAdapter<myTypes_t> inputAdapter_t;
79 inputAdapter_t ia(10, someIds.getRawPtr(), weights, strides);
80
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}
void goToSleep(const RCP< const Zoltan2::Environment > &env)
static void sleep_wrap(unsigned int seconds)
Defines the BasicIdentifierAdapter class.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > myTypes_t
Defines the PartitioningProblem class.
common code used by tests
Declarations for TimerManager.
int main()
This class represents a collection of global Identifiers and their associated weights,...
A simple class that can be the User template argument for an InputAdapter.
PartitioningProblem sets up partitioning problems for the user.
const RCP< const Environment > & getEnvironment() const
Get the current Environment. Useful for testing.
void printTimers() const
Return the communicator passed to the problem.
@ 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.
static ArrayRCP< ArrayRCP< zscalar_t > > weights