XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
timer_macro.hpp
Go to the documentation of this file.
1 #ifndef TIMER_MACRO_HPP
2 #define TIMER_MACRO_HPP
3 
4 #ifdef CAM_TIMERS
5 #include "gptl.h"
6 #else
7 // If camtimers is not present, use this spoofed version of the timers
8 static int GPTLinitialize(){ return 0;}
9 static int GPTLstart(const char* name){ return 0;}
10 static int GPTLstop(const char* name){ return 0;}
11 static int GPTLpr_file(const char* name){ return 0;}
12 #endif
13 
14 // Since it's a common name, make sure it isn't already used somewhere
15 #ifdef TIMER
16 #error "TIMER macro already defined"
17 #endif
18 
19 // Debug flag: adds an MPI barrier with checkpoint before and after each timer
20 #include "checkpoint.hpp"
21 #define TIMER_CHKPT_START(N) if(global_debug_flag) checkpoint(std::string("Starting '") + N + std::string("'...\n"));
22 #define TIMER_CHKPT_END(N) if(global_debug_flag) checkpoint(std::string("Finished '") + N + std::string("'!\n"));
23 
24 #define TIMER(N,F) {TIMER_CHKPT_START(N); GPTLstart(N); F; GPTLstop(N); TIMER_CHKPT_END(N);}
25 // e.g.: TIMER(push(), "Push");
26 // becomes:
27 // {
28 // GPTLstart("Push");
29 // push();
30 // GPTLstop("Push");
31 // }
32 // The braces are there for safe scoping, but that means you can't time declarations.
33 
34 // Here is a macro for timing Kokkos kernels from regression tests. This includes
35 // a call to Kokkos::fence() to time the full kernel, not just the launch.
36 
37 #ifdef FENCED_TIMER
38 #error "FENCED_TIMER macro already defined"
39 #endif
40 
41 #define FENCED_TIMER(N,F) {TIMER_CHKPT_START(N); GPTLstart(N); F; Kokkos::fence(); GPTLstop(N); TIMER_CHKPT_END(N);}
42 // e.g.: FENCED_TIMER(push(), "Push");
43 // becomes:
44 // {
45 // GPTLstart("Push");
46 // push();
47 // Kokkos::fence();
48 // GPTLstop("Push");
49 // }
50 
51 // Here is an non-scoped version:
52 
53 #ifdef TIMER_NS
54 #error "TIMER_NS macro already defined"
55 #endif
56 
57 #define TIMER_NS(N,F) TIMER_CHKPT_START(N); GPTLstart(N); F; GPTLstop(N); TIMER_CHKPT_END(N);
58 
59 
60 #endif
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
static int GPTLinitialize()
Definition: timer_macro.hpp:8
static int GPTLpr_file(const char *name)
Definition: timer_macro.hpp:11
static int GPTLstop(const char *name)
Definition: timer_macro.hpp:10