PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
reset.c
Go to the documentation of this file.
1 /* This file performs the following test: start, read, stop and again functionality
2 
3  - It attempts to use the following three counters. It may use less depending on
4  hardware counter resource limitations. These are counted in the default counting
5  domain and default granularity, depending on the platform. Usually this is
6  the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR).
7  + PAPI_FP_INS or PAPI_TOT_INS if PAPI_FP_INS doesn't exist
8  + PAPI_TOT_CYC
9 
10  1
11  - Start counters
12  - Do flops
13  - Stop counters
14 
15  2
16  - Start counters
17  - Do flops
18  - Stop counters (should duplicate above)
19 
20  3
21  - Reset counters (should be redundant if stop works properly)
22  - Start counters
23  - Do flops
24  - Stop counters
25 
26  4
27  - Start counters
28  - Do flops/2
29  - Read counters (flops/2;counters keep counting)
30 
31  5
32  - Do flops/2
33  - Read counters (2flops/2; counters keep counting)
34 
35  6
36  - Do flops/2
37  - Read counters (3*flops/2; counters keep counting)
38  - Accum counters (2*(3*flops.2); counters clear and counting)
39 
40  7
41  - Do flops/2
42  - Read counters (flops/2; counters keep counting)
43 
44  8
45  - Reset (counters set to zero; still counting)
46  - Stop counters (flops/2; counters stopped)
47 
48  9
49  - Reset (counters set to zero; still counting)
50  - Do flops/2
51  - Stop counters (flops/2; counters stopped)
52 
53  9
54  - Reset (counters set to zero and stopped)
55  - Read counters (should be zero)
56 */
57 
58 #include <stdio.h>
59 
60 #include "papi.h"
61 #include "papi_test.h"
62 
63 #include "do_loops.h"
64 
65 int
66 main( int argc, char **argv )
67 {
68  int retval, num_tests = 9, num_events, tmp, i;
69  long long **values;
70  int EventSet = PAPI_NULL;
71  int PAPI_event, mask;
72  char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
73  int quiet;
74 
75  /* Set TESTS_QUIET variable */
76  quiet = tests_quiet( argc, argv );
77 
78  /* Init the PAPI library */
80  if ( retval != PAPI_VER_CURRENT ) {
81  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
82  }
83 
84  /* add PAPI_TOT_CYC and one of the events in
85  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
86  depending on the availability of the event
87  on the platform */
88  EventSet = add_two_events( &num_events, &PAPI_event, &mask );
89 
90  retval = PAPI_event_code_to_name( PAPI_event, event_name );
91  if ( retval != PAPI_OK ) {
92  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
93  }
94  sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
95 
96  values = allocate_test_space( num_tests, num_events );
97 
98  /*===== Test 1: Start/Stop =======================*/
99 
100  retval = PAPI_start( EventSet );
101  if ( retval != PAPI_OK ) {
102  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
103  }
104 
105  do_flops( NUM_FLOPS );
106 
107  retval = PAPI_stop( EventSet, values[0] );
108  if ( retval != PAPI_OK ) {
109  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
110  }
111 
112  /*===== Test 2 Start/Stop =======================*/
113 
114  retval = PAPI_start( EventSet );
115  if ( retval != PAPI_OK ) {
116  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
117  }
118 
119  do_flops( NUM_FLOPS );
120 
121  retval = PAPI_stop( EventSet, values[1] );
122  if ( retval != PAPI_OK ) {
123  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
124  }
125 
126  /*===== Test 3: Reset/Start/Stop =======================*/
127 
128  retval = PAPI_reset( EventSet );
129  if ( retval != PAPI_OK ) {
130  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
131  }
132 
133  retval = PAPI_start( EventSet );
134  if ( retval != PAPI_OK ) {
135  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
136  }
137 
138  do_flops( NUM_FLOPS );
139 
140  retval = PAPI_stop( EventSet, values[2] );
141  if ( retval != PAPI_OK ) {
142  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
143  }
144 
145  /*===== Test 4: Start/Read =======================*/
146 
147  retval = PAPI_start( EventSet );
148  if ( retval != PAPI_OK ) {
149  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
150  }
151 
152  do_flops( NUM_FLOPS / 2 );
153 
154  retval = PAPI_read( EventSet, values[3] );
155  if ( retval != PAPI_OK ) {
156  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
157  }
158 
159  /*===== Test 5: Read =======================*/
160 
161  do_flops( NUM_FLOPS / 2 );
162 
163  retval = PAPI_read( EventSet, values[4] );
164  if ( retval != PAPI_OK ) {
165  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
166  }
167 
168  /*===== Test 6: Read/Accum =======================*/
169 
170  do_flops( NUM_FLOPS / 2 );
171 
172  retval = PAPI_read( EventSet, values[5] );
173  if ( retval != PAPI_OK ) {
174  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
175  }
176 
177  retval = PAPI_accum( EventSet, values[5] );
178 
179  if ( retval != PAPI_OK ) {
180  test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
181  }
182 
183  /*===== Test 7: Read =======================*/
184 
185  do_flops( NUM_FLOPS / 2 );
186 
187  retval = PAPI_read( EventSet, values[6] );
188  if ( retval != PAPI_OK ) {
189  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
190  }
191 
192  /*===== Test 8 Reset/Stop =======================*/
193  retval = PAPI_reset( EventSet );
194  if ( retval != PAPI_OK ) {
195  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
196  }
197 
198  do_flops( NUM_FLOPS / 2 );
199 
200  retval = PAPI_stop( EventSet, values[7] );
201  if ( retval != PAPI_OK ) {
202  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
203  }
204 
205  /*===== Test 9: Reset/Read =======================*/
206  retval = PAPI_reset( EventSet );
207  if ( retval != PAPI_OK ) {
208  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
209  }
210 
211  retval = PAPI_read( EventSet, values[8] );
212  if ( retval != PAPI_OK ) {
213  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
214  }
215 
216  remove_test_events( &EventSet, mask );
217 
218  if (!quiet) {
219  printf( "Test case: Start/Stop/Read/Accum/Reset.\n" );
220  printf( "----------------------------------------------------------------\n" );
221  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
222  printf( "Default domain is: %d (%s)\n", tmp,
223  stringify_all_domains( tmp ) );
224  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
225  printf( "Default granularity is: %d (%s)\n", tmp,
226  stringify_granularity( tmp ) );
227  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
228  printf( "-------------------------------------------------------------------------\n" );
229 
230  sprintf( add_event_str, "%s:", event_name );
231  printf( " PAPI_TOT_CYC %s\n", event_name );
232  printf( "1. start,ops,stop %10lld %10lld\n", values[0][0],
233  values[0][1] );
234  printf( "2. start,ops,stop %10lld %10lld\n", values[1][0],
235  values[1][1] );
236  printf( "3. reset,start,ops,stop %10lld %10lld\n", values[2][0],
237  values[2][1] );
238  printf( "4. start,ops/2,read %10lld %10lld\n", values[3][0],
239  values[3][1] );
240  printf( "5. ops/2,read %10lld %10lld\n", values[4][0],
241  values[4][1] );
242  printf( "6. ops/2,accum %10lld %10lld\n", values[5][0],
243  values[5][1] );
244  printf( "7. ops/2,read %10lld %10lld\n", values[6][0],
245  values[6][1] );
246  printf( "8. reset,ops/2,stop %10lld %10lld\n", values[7][0],
247  values[7][1] );
248  printf( "9. reset,read %10lld %10lld\n", values[8][0],
249  values[8][1] );
250  printf( "-------------------------------------------------------------------------\n" );
251  printf( "Verification:\n" );
252  printf( "Row 1 approximately equals rows 2 and 3 \n" );
253  printf( "Row 4 approximately equals 1/2 of row 3\n" );
254  printf( "Row 5 approximately equals twice row 4\n" );
255  printf( "Row 6 approximately equals 6 times row 4\n" );
256  printf( "Rows 7 and 8 approximately equal row 4\n" );
257  printf( "Row 9 equals 0\n" );
258  printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC",
259  100.0 * ( float ) values[0][0] / ( float ) values[1][0] );
260  printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str,
261  100.0 * ( float ) values[0][1] / ( float ) values[1][1] );
262  }
263 
264  for ( i = 0; i <= 1; i++ ) {
265  if ( !approx_equals
266  ( ( double ) values[0][i], ( double ) values[1][i] ) )
267  test_fail( __FILE__, __LINE__,
268  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
269  if ( !approx_equals
270  ( ( double ) values[1][i], ( double ) values[2][i] ) )
271  test_fail( __FILE__, __LINE__,
272  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
273  if ( !approx_equals
274  ( ( double ) values[2][i], ( double ) values[3][i] * 2.0 ) )
275  test_fail( __FILE__, __LINE__,
276  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
277  if ( !approx_equals
278  ( ( double ) values[2][i], ( double ) values[4][i] ) )
279  test_fail( __FILE__, __LINE__,
280  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
281  if ( !approx_equals
282  ( ( double ) values[5][i], ( double ) values[3][i] * 6.0 ) )
283  test_fail( __FILE__, __LINE__,
284  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
285  if ( !approx_equals
286  ( ( double ) values[6][i], ( double ) values[3][i] ) )
287  test_fail( __FILE__, __LINE__,
288  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
289  if ( !approx_equals
290  ( ( double ) values[7][i], ( double ) values[3][i] ) )
291  test_fail( __FILE__, __LINE__,
292  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
293  if ( values[8][i] != 0LL )
294  test_fail( __FILE__, __LINE__,
295  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
296  }
297 
298  test_pass( __FILE__ );
299 
300  return 0;
301 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_reset(int EventSet)
Definition: papi.c:2459
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define PAPI_NULL
Definition: papi.h:292
static int num_events
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
char ** argv
Definition: iozone.c:1610
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2745
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4143
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:615
#define PAPI_DEFGRN
Definition: papi.h:434
int approx_equals(double a, double b)
Definition: test_utils.c:33
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
printf("\tTry: -i 0 -i 1 \n\n")
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
#define PAPI_DEFDOM
Definition: papi.h:432
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
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:46
#define PAPI_VER_CURRENT
Definition: papi.h:225
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:201