|
PAPI
5.0.1.0
|
00001 /* 00002 * A simple example for the use of PAPI, using PAPI_ipc 00003 * -Kevin London 00004 */ 00005 00006 #include "papi_test.h" 00007 00008 00009 #define INDEX 500 00010 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00011 00012 00013 int 00014 main( int argc, char **argv ) 00015 { 00016 extern void dummy( void * ); 00017 float matrixa[INDEX][INDEX], matrixb[INDEX][INDEX], mresult[INDEX][INDEX]; 00018 float real_time, proc_time, ipc; 00019 long long ins; 00020 int retval; 00021 int i, j, k; 00022 00023 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00024 00025 00026 /* Initialize the Matrix arrays */ 00027 for( i = 0; i < INDEX; i++ ) { 00028 for( j= 0; j < INDEX; j++ ) { 00029 mresult[i][j] = 0.0; 00030 matrixa[i][j] = matrixb[i][j] = ( float ) rand( ) * ( float ) 1.1; 00031 } 00032 } 00033 00034 /* Setup PAPI library and begin collecting data from the counters */ 00035 if ( ( retval = PAPI_ipc( &real_time, &proc_time, &ins, &ipc ) ) < PAPI_OK ) 00036 test_fail( __FILE__, __LINE__, "PAPI_ipc", retval ); 00037 00038 /* Matrix-Matrix multiply */ 00039 for ( i = 0; i < INDEX; i++ ) 00040 for ( j = 0; j < INDEX; j++ ) 00041 for ( k = 0; k < INDEX; k++ ) 00042 mresult[i][j] = mresult[i][j] + matrixa[i][k] * matrixb[k][j]; 00043 00044 /* Collect the data into the variables passed in */ 00045 if ( ( retval = PAPI_ipc( &real_time, &proc_time, &ins, &ipc ) ) < PAPI_OK ) 00046 test_fail( __FILE__, __LINE__, "PAPI_ipc", retval ); 00047 dummy( ( void * ) mresult ); 00048 00049 if ( !TESTS_QUIET ) { 00050 printf( "Real_time: %f Proc_time: %f Total ins: ", real_time, 00051 proc_time ); 00052 printf( LLDFMT, ins ); 00053 printf( " IPC: %f\n", ipc ); 00054 } 00055 00056 /* This should not happen unless the optimizer */ 00057 /* gets too good */ 00058 if (ins < INDEX*INDEX) { 00059 test_fail( __FILE__, __LINE__, "Instruction count too low.", 00060 5 ); 00061 } 00062 /* Something is broken, or else you have a really */ 00063 /* slow processor */ 00064 if (ipc<0.01 ) { 00065 test_fail( __FILE__, __LINE__, "IPC equals zero.", 00066 5 ); 00067 } 00068 00069 test_pass( __FILE__, NULL, 0 ); 00070 exit( 1 ); 00071 }