|
PAPI
5.0.1.0
|
00001 /* 00002 * A simple example for the use of PAPI, the number of flops you should 00003 * get is about INDEX^3 on machines that consider add and multiply one flop 00004 * such as SGI, and 2*(INDEX^3) that don't consider it 1 flop such as INTEL 00005 * -Kevin London 00006 */ 00007 00008 #include "papi_test.h" 00009 00010 #define INDEX 1000 00011 00012 char format_string[] = 00013 { "Real_time: %f Proc_time: %f Total flpins: %lld MFLOPS: %f\n" }; 00014 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00015 00016 00017 extern void dummy( void * ); 00018 float matrixa[INDEX][INDEX], matrixb[INDEX][INDEX], mresult[INDEX][INDEX]; 00019 int 00020 main( int argc, char **argv ) 00021 { 00022 float real_time, proc_time, mflops; 00023 long long flpins; 00024 int retval; 00025 int i, j, k, fip = 0; 00026 00027 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00028 00029 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00030 if ( retval != PAPI_VER_CURRENT ) 00031 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00032 00033 if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) 00034 fip = 1; 00035 else if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK ) 00036 fip = 2; 00037 else { 00038 if ( !TESTS_QUIET ) 00039 printf 00040 ( "PAPI_FP_INS and PAPI_FP_OPS are not defined for this platform.\n" ); 00041 } 00042 00043 PAPI_shutdown( ); 00044 00045 if ( fip > 0 ) { 00046 /* Initialize the Matrix arrays */ 00047 for ( i = 0; i < INDEX; i++ ) { 00048 for ( j = 0; j < INDEX; j++) { 00049 mresult[j][i] = 0.0; 00050 matrixa[j][i] = matrixb[j][i] = ( float ) rand( ) * ( float ) 1.1; 00051 } 00052 } 00053 00054 /* Setup PAPI library and begin collecting data from the counters */ 00055 if ( fip == 1 ) { 00056 if ( ( retval = 00057 PAPI_flips( &real_time, &proc_time, &flpins, 00058 &mflops ) ) < PAPI_OK ) 00059 test_fail( __FILE__, __LINE__, "PAPI_flips", retval ); 00060 } else { 00061 if ( ( retval = 00062 PAPI_flops( &real_time, &proc_time, &flpins, 00063 &mflops ) ) < PAPI_OK ) 00064 test_fail( __FILE__, __LINE__, "PAPI_flops", retval ); 00065 } 00066 00067 /* Matrix-Matrix multiply */ 00068 for ( i = 0; i < INDEX; i++ ) 00069 for ( j = 0; j < INDEX; j++ ) 00070 for ( k = 0; k < INDEX; k++ ) 00071 mresult[i][j] = 00072 mresult[i][j] + matrixa[i][k] * matrixb[k][j]; 00073 00074 /* Collect the data into the variables passed in */ 00075 if ( fip == 1 ) { 00076 if ( ( retval = 00077 PAPI_flips( &real_time, &proc_time, &flpins, 00078 &mflops ) ) < PAPI_OK ) 00079 test_fail( __FILE__, __LINE__, "PAPI_flips", retval ); 00080 } else { 00081 if ( ( retval = 00082 PAPI_flops( &real_time, &proc_time, &flpins, 00083 &mflops ) ) < PAPI_OK ) 00084 test_fail( __FILE__, __LINE__, "PAPI_flops", retval ); 00085 } 00086 dummy( ( void * ) mresult ); 00087 00088 if ( !TESTS_QUIET ) { 00089 if ( fip == 1 ) { 00090 printf( "Real_time: %f Proc_time: %f Total flpins: ", real_time, 00091 proc_time ); 00092 } else { 00093 printf( "Real_time: %f Proc_time: %f Total flpops: ", real_time, 00094 proc_time ); 00095 } 00096 printf( LLDFMT, flpins ); 00097 printf( " MFLOPS: %f\n", mflops ); 00098 } 00099 } 00100 test_pass( __FILE__, NULL, 0 ); 00101 exit( 1 ); 00102 }