PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
reset_multiplex.c
Go to the documentation of this file.
1 /* This file performs the same tests as the reset test
2  but does it with the events multiplexed.
3 
4  This is mostly to test perf_event, where resetting
5  multiplexed events is handled differently than grouped events.
6 
7 */
8 
9 #include "papi_test.h"
10 
11 int
12 main( int argc, char **argv )
13 {
14  int retval, num_tests = 9, num_events, tmp, i;
15  long long **values;
16  int EventSet = PAPI_NULL;
17  int PAPI_event, mask;
18  char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
19 
20  /* Set TESTS_QUIET variable */
21  tests_quiet( argc, argv );
22 
23  /* Init the PAPI library */
25  if ( retval != PAPI_VER_CURRENT ) {
26  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
27  }
28 
29  retval = PAPI_multiplex_init( );
30  if ( retval == PAPI_ENOSUPP) {
31  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
32  }
33  else if ( retval != PAPI_OK ) {
34  test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval );
35  }
36 
37 
38  /* add PAPI_TOT_CYC and one of the events in
39  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
40  depending on the availability of the event
41  on the platform */
42  EventSet = add_two_events( &num_events, &PAPI_event, &mask );
43 
44  /* Set multiplexing on the eventset */
45 
46  retval = PAPI_set_multiplex( EventSet );
47  if ( retval != PAPI_OK) {
48  test_fail(__FILE__, __LINE__, "Setting multiplex", retval);
49  }
50 
51  retval = PAPI_event_code_to_name( PAPI_event, event_name );
52  if ( retval != PAPI_OK ) {
53  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
54  }
55  sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
56 
57  values = allocate_test_space( num_tests, num_events );
58 
59  /*===== Test 1: Start/Stop =======================*/
60 
61  retval = PAPI_start( EventSet );
62  if ( retval != PAPI_OK ) {
63  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
64  }
65 
67 
68  retval = PAPI_stop( EventSet, values[0] );
69  if ( retval != PAPI_OK ) {
70  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
71  }
72 
73  /*===== Test 2 Start/Stop =======================*/
74 
75  retval = PAPI_start( EventSet );
76  if ( retval != PAPI_OK ) {
77  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
78  }
79 
81 
82  retval = PAPI_stop( EventSet, values[1] );
83  if ( retval != PAPI_OK ) {
84  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
85  }
86 
87  /*===== Test 3: Reset/Start/Stop =======================*/
88 
89  retval = PAPI_reset( EventSet );
90  if ( retval != PAPI_OK ) {
91  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
92  }
93 
94  retval = PAPI_start( EventSet );
95  if ( retval != PAPI_OK ) {
96  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
97  }
98 
100 
101  retval = PAPI_stop( EventSet, values[2] );
102  if ( retval != PAPI_OK ) {
103  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
104  }
105 
106  /*===== Test 4: Start/Read =======================*/
107 
108  retval = PAPI_start( EventSet );
109  if ( retval != PAPI_OK ) {
110  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
111  }
112 
113  do_flops( NUM_FLOPS / 2 );
114 
115  retval = PAPI_read( EventSet, values[3] );
116  if ( retval != PAPI_OK ) {
117  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
118  }
119 
120  /*===== Test 5: Read =======================*/
121 
122  do_flops( NUM_FLOPS / 2 );
123 
124  retval = PAPI_read( EventSet, values[4] );
125  if ( retval != PAPI_OK ) {
126  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
127  }
128 
129  /*===== Test 6: Read/Accum =======================*/
130 
131  do_flops( NUM_FLOPS / 2 );
132 
133  retval = PAPI_read( EventSet, values[5] );
134  if ( retval != PAPI_OK ) {
135  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
136  }
137 
138  retval = PAPI_accum( EventSet, values[5] );
139 
140  if ( retval != PAPI_OK ) {
141  test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
142  }
143 
144  /*===== Test 7: Read =======================*/
145 
146  do_flops( NUM_FLOPS / 2 );
147 
148  retval = PAPI_read( EventSet, values[6] );
149  if ( retval != PAPI_OK ) {
150  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
151  }
152 
153  /*===== Test 8 Reset/Stop =======================*/
154  retval = PAPI_reset( EventSet );
155  if ( retval != PAPI_OK ) {
156  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
157  }
158 
159  do_flops( NUM_FLOPS / 2 );
160 
161  retval = PAPI_stop( EventSet, values[7] );
162  if ( retval != PAPI_OK ) {
163  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
164  }
165 
166  /*===== Test 9: Reset/Read =======================*/
167  retval = PAPI_reset( EventSet );
168  if ( retval != PAPI_OK ) {
169  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
170  }
171 
172  retval = PAPI_read( EventSet, values[8] );
173  if ( retval != PAPI_OK ) {
174  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
175  }
176 
177  remove_test_events( &EventSet, mask );
178 
179  printf( "Test case: Start/Stop/Read/Accum/Reset.\n" );
180  printf( "----------------------------------------------------------------\n" );
181  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
182  printf( "Default domain is: %d (%s)\n", tmp,
183  stringify_all_domains( tmp ) );
184  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
185  printf( "Default granularity is: %d (%s)\n", tmp,
186  stringify_granularity( tmp ) );
187  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
188  printf( "-------------------------------------------------------------------------\n" );
189 
190  sprintf( add_event_str, "%s:", event_name );
191  printf( " PAPI_TOT_CYC %s\n", event_name );
192  printf( "1. start,ops,stop %10lld %10lld\n", values[0][0],
193  values[0][1] );
194  printf( "2. start,ops,stop %10lld %10lld\n", values[1][0],
195  values[1][1] );
196  printf( "3. reset,start,ops,stop %10lld %10lld\n", values[2][0],
197  values[2][1] );
198  printf( "4. start,ops/2,read %10lld %10lld\n", values[3][0],
199  values[3][1] );
200  printf( "5. ops/2,read %10lld %10lld\n", values[4][0],
201  values[4][1] );
202  printf( "6. ops/2,accum %10lld %10lld\n", values[5][0],
203  values[5][1] );
204  printf( "7. ops/2,read %10lld %10lld\n", values[6][0],
205  values[6][1] );
206  printf( "8. reset,ops/2,stop %10lld %10lld\n", values[7][0],
207  values[7][1] );
208  printf( "9. reset,read %10lld %10lld\n", values[8][0],
209  values[8][1] );
210  printf
211  ( "-------------------------------------------------------------------------\n" );
212  printf( "Verification:\n" );
213  printf( "Row 1 approximately equals rows 2 and 3 \n" );
214  printf( "Row 4 approximately equals 1/2 of row 3\n" );
215  printf( "Row 5 approximately equals twice row 4\n" );
216  printf( "Row 6 approximately equals 6 times row 4\n" );
217  printf( "Rows 7 and 8 approximately equal row 4\n" );
218  printf( "Row 9 equals 0\n" );
219  printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC",
220  100.0 * ( float ) values[0][0] / ( float ) values[1][0] );
221  printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str,
222  100.0 * ( float ) values[0][1] / ( float ) values[1][1] );
223 
224 
225  for ( i = 0; i <= 1; i++ ) {
226  if ( !approx_equals
227  ( ( double ) values[0][i], ( double ) values[1][i] ) )
228  test_fail( __FILE__, __LINE__,
229  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
230  if ( !approx_equals
231  ( ( double ) values[1][i], ( double ) values[2][i] ) )
232  test_fail( __FILE__, __LINE__,
233  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
234  if ( !approx_equals
235  ( ( double ) values[2][i], ( double ) values[3][i] * 2.0 ) )
236  test_fail( __FILE__, __LINE__,
237  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
238  if ( !approx_equals
239  ( ( double ) values[2][i], ( double ) values[4][i] ) )
240  test_fail( __FILE__, __LINE__,
241  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
242  if ( !approx_equals
243  ( ( double ) values[5][i], ( double ) values[3][i] * 6.0 ) )
244  test_fail( __FILE__, __LINE__,
245  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
246  if ( !approx_equals
247  ( ( double ) values[6][i], ( double ) values[3][i] ) )
248  test_fail( __FILE__, __LINE__,
249  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
250  if ( !approx_equals
251  ( ( double ) values[7][i], ( double ) values[3][i] ) )
252  test_fail( __FILE__, __LINE__,
253  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
254  if ( values[8][i] != 0LL )
255  test_fail( __FILE__, __LINE__,
256  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
257  }
258 
259  test_pass( __FILE__, values, num_tests );
260  return 0;
261 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
int PAPI_event[2]
Definition: data_range.c:24
int PAPI_reset(int EventSet)
Definition: papi.c:2403
char * stringify_granularity(int granularity)
Definition: test_utils.c:429
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
int num_events
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2689
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
int i
Definition: fileop.c:140
char * stringify_all_domains(int domains)
Definition: test_utils.c:369
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:680
#define PAPI_DEFGRN
Definition: papi.h:432
int approx_equals(double a, double b)
Definition: test_utils.c:94
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_multiplex_init(void)
Definition: papi.c:2926
#define PAPI_DEFDOM
Definition: papi.h:430
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3277
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2503
int PAPI_start(int EventSet)
Definition: papi.c:2053
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277