Commit 49ec202c authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

Cleanup of error handling in papi.c

parent 39b5ebdb
......@@ -37,8 +37,8 @@ static int cycle_available = 0;
#include <papi.h>
#define papi_try(x, on_error) if ((ret = x) < 0) { \
fprintf(stderr, "ftimings: %s:%d: PAPI_library_init(%d): %s\n", \
__FILE__, __LINE__, PAPI_VER_CURRENT, PAPI_strerror(ret)); \
fprintf(stderr, "ftimings: %s:%d: " #x ": %s\n", \
__FILE__, __LINE__, PAPI_strerror(ret)); \
on_error; \
}
......@@ -67,56 +67,28 @@ static int papi_init(void) {
event_set = PAPI_NULL;
if ((ret = PAPI_library_init(PAPI_VER_CURRENT)) < 0) {
fprintf(stderr, "ftimings: %s:%d: PAPI_library_init(%d): %s\n",
__FILE__, __LINE__, PAPI_VER_CURRENT, PAPI_strerror(ret));
papi_available = 0;
break;
}
papi_try(PAPI_library_init(PAPI_VER_CURRENT), papi_available = 0; break)
papi_try(PAPI_thread_init(pthread_self), papi_available = 0; break)
if ((ret = PAPI_create_eventset(&event_set)) < 0) {
fprintf(stderr, "ftimings: %s:%d PAPI_create_eventset(): %s\n",
__FILE__, __LINE__, PAPI_strerror(ret));
papi_available = 0;
break;
}
papi_try(PAPI_create_eventset(&event_set), papi_available = 0; break)
/* FLOP counter
*/
if ((ret = PAPI_query_event(PAPI_DP_OPS)) < 0) {
fprintf(stderr, "ftimings: %s:%d: PAPI_query_event(PAPI_DP_INS): %s\n",
__FILE__, __LINE__, PAPI_strerror(ret));
flop_available = 0;
} else if ((ret = PAPI_add_event(event_set, PAPI_DP_OPS)) < 0) {
fprintf(stderr, "ftimings: %s:%d PAPI_add_event(): %s\n",
__FILE__, __LINE__, PAPI_strerror(ret));
flop_available = 0;
} else {
papi_try(PAPI_query_event(PAPI_DP_OPS), flop_available = 0)
else papi_try(PAPI_add_event(event_set, PAPI_DP_OPS), flop_available = 0)
else {
flop_available = 1;
}
/* Cycle counter
*/
if ((ret = PAPI_query_event(PAPI_TOT_CYC)) < 0) {
fprintf(stderr, "ftimings: %s:%d: PAPI_query_event(PAPI_TOT_CYC): %s\n",
__FILE__, __LINE__, PAPI_strerror(ret));
cycle_available = 0;
} else if ((ret = PAPI_add_event(event_set, PAPI_TOT_CYC)) < 0) {
fprintf(stderr, "ftimings: %s:%d PAPI_add_event(): %s\n",
__FILE__, __LINE__, PAPI_strerror(ret));
cycle_available = 0;
} else {
papi_try(PAPI_query_event(PAPI_TOT_CYC), cycle_available = 0)
else papi_try(PAPI_add_event(event_set, PAPI_TOT_CYC), cycle_available = 0)
else {
cycle_available = 1;
}
/* Start */
if ((ret = PAPI_start(event_set)) < 0) {
fprintf(stderr, "ftimings: %s:%d PAPI_start(): %s\n",
__FILE__, __LINE__, PAPI_strerror(ret));
papi_available = 0;
break;
}
papi_try(PAPI_start(event_set), papi_available = 0; papi_uninit(); break)
/* PAPI works */
papi_available = 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment