Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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>
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 
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);
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 }
Time an algorithm (or other entity) as a whole.
static ArrayRCP< ArrayRCP< zscalar_t > > weights
static void sleep_wrap(unsigned int seconds)
int main(int narg, char **arg)
Definition: coloring1.cpp:164
common code used by tests
Time the substeps of an entity.
void goToSleep(const RCP< const Zoltan2::Environment > &env)
Run both MACRO and MICRO timers.
This class represents a collection of global Identifiers and their associated weights, if any.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > myTypes_t
Defines the BasicIdentifierAdapter class.
PartitioningProblem sets up partitioning problems for the user.
Defines the PartitioningProblem class.
Declarations for TimerManager.