PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
reset.c File Reference
Include dependency graph for reset.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 61 of file reset.c.

62 {
63  int retval, num_tests = 9, num_events, tmp, i;
64  long long **values;
65  int EventSet = PAPI_NULL;
66  int PAPI_event, mask;
67  char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
68 
69  /* Set TESTS_QUIET variable */
70  tests_quiet( argc, argv );
71 
72  /* Init the PAPI library */
74  if ( retval != PAPI_VER_CURRENT ) {
75  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
76  }
77 
78  /* add PAPI_TOT_CYC and one of the events in
79  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
80  depending on the availability of the event
81  on the platform */
82  EventSet = add_two_events( &num_events, &PAPI_event, &mask );
83 
84  retval = PAPI_event_code_to_name( PAPI_event, event_name );
85  if ( retval != PAPI_OK ) {
86  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
87  }
88  sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
89 
90  values = allocate_test_space( num_tests, num_events );
91 
92  /*===== Test 1: Start/Stop =======================*/
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[0] );
102  if ( retval != PAPI_OK ) {
103  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
104  }
105 
106  /*===== Test 2 Start/Stop =======================*/
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 );
114 
115  retval = PAPI_stop( EventSet, values[1] );
116  if ( retval != PAPI_OK ) {
117  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
118  }
119 
120  /*===== Test 3: Reset/Start/Stop =======================*/
121 
122  retval = PAPI_reset( EventSet );
123  if ( retval != PAPI_OK ) {
124  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
125  }
126 
127  retval = PAPI_start( EventSet );
128  if ( retval != PAPI_OK ) {
129  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
130  }
131 
132  do_flops( NUM_FLOPS );
133 
134  retval = PAPI_stop( EventSet, values[2] );
135  if ( retval != PAPI_OK ) {
136  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
137  }
138 
139  /*===== Test 4: Start/Read =======================*/
140 
141  retval = PAPI_start( EventSet );
142  if ( retval != PAPI_OK ) {
143  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
144  }
145 
146  do_flops( NUM_FLOPS / 2 );
147 
148  retval = PAPI_read( EventSet, values[3] );
149  if ( retval != PAPI_OK ) {
150  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
151  }
152 
153  /*===== Test 5: Read =======================*/
154 
155  do_flops( NUM_FLOPS / 2 );
156 
157  retval = PAPI_read( EventSet, values[4] );
158  if ( retval != PAPI_OK ) {
159  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
160  }
161 
162  /*===== Test 6: Read/Accum =======================*/
163 
164  do_flops( NUM_FLOPS / 2 );
165 
166  retval = PAPI_read( EventSet, values[5] );
167  if ( retval != PAPI_OK ) {
168  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
169  }
170 
171  retval = PAPI_accum( EventSet, values[5] );
172 
173  if ( retval != PAPI_OK ) {
174  test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
175  }
176 
177  /*===== Test 7: Read =======================*/
178 
179  do_flops( NUM_FLOPS / 2 );
180 
181  retval = PAPI_read( EventSet, values[6] );
182  if ( retval != PAPI_OK ) {
183  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
184  }
185 
186  /*===== Test 8 Reset/Stop =======================*/
187  retval = PAPI_reset( EventSet );
188  if ( retval != PAPI_OK ) {
189  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
190  }
191 
192  do_flops( NUM_FLOPS / 2 );
193 
194  retval = PAPI_stop( EventSet, values[7] );
195  if ( retval != PAPI_OK ) {
196  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
197  }
198 
199  /*===== Test 9: Reset/Read =======================*/
200  retval = PAPI_reset( EventSet );
201  if ( retval != PAPI_OK ) {
202  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
203  }
204 
205  retval = PAPI_read( EventSet, values[8] );
206  if ( retval != PAPI_OK ) {
207  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
208  }
209 
210  remove_test_events( &EventSet, mask );
211 
212  printf( "Test case: Start/Stop/Read/Accum/Reset.\n" );
213  printf( "----------------------------------------------------------------\n" );
214  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
215  printf( "Default domain is: %d (%s)\n", tmp,
216  stringify_all_domains( tmp ) );
217  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
218  printf( "Default granularity is: %d (%s)\n", tmp,
219  stringify_granularity( tmp ) );
220  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
221  printf( "-------------------------------------------------------------------------\n" );
222 
223  sprintf( add_event_str, "%s:", event_name );
224  printf( " PAPI_TOT_CYC %s\n", event_name );
225  printf( "1. start,ops,stop %10lld %10lld\n", values[0][0],
226  values[0][1] );
227  printf( "2. start,ops,stop %10lld %10lld\n", values[1][0],
228  values[1][1] );
229  printf( "3. reset,start,ops,stop %10lld %10lld\n", values[2][0],
230  values[2][1] );
231  printf( "4. start,ops/2,read %10lld %10lld\n", values[3][0],
232  values[3][1] );
233  printf( "5. ops/2,read %10lld %10lld\n", values[4][0],
234  values[4][1] );
235  printf( "6. ops/2,accum %10lld %10lld\n", values[5][0],
236  values[5][1] );
237  printf( "7. ops/2,read %10lld %10lld\n", values[6][0],
238  values[6][1] );
239  printf( "8. reset,ops/2,stop %10lld %10lld\n", values[7][0],
240  values[7][1] );
241  printf( "9. reset,read %10lld %10lld\n", values[8][0],
242  values[8][1] );
243  printf
244  ( "-------------------------------------------------------------------------\n" );
245  printf( "Verification:\n" );
246  printf( "Row 1 approximately equals rows 2 and 3 \n" );
247  printf( "Row 4 approximately equals 1/2 of row 3\n" );
248  printf( "Row 5 approximately equals twice row 4\n" );
249  printf( "Row 6 approximately equals 6 times row 4\n" );
250  printf( "Rows 7 and 8 approximately equal row 4\n" );
251  printf( "Row 9 equals 0\n" );
252  printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC",
253  100.0 * ( float ) values[0][0] / ( float ) values[1][0] );
254  printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str,
255  100.0 * ( float ) values[0][1] / ( float ) values[1][1] );
256 
257 
258  for ( i = 0; i <= 1; i++ ) {
259  if ( !approx_equals
260  ( ( double ) values[0][i], ( double ) values[1][i] ) )
261  test_fail( __FILE__, __LINE__,
262  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
263  if ( !approx_equals
264  ( ( double ) values[1][i], ( double ) values[2][i] ) )
265  test_fail( __FILE__, __LINE__,
266  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
267  if ( !approx_equals
268  ( ( double ) values[2][i], ( double ) values[3][i] * 2.0 ) )
269  test_fail( __FILE__, __LINE__,
270  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
271  if ( !approx_equals
272  ( ( double ) values[2][i], ( double ) values[4][i] ) )
273  test_fail( __FILE__, __LINE__,
274  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
275  if ( !approx_equals
276  ( ( double ) values[5][i], ( double ) values[3][i] * 6.0 ) )
277  test_fail( __FILE__, __LINE__,
278  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
279  if ( !approx_equals
280  ( ( double ) values[6][i], ( double ) values[3][i] ) )
281  test_fail( __FILE__, __LINE__,
282  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
283  if ( !approx_equals
284  ( ( double ) values[7][i], ( double ) values[3][i] ) )
285  test_fail( __FILE__, __LINE__,
286  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
287  if ( values[8][i] != 0LL )
288  test_fail( __FILE__, __LINE__,
289  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
290  }
291 
292  test_pass( __FILE__, values, num_tests );
293  return 0;
294 }
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:2225
#define NUM_FLOPS
int PAPI_event[2]
Definition: data_range.c:24
int PAPI_reset(int EventSet)
Definition: papi.c:2370
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
char * stringify_granularity(int granularity)
Definition: test_utils.c:429
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:2653
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
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:4030
#define PAPI_DEFDOM
Definition: fpapi.h:49
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:680
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int approx_equals(double a, double b)
Definition: test_utils.c:94
#define PAPI_DEFGRN
Definition: fpapi.h:51
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:920
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
int EventSet
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2469
int PAPI_start(int EventSet)
Definition: papi.c:2019
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
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277

Here is the call graph for this function: