QMCPACK
NewTimer.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 //
11 // File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 /** @file NewTimer.cpp
16  * @brief Implements NewTimer member functions
17  */
18 #include "NewTimer.h"
19 #include <iostream>
20 #include "Concurrency/OpenMP.h"
21 #include "config.h"
22 #include "TimerManager.h"
23 
24 namespace qmcplusplus
25 {
27 
28 #ifndef ENABLE_TIMERS
29 template<class CLOCK>
31 {}
32 template<class CLOCK>
34 {}
35 #else
36 template<class CLOCK>
38 {
39  if (active)
40  {
41 #ifdef USE_STACK_TIMERS
42 
43 #ifdef USE_VTUNE_TASKS
44  __itt_id parent_task = __itt_null;
45  __itt_task_begin(manager->task_domain, __itt_null, parent_task, task_name);
46 #endif
47 
48 #ifdef USE_NVTX_API
49  nvtxRangePushA(name.c_str());
50 #endif
51 
52  bool is_true_master(true);
53  for (int level = omp_get_level(); level > 0; level--)
54  if (omp_get_ancestor_thread_num(level) != 0)
55  is_true_master = false;
56  if (is_true_master)
57  {
58  if (manager)
59  {
60  // compute current_stack_key
61  TimerType* parent = manager->current_timer();
62  if (parent)
63  {
64  current_stack_key = parent->get_stack_key();
65  current_stack_key.add_id(timer_id);
66  }
67  else
68  {
69  current_stack_key = StackKey();
70  current_stack_key.add_id(timer_id);
71  }
72 
73  manager->push_timer(this);
74  }
75  start_time = CLOCK::now();
76  }
77 #else
78  start_time = CLOCK::now();
79 #endif
80  }
81 }
82 
83 template<class CLOCK>
85 {
86  if (active)
87  {
88 #ifdef USE_STACK_TIMERS
89 
90 #ifdef USE_VTUNE_TASKS
91  __itt_task_end(manager->task_domain);
92 #endif
93 
94 #ifdef USE_NVTX_API
95  nvtxRangePop();
96 #endif
97 
98  bool is_true_master(true);
99  for (int level = omp_get_level(); level > 0; level--)
100  if (omp_get_ancestor_thread_num(level) != 0)
101  is_true_master = false;
102  if (is_true_master)
103  {
104  std::chrono::duration<double> elapsed = CLOCK::now() - start_time;
105  total_time += elapsed.count();
106  num_calls++;
107 
108  per_stack_total_time[current_stack_key] += elapsed.count();
109  per_stack_num_calls[current_stack_key] += 1;
110 
111  if (manager)
112  manager->pop_timer(this);
113  }
114 #else
115  std::chrono::duration<double> elapsed = CLOCK::now() - start_time;
116  total_time += elapsed.count();
117  num_calls++;
118 #endif
119  }
120 }
121 #endif
122 
123 template<class CLOCK>
125 {
126  if (timer_level <= threshold)
127  active = true;
128  else
129  active = false;
130 }
131 
132 template class TimerType<ChronoClock>;
133 template class TimerType<FakeChronoClock>;
134 
135 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
timer_manager class.
void set_active_by_timer_threshold(const timer_levels threshold)
Definition: NewTimer.cpp:124
Timer accumulates time and call counts.
Definition: NewTimer.h:135
StackKey & get_stack_key()
Definition: NewTimer.h:174
omp_int_t omp_get_ancestor_thread_num(int level)
Definition: OpenMP.h:29
void add_id(timer_id_t c1)
Definition: NewTimer.h:88
bool timer_max_level_exceeded
Definition: NewTimer.cpp:26
omp_int_t omp_get_level()
Definition: OpenMP.h:28
StackKeyParam< 2 > StackKey
Definition: NewTimer.h:129
NewTimer class various high-resolution timers.