|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* A simple example for the use of PAPI, the number of flops you should
|
|
Packit |
577717 |
* get is about INDEX^3 on machines that consider add and multiply one flop
|
|
Packit |
577717 |
* such as SGI, and 2*(INDEX^3) that don't consider it 1 flop such as INTEL
|
|
Packit |
577717 |
* -Kevin London
|
|
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 "testcode.h"
|
|
Packit |
577717 |
#include "display_error.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
main( int argc, char **argv )
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
float real_time, proc_time, mflops;
|
|
Packit |
577717 |
long long flpins;
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
int fip = 0;
|
|
Packit |
577717 |
int quiet=0;
|
|
Packit |
577717 |
long long expected;
|
|
Packit |
577717 |
double double_result,error;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Set TESTS_QUIET variable */
|
|
Packit |
577717 |
quiet=tests_quiet( argc, argv );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Initialize PAPI library */
|
|
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 |
/* Try to use one of the FP events */
|
|
Packit |
577717 |
if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
|
|
Packit |
577717 |
fip = 1;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
else if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK ) {
|
|
Packit |
577717 |
fip = 2;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
else {
|
|
Packit |
577717 |
if ( !quiet ) printf( "PAPI_FP_INS and PAPI_FP_OPS are not defined for this platform.\n" );
|
|
Packit |
577717 |
test_skip(__FILE__,__LINE__,"No FP events available",1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Shutdown? */
|
|
Packit |
577717 |
/* I guess because it would interfere with the high-level interface? */
|
|
Packit |
577717 |
PAPI_shutdown( );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Initialize the Matrix arrays */
|
|
Packit |
577717 |
expected=flops_float_init_matrix();
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Setup PAPI library and begin collecting data from the counters */
|
|
Packit |
577717 |
if ( fip == 1 ) {
|
|
Packit |
577717 |
retval = PAPI_flips( &real_time, &proc_time, &flpins, &mflops );
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
else {
|
|
Packit |
577717 |
retval = PAPI_flops( &real_time, &proc_time, &flpins, &mflops );
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Matrix-Matrix multiply */
|
|
Packit |
577717 |
double_result=flops_float_matrix_matrix_multiply();
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Collect the data into the variables passed in */
|
|
Packit |
577717 |
if ( fip == 1 ) {
|
|
Packit |
577717 |
retval = PAPI_flips( &real_time, &proc_time, &flpins, &mflops );
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
retval = PAPI_flops( &real_time, &proc_time, &flpins, &mflops );
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!quiet) printf("result=%lf\n",double_result);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( !quiet ) {
|
|
Packit |
577717 |
printf( "Real_time: %f Proc_time: %f MFLOPS: %f\n",
|
|
Packit |
577717 |
real_time, proc_time, mflops );
|
|
Packit |
577717 |
if ( fip == 1 ) {
|
|
Packit |
577717 |
printf( "Total flpins: ");
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
printf( "Total flpops: ");
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
printf( "%lld\n\n", flpins );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
error=display_error(flpins,flpins,flpins,expected,quiet);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ((error > 1.0) || (error<-1.0)) {
|
|
Packit |
577717 |
if (!quiet) printf("Instruction count off by more than 1%%\n");
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Validation failed", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
test_pass( __FILE__ );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
}
|