PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mendes-alt.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include "papi_test.h"
5 
6 #ifdef SETMAX
7 #define MAX SETMAX
8 #else
9 #define MAX 10000
10 #endif
11 #define TIMES 1000
12 
13 #define PAPI_MAX_EVENTS 2
17 static int EventSet = PAPI_NULL;
18 
19 extern int TESTS_QUIET; /* Declared in test_utils.c */
20 
21 int
22 main( argc, argv )
24 char *argv[];
25 {
26  int i, retval;
27  double a[MAX], b[MAX];
28  void funcX( ), funcA( );
29 
30  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
31 
32  for ( i = 0; i < MAX; i++ ) {
33  a[i] = 0.0;
34  b[i] = 0.;
35  }
36 
37  for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
38  PAPI_values1[i] = PAPI_values2[i] = 0;
39 
41  if ( retval != PAPI_VER_CURRENT )
42  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
43 
44 #ifdef MULTIPLEX
45  if ( !TESTS_QUIET ) {
46  printf( "Activating PAPI Multiplex\n" );
47  }
48  init_multiplex( );
49 #endif
50 
51  retval = PAPI_create_eventset( &EventSet );
52  if ( retval != PAPI_OK )
53  test_fail( __FILE__, __LINE__, "PAPI set event fail\n", retval );
54 
55 #ifdef MULTIPLEX
56  /* In Component PAPI, EventSets must be assigned a component index
57  before you can fiddle with their internals.
58  0 is always the cpu component */
60  if ( retval != PAPI_OK )
61  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
62  retval );
63 
64  retval = PAPI_set_multiplex( EventSet );
65  if (retval == PAPI_ENOSUPP) {
66  test_skip( __FILE__, __LINE__, "Multiplex not supported", 1 );
67  }
68  else if ( retval != PAPI_OK )
69  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex fails \n", retval );
70 #endif
71 
72  retval = PAPI_add_event( EventSet, PAPI_FP_INS );
73  if ( retval < PAPI_OK ) {
75  if ( retval < PAPI_OK )
76  test_fail( __FILE__, __LINE__,
77  "PAPI add PAPI_FP_INS or PAPI_TOT_INS fail\n", retval );
78  else if ( !TESTS_QUIET ) {
79  printf( "PAPI_TOT_INS\n" );
80  }
81  } else if ( !TESTS_QUIET ) {
82  printf( "PAPI_FP_INS\n" );
83  }
84 
86  if ( retval < PAPI_OK )
87  test_fail( __FILE__, __LINE__, "PAPI add PAPI_TOT_CYC fail\n",
88  retval );
89  if ( !TESTS_QUIET ) {
90  printf( "PAPI_TOT_CYC\n" );
91  }
92 
93  retval = PAPI_start( EventSet );
94  if ( retval != PAPI_OK )
95  test_fail( __FILE__, __LINE__, "PAPI start fail\n", retval );
96 
97  funcX( a, b, MAX );
98 
99  retval = PAPI_read( EventSet, PAPI_values1 );
100  if ( retval != PAPI_OK )
101  test_fail( __FILE__, __LINE__, "PAPI read fail \n", retval );
102 
103  funcX( a, b, MAX );
104 
105  retval = PAPI_read( EventSet, PAPI_values2 );
106  if ( retval != PAPI_OK )
107  test_fail( __FILE__, __LINE__, "PAPI read fail \n", retval );
108 
109 #ifdef RESET
110  retval = PAPI_reset( EventSet );
111  if ( retval != PAPI_OK )
112  test_fail( __FILE__, __LINE__, "PAPI read fail \n", retval );
113 #endif
114 
115  funcA( a, b, MAX );
116 
117  retval = PAPI_stop( EventSet, PAPI_values3 );
118  if ( retval != PAPI_OK )
119  test_fail( __FILE__, __LINE__, "PAPI read fail \n", retval );
120 
121  if ( !TESTS_QUIET ) {
122  printf( "values1 is:\n" );
123  for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
125 
126  printf( "\nvalues2 is:\n" );
127  for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
129  printf( "\nvalues3 is:\n" );
130  for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
132 
133 #ifndef RESET
134  printf( "\nPAPI value (2-1) is : \n" );
135  for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
137  printf( "\nPAPI value (3-2) is : \n" );
138  for ( i = 0; i < PAPI_MAX_EVENTS; i++ ) {
139  long long diff;
140  diff = PAPI_values3[i] - PAPI_values2[i];
141  printf( LLDFMT15, diff);
142  if (diff<0) {
143  test_fail( __FILE__, __LINE__, "Multiplexed counter decreased", 1 );
144  }
145  }
146 #endif
147 
148  printf( "\n\nVerification:\n" );
149  printf( "From start to first PAPI_read %d fp operations are made.\n",
150  2 * MAX * TIMES );
151  printf( "Between 1st and 2nd PAPI_read %d fp operations are made.\n",
152  2 * MAX * TIMES );
153  printf( "Between 2nd and 3rd PAPI_read %d fp operations are made.\n",
154  0 );
155  printf( "\n" );
156  }
157  test_pass( __FILE__, NULL, 0 );
158  exit( 1 );
159 }
160 
161 void
162 funcX( a, b, n )
163 double a[MAX], b[MAX];
164 int n;
165 {
166  int i, k;
167  for ( k = 0; k < TIMES; k++ )
168  for ( i = 0; i < n; i++ )
169  a[i] = a[i] * b[i] + 1.;
170 }
171 
172 void
173 funcA( a, b, n )
174 double a[MAX], b[MAX];
175 int n;
176 {
177  int i, k;
178  double t[MAX];
179  for ( k = 0; k < TIMES; k++ )
180  for ( i = 0; i < n; i++ ) {
181  t[i] = b[n - i];
182  b[i] = a[n - i];
183  a[i] = t[i];
184  }
185 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
void funcA()
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
int PAPI_reset(int EventSet)
Definition: papi.c:2403
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_ENOSUPP
Definition: papi.h:269
#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)
#define printf
Definition: papi_test.h:125
void init_multiplex(void)
Definition: test_utils.c:892
static double
Definition: fileop.c:1281
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
t
Definition: iozone.c:23562
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
void funcX()
#define PAPI_MAX_EVENTS
Definition: mendes-alt.c:13
int k
Definition: iozone.c:19136
long long PAPI_values3[PAPI_MAX_EVENTS]
Definition: mendes-alt.c:16
long long PAPI_values1[PAPI_MAX_EVENTS]
Definition: mendes-alt.c:14
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1485
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
long long PAPI_values2[PAPI_MAX_EVENTS]
Definition: mendes-alt.c:15
#define TIMES
Definition: mendes-alt.c:11
#define MAX
Definition: mendes-alt.c:9
int
Definition: iozone.c:18528
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3277
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2503
#define LLDFMT15
Definition: papi_test.h:121
int PAPI_start(int EventSet)
Definition: papi.c:2053
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()
#define PAPI_FP_INS
int n
Definition: mendes-alt.c:164