|
Packit |
577717 |
/* These examples show the essentials in using the PAPI high-level
|
|
Packit |
577717 |
interface. The program consists of 4 work-loops. The programmer
|
|
Packit |
577717 |
intends to count the total events for loop 1, 2 and 4, but not
|
|
Packit |
577717 |
include the number of events in loop 3.
|
|
Packit |
577717 |
|
|
Packit |
577717 |
To accomplish this PAPI_read_counters is used as a counter
|
|
Packit |
577717 |
reset function, while PAPI_accum_counters is used to sum
|
|
Packit |
577717 |
the contributions of loops 2 and 4 into the total count.
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
#include "papi_test.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "do_loops.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#define NUM_EVENTS 2
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
main( int argc, char **argv )
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
long long values[NUM_EVENTS], dummyvalues[NUM_EVENTS];
|
|
Packit |
577717 |
long long myvalues[NUM_EVENTS];
|
|
Packit |
577717 |
int Events[NUM_EVENTS];
|
|
Packit |
577717 |
int quiet;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Set TESTS_QUIET variable */
|
|
Packit |
577717 |
quiet=tests_quiet( argc, argv );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_library_init( PAPI_VER_CURRENT );
|
|
Packit |
577717 |
if ( retval != PAPI_VER_CURRENT ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* query and set up the right events to monitor */
|
|
Packit |
577717 |
if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
|
|
Packit |
577717 |
Events[0] = PAPI_FP_INS;
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
Events[0] = PAPI_TOT_INS;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
Events[1] = PAPI_TOT_CYC;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_start_counters( ( int * ) Events, NUM_EVENTS );
|
|
Packit |
577717 |
if ( retval != PAPI_OK ) {
|
|
Packit |
577717 |
if (!quiet) printf("Cannot start events\n");
|
|
Packit |
577717 |
test_skip( __FILE__, __LINE__, "PAPI_start_counters", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Loop 1 */
|
|
Packit |
577717 |
do_flops( NUM_FLOPS );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_read_counters( values, NUM_EVENTS );
|
|
Packit |
577717 |
if ( retval != PAPI_OK )
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_read_counters", retval );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( !quiet )
|
|
Packit |
577717 |
printf( TWO12, values[0], values[1], "(Counters continuing...)\n" );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
myvalues[0] = values[0];
|
|
Packit |
577717 |
myvalues[1] = values[1];
|
|
Packit |
577717 |
/* Loop 2 */
|
|
Packit |
577717 |
do_flops( NUM_FLOPS );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_accum_counters( values, NUM_EVENTS );
|
|
Packit |
577717 |
if ( retval != PAPI_OK )
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_accum_counters", retval );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( !quiet )
|
|
Packit |
577717 |
printf( TWO12, values[0], values[1], "(Counters being ''held'')\n" );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Loop 3 */
|
|
Packit |
577717 |
/* Simulated code that should not be counted */
|
|
Packit |
577717 |
do_flops( NUM_FLOPS );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_read_counters( dummyvalues, NUM_EVENTS );
|
|
Packit |
577717 |
if ( retval != PAPI_OK )
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_read_counters", retval );
|
|
Packit |
577717 |
if ( !quiet )
|
|
Packit |
577717 |
printf( TWO12, dummyvalues[0], dummyvalues[1], "(Skipped counts)\n" );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( !quiet )
|
|
Packit |
577717 |
printf( "%12s %12s (''Continuing'' counting)\n", "xxx", "xxx" );
|
|
Packit |
577717 |
/* Loop 4 */
|
|
Packit |
577717 |
do_flops( NUM_FLOPS );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_accum_counters( values, NUM_EVENTS );
|
|
Packit |
577717 |
if ( retval != PAPI_OK )
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_accum_counters", retval );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( !quiet )
|
|
Packit |
577717 |
printf( TWO12, values[0], values[1], "" );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( !quiet ) {
|
|
Packit |
577717 |
printf( "----------------------------------\n" );
|
|
Packit |
577717 |
printf( "Verification: The last line in each experiment should be\n" );
|
|
Packit |
577717 |
printf( "approximately three times the value of the first line.\n" );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
long long min, max;
|
|
Packit |
577717 |
min = ( long long ) ( ( double ) myvalues[0] * .9 );
|
|
Packit |
577717 |
max = ( long long ) ( ( double ) myvalues[0] * 1.1 );
|
|
Packit |
577717 |
if ( values[0] < ( 3 * min ) || values[0] > ( 3 * max ) ) {
|
|
Packit |
577717 |
retval = 1;
|
|
Packit |
577717 |
if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 );
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_TOT_INS", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
min = ( long long ) ( ( double ) myvalues[1] * .9 );
|
|
Packit |
577717 |
max = ( long long ) ( ( double ) myvalues[1] * 1.1 );
|
|
Packit |
577717 |
if ( values[1] < ( 3 * min ) || values[1] > ( 3 * max ) ) {
|
|
Packit |
577717 |
retval = 1;
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
/* The values array is not allocated through allocate_test_space
|
|
Packit |
577717 |
* so we need to pass NULL here */
|
|
Packit |
577717 |
test_pass( __FILE__ );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
}
|