PAPI  5.6.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 <stdio.h>
14 #include <stdlib.h>
15 
16 #include "papi.h"
17 #include "papi_test.h"
18 
19 int
20 main( int argc, char **argv )
21 {
22  double c, a = 0.999, b = 1.001;
23  int n = 1000;
24  int EventSet = PAPI_NULL;
25  int retval;
26  int j = 0, i;
27  long long g1[3];
28 
29  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
30 
31  if ( ( retval =
33  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
34 
35  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
36  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
37 
39  j++;
40 
41  if ( j == 1 &&
42  ( retval = PAPI_add_event( EventSet, PAPI_BR_CN ) ) != PAPI_OK ) {
43  if ( retval != PAPI_ECNFLCT )
44  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
45  }
46 
47  i = j;
49  j++;
50 
51  if ( j == ( i + 1 ) &&
52  ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK ) {
53  if ( retval != PAPI_ECNFLCT )
54  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
55  }
56 
57  i = j;
59  j++;
60 
61  if ( j == ( i + 1 ) &&
62  ( retval = PAPI_add_event( EventSet, PAPI_TOT_INS ) ) != PAPI_OK ) {
63  if ( retval != PAPI_ECNFLCT )
64  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
65  }
66 
67  if ( j ) {
68  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
69  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
70 
71  for ( i = 0; i < n; i++ ) {
72  c = a * b;
73  }
74  if (!TESTS_QUIET) fprintf(stdout,"c=%lf\n",c);
75  if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
76  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
77  }
78 
79  test_pass( __FILE__ );
80 
81  return 0;
82 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
#define PAPI_NULL
Definition: papi.h:292
#define PAPI_TOT_INS
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
double c
Definition: multiplex.c:22
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
char ** argv
Definition: iozone.c:1610
#define PAPI_BR_CN
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
#define PAPI_TOT_CYC
#define PAPI_ECNFLCT
Definition: papi.h:261
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_query_event(int EventCode)
Definition: papi.c:684
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_start(int EventSet)
Definition: papi.c:2096
long j
Definition: iozone.c:19135
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38