source: CIVL/examples/xsbench/src/papi.c@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[788bdd2]1#include "XSbench_header.h"
2
3void 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
40void 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}
Note: See TracBrowser for help on using the repository browser.