GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
timing.h
Go to the documentation of this file.
1 
6 #ifndef GHOST_TIMING_H
7 #define GHOST_TIMING_H
8 
9 #include <float.h>
10 
11 #include "error.h"
12 
13 #ifndef MIN
14 #define MIN(x,y) ((x)<(y)?(x):(y))
15 #endif
16 #ifndef MAX
17 #define MAX(x,y) ((x)<(y)?(y):(x))
18 #endif
19 
29 #define GHOST_TIME(nIter,func,...) \
30  double func ## _start, func ## _end, func ## _tstart, func ## _tend;\
31 double func ## _tmin = DBL_MAX;\
32 double func ## _tmax = 0.;\
33 double func ## _tavg = 0.;\
34 int func ## _it;\
35 ghost_timing_wc(&func ## _tstart);\
36 for (func ## _it=0; func ## _it<nIter; func ## _it++) {\
37  ghost_timing_wc(&func ## _start);\
38  func(__VA_ARGS__);\
39  ghost_timing_wc(&func ## _end);\
40  func ## _tmin = MIN(func ## _end-func ## _start,func ## _tmin);\
41  func ## _tmax = MAX(func ## _end-func ## _start,func ## _tmax);\
42 }\
43 ghost_timing_wc(&func ## _tend);\
44 func ## _tavg = (func ## _tend - func ## _tstart)/((double)nIter);\
45 
46 typedef int (*ghost_compute_performance_func)(double *perf, double time, void *arg);
47 
51 typedef struct
52 {
56  int nCalls;
60  double *times;
64  double avgTime;
68  double minTime;
72  double maxTime;
76  double accTime;
80  double skip10avgTime;
81 
82 }
84 
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 
94  void ghost_timing_tick(const char *tag);
100  void ghost_timing_tock(const char *tag);
117  ghost_error ghost_timing_region_create(ghost_timing_region ** region, const char *tag);
124 
132  ghost_error ghost_timing_wc(double *time);
140  ghost_error ghost_timing_wcmilli(double *time);
141 
152  void ghost_timing_set_perfFunc(const char *prefix, const char *tag, ghost_compute_performance_func func, void *arg, size_t sizeofarg, const char *unit);
153 
157  void ghost_timing_destroy();
158 
160  ghost_error ghost_timing_elapsed(double *time);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 #endif
void ghost_timing_tick(const char *tag)
Save the start time for a region.
Definition: timing.cpp:53
ghost_error ghost_timing_summarystring(char **str)
Summarize all timed regions into a string.
Definition: timing.cpp:177
ghost_error ghost_timing_start()
Definition: timing.c:10
ghost_error ghost_timing_wc(double *time)
Get the wallclock time in seconds.
Definition: timing.c:25
Types, functions and macros for error handling.
ghost_error
Error return type.
Definition: error.h:23
int(* ghost_compute_performance_func)(double *perf, double time, void *arg)
Definition: timing.h:46
double skip10avgTime
The average time omitting the first ten calls (useful for benchmarking).
Definition: timing.h:80
double maxTime
The maximum runtime.
Definition: timing.h:72
double avgTime
The average runtime of each call.
Definition: timing.h:64
ghost_error ghost_timing_region_create(ghost_timing_region **region, const char *tag)
Obtain timing info about a specific region.
Definition: timing.cpp:111
double minTime
The minimum runtime.
Definition: timing.h:68
double * times
The runtime of each call. (length: nCalls)
Definition: timing.h:60
void ghost_timing_tock(const char *tag)
Save the runtime for a region using the start time from ghost_timing_tick().
Definition: timing.cpp:64
void ghost_timing_set_perfFunc(const char *prefix, const char *tag, ghost_compute_performance_func func, void *arg, size_t sizeofarg, const char *unit)
Set a performance computation function to a given tag.
Definition: timing.cpp:74
ghost_error ghost_timing_wcmilli(double *time)
Get the wallclock time in milliseconds.
Definition: timing.c:39
void ghost_timing_region_destroy(ghost_timing_region *region)
Destroy a timing region.
Definition: timing.cpp:149
Information about a timed region.
Definition: timing.h:51
ghost_error ghost_timing_elapsed(double *time)
Definition: timing.c:15
void ghost_timing_destroy()
Free timing data structures.
Definition: timing.cpp:161
int nCalls
The number of times the region has been called.
Definition: timing.h:56
double accTime
The accumulated runtime.
Definition: timing.h:76