fix warnings
[pluto.git] / examples / fdtd-1d / papi_defs.h
blob4ea38505a7cbefa65e2fb43bf64478c1585df798
1 #ifdef PERFCTR
3 #define PERF_INIT \
4 int err, EventSet = PAPI_NULL; \
5 int papi_events[2] = {PAPI_L1_DCM, PAPI_L2_TCM}; \
6 long long CtrValues[4]; \
8 /* --- SETUP --- Configure PAPI events ------------------ */ \
9 printf("Initializing PAPI Hardware Performance Counters:\n"); \
10 err = PAPI_library_init(PAPI_VER_CURRENT); \
11 if (err != PAPI_VER_CURRENT) { \
12 fprintf(stderr, "Error initializing PAPI: Version mismatch. Expected %d, got %d\n", PAPI_VER_CURRENT, err); \
13 perror("System error (mostly a perfctr device permission problem)\n"); \
14 exit(1); \
15 } \
17 /* Create Event Set */ \
18 if (PAPI_create_eventset(&EventSet) != PAPI_OK) { \
19 printf("Failed to create PAPI Event Set\n"); \
20 exit(1); \
21 } \
23 /* Add Total Instructions Executed to our EventSet */ \
24 if (PAPI_query_event(PAPI_L1_DCM) == PAPI_OK) { \
25 printf(" * PAPI will count L1 misses\n"); \
26 err = PAPI_add_event(EventSet, papi_events[0]); \
27 } \
28 if (err != PAPI_OK) { \
29 printf("Failed to add PAPI event\n"); \
30 exit(1); \
31 } \
32 if (PAPI_query_event(PAPI_L2_TCM) == PAPI_OK) { \
33 printf(" * PAPI will count L2 misses\n"); \
34 err = PAPI_add_event(EventSet, papi_events[1]); \
35 } \
36 if (err != PAPI_OK) { \
37 printf("Failed to add PAPI event\n"); \
38 exit(1); \
39 } \
40 PAPI_start(EventSet);
42 #define PERF_EXIT \
43 PAPI_stop(EventSet, &CtrValues[0]); \
44 printf("L1 D cache misses: %ld\n", CtrValues[0]); \
45 printf("L2 (total) cache misses: %ld\n", CtrValues[1]);
46 #endif