{
#define NROWS1 175
#define NCOLS1 225
#define NROWS2 NCOLS1
#define NCOLS2 150
double p[NROWS1][NCOLS1], q[NROWS2][NCOLS2], r[NROWS1][NCOLS2];
int i, j, k, num_events, retval;
int event[2];
long long values[2], tmp;
extern int TESTS_QUIET;
tests_quiet( argc, argv );
num_events = 0;
num_events = PAPI_num_counters( );
if ( num_events < 2 ) {
printf( "This example program requries the architecture to "
"support 2 simultaneous hardware events...shutting down.\n" );
test_skip( __FILE__, __LINE__, "PAPI_num_counters", 1 );
}
if ( !TESTS_QUIET )
printf( "Number of hardware counters supported: %d\n", num_events );
if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK )
event[0] = PAPI_FP_OPS;
else if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK )
event[0] = PAPI_FP_INS;
else
event[0] = PAPI_TOT_INS;
event[1] = PAPI_TOT_CYC;
for ( i = 0; i < NROWS1; i++ )
for ( j = 0; j < NCOLS1; j++ )
p[i][j] = i * j * 1.0;
for ( i = 0; i < NROWS2; i++ )
for ( j = 0; j < NCOLS2; j++ )
q[i][j] = i * j * 1.0;
for ( i = 0; i < NROWS1; i++ )
for ( j = 0; j < NCOLS2; j++ )
r[i][j] = i * j * 1.0;
num_events = 2;
retval = PAPI_start_counters( event, num_events );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_start_counters", retval );
retval = PAPI_read_counters( values, num_events );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_read_counters", retval );
for ( i = 0; i < NROWS1; i++ )
for ( j = 0; j < NCOLS2; j++ )
for ( k = 0; k < NCOLS1; k++ )
r[i][j] = r[i][j] + p[i][k] * q[k][j];
retval = PAPI_stop_counters( values, num_events );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_stop_counters", retval );
dummy( r );
if ( !TESTS_QUIET ) {
if ( event[0] == PAPI_TOT_INS ) {
printf( TAB1, "TOT Instructions:", values[0] );
} else {
printf( TAB1, "FP Instructions:", values[0] );
}
printf( TAB1, "Cycles:", values[1] );
}
if ( event[0] == PAPI_FP_INS ) {
tmp =
2 * ( long long ) ( NROWS1 ) * ( long long ) ( NCOLS2 ) *
( long long ) ( NCOLS1 );
if ( abs( ( int ) values[0] - ( int ) tmp ) > ( double ) tmp * 0.05 ) {
tmp = tmp / 2;
if ( abs( ( int ) values[0] - ( int ) tmp ) >
( double ) tmp * 0.05 ) {
printf( "\n" TAB1, "Expected operation count: ", 2 * tmp );
printf( TAB1, "Or possibly (using FMA): ", tmp );
printf( TAB1, "Instead I got: ", values[0] );
test_fail( __FILE__, __LINE__,
"Unexpected FLOP count (check vector operations)",
1 );
}
}
}
test_pass( __FILE__, 0, 0 );
return ( PAPI_EMISC );
}