| [788bdd2] | 1 | #include "XSbench_header.h"
|
|---|
| 2 |
|
|---|
| 3 | void counter_init( int *eventset, int *num_papi_events )
|
|---|
| 4 | {
|
|---|
| 5 | char error_str[PAPI_MAX_STR_LEN];
|
|---|
| 6 | // int events[] = {PAPI_TOT_INS,PAPI_BR_INS,PAPI_SR_INS};
|
|---|
| 7 | int events[] = {PAPI_TOT_CYC,PAPI_L3_TCM};
|
|---|
| 8 | int stat;
|
|---|
| 9 |
|
|---|
| 10 | int thread = omp_get_thread_num();
|
|---|
| 11 | if( thread == 0 )
|
|---|
| 12 | printf("Initializing PAPI counters...\n");
|
|---|
| 13 |
|
|---|
| 14 | *num_papi_events = sizeof(events) / sizeof(int);
|
|---|
| 15 |
|
|---|
| 16 | if ((stat = PAPI_thread_init((long unsigned int (*)(void)) omp_get_thread_num)) != PAPI_OK){
|
|---|
| 17 | PAPI_perror("PAPI_thread_init");
|
|---|
| 18 | exit(1);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | if ( (stat= PAPI_create_eventset(eventset)) != PAPI_OK){
|
|---|
| 22 | PAPI_perror("PAPI_create_eventset");
|
|---|
| 23 | exit(1);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | for( int i = 0; i < *num_papi_events; i++ ){
|
|---|
| 27 | if ((stat=PAPI_add_event(*eventset,events[i])) != PAPI_OK){
|
|---|
| 28 | PAPI_perror("PAPI_add_event");
|
|---|
| 29 | exit(1);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | if ((stat=PAPI_start(*eventset)) != PAPI_OK){
|
|---|
| 34 | PAPI_perror("PAPI_start");
|
|---|
| 35 | exit(1);
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | // Stops the papi counters and prints results
|
|---|
| 40 | void counter_stop( int * eventset, int num_papi_events )
|
|---|
| 41 | {
|
|---|
| 42 | int * events = malloc(num_papi_events * sizeof(int));
|
|---|
| 43 | int n = num_papi_events;
|
|---|
| 44 | PAPI_list_events( *eventset, events, &n );
|
|---|
| 45 | PAPI_event_info_t info;
|
|---|
| 46 |
|
|---|
| 47 | long_long * values = malloc( num_papi_events * sizeof(long_long));
|
|---|
| 48 | PAPI_stop(*eventset, values);
|
|---|
| 49 | int thread = omp_get_thread_num();
|
|---|
| 50 |
|
|---|
| 51 | #pragma omp critical (papi)
|
|---|
| 52 | {
|
|---|
| 53 | printf("Thread %d\n", thread);
|
|---|
| 54 | for( int i = 0; i < num_papi_events; i++ )
|
|---|
| 55 | {
|
|---|
| 56 | PAPI_get_event_info(events[i], &info);
|
|---|
| 57 | printf("%-15lld\t%s\t%s\n", values[i],info.symbol,info.long_descr);
|
|---|
| 58 | }
|
|---|
| 59 | free(events);
|
|---|
| 60 | free(values);
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|