PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
case1.c
Go to the documentation of this file.
1 /* From Dave McNamara at PSRV. Thanks! */
2 
3 /* If you try to add an event that doesn't exist, you get the correct error
4 message, yet you get subsequent Seg. Faults when you try to do PAPI_start and
5 PAPI_stop. I would expect some bizarre behavior if I had no events added to the
6 event set and then tried to PAPI_start but if I had successfully added one
7 event, then the 2nd one get an error when I tried to add it, is it possible for
8 PAPI_start to work but just count the first event?
9 */
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 
14 #include "papi.h"
15 #include "papi_test.h"
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 i, j = 0;
25  long long g1[2];
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 
34  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
35  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
36 
38  j++;
39 
40  if ( j == 1 &&
41  ( retval = PAPI_add_event( EventSet, PAPI_L2_TCM ) ) != PAPI_OK ) {
42  if ( retval != PAPI_ECNFLCT )
43  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
44  j--; /* The event was not added */
45  }
46 
47  i = j;
49  j++;
50 
51  if ( j == ( i + 1 ) &&
52  ( retval = PAPI_add_event( EventSet, PAPI_L2_DCM ) ) != PAPI_OK ) {
53  if ( retval != PAPI_ECNFLCT )
54  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
55  j--; /* The event was not added */
56  }
57 
58  if ( j ) {
59  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
60  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
61  for ( i = 0; i < n; i++ ) {
62  c = a * b;
63  }
64  if (!TESTS_QUIET) fprintf(stdout,"c=%lf\n",c);
65 
66  if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
67  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
68  }
69 
70  test_pass( __FILE__ );
71 
72  return 0;
73 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_L2_TCM
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
#define PAPI_NULL
Definition: papi.h:292
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
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
#define PAPI_ECNFLCT
Definition: papi.h:261
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define PAPI_L2_DCM
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