PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
case2.c
Go to the documentation of this file.
1 /* From Dave McNamara at PSRV. Thanks! */
2 
3 /* If an event is countable but you've exhausted the counter resources
4 and you try to add an event, it seems subsequent PAPI_start and/or
5 PAPI_stop will causes a Seg. Violation.
6 
7  I got around this by calling PAPI to get the # of countable events,
8 then making sure that I didn't try to add more than these number of
9 events. I still have a problem if someone adds Level 2 cache misses
10 and then adds FLOPS 'cause I didn't count FLOPS as actually requiring
11 2 counters. */
12 
13 #include "papi_test.h"
14 
15 extern int TESTS_QUIET; /* Declared in test_utils.c */
16 
17 int
18 main( int argc, char **argv )
19 {
20  double c, a = 0.999, b = 1.001;
21  int n = 1000;
22  int EventSet = PAPI_NULL;
23  int retval;
24  int j = 0, i;
25  long long g1[3];
26 
27  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
28 
29  if ( ( retval =
31  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
32 
33  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
34  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
35 
37  j++;
38 
39  if ( j == 1 &&
40  ( retval = PAPI_add_event( EventSet, PAPI_BR_CN ) ) != PAPI_OK ) {
41  if ( retval != PAPI_ECNFLCT )
42  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
43  }
44 
45  i = j;
47  j++;
48 
49  if ( j == ( i + 1 ) &&
50  ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK ) {
51  if ( retval != PAPI_ECNFLCT )
52  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
53  }
54 
55  i = j;
57  j++;
58 
59  if ( j == ( i + 1 ) &&
60  ( retval = PAPI_add_event( EventSet, PAPI_TOT_INS ) ) != PAPI_OK ) {
61  if ( retval != PAPI_ECNFLCT )
62  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
63  }
64 
65  if ( j ) {
66  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
67  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
68 
69  for ( i = 0; i < n; i++ ) {
70  c = a * b;
71  }
72  if (!TESTS_QUIET) fprintf(stdout,"c=%lf\n",c);
73  if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
74  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
75  }
76  test_pass( __FILE__, NULL, 0 );
77  exit( 1 );
78 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
double c
Definition: multiplex.c:22
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
#define PAPI_BR_CN
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
int i
Definition: fileop.c:140
#define PAPI_TOT_CYC
#define PAPI_ECNFLCT
Definition: papi.h:259
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_query_event(int EventCode)
Definition: papi.c:698
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
int PAPI_start(int EventSet)
Definition: papi.c:2053
long j
Definition: iozone.c:19135
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int n
Definition: mendes-alt.c:164