PAPI  5.0.1.0
cost_utils.c
Go to the documentation of this file.
00001 #include "papi_test.h"
00002 
00003 int num_iters = NUM_ITERS;
00004 
00005 /* computes min, max, and mean for an array; returns std deviation */
00006 double
00007 do_stats( long long *array, long long *min, long long *max, double *average )
00008 {
00009     int i;
00010     double std, tmp;
00011 
00012     *min = *max = array[0];
00013     *average = 0;
00014     for ( i = 0; i < num_iters; i++ ) {
00015         *average += ( double ) array[i];
00016         if ( *min > array[i] )
00017             *min = array[i];
00018         if ( *max < array[i] )
00019             *max = array[i];
00020     }
00021     *average = *average / ( double ) num_iters;
00022     std = 0;
00023     for ( i = 0; i < num_iters; i++ ) {
00024         tmp = ( double ) array[i] - ( *average );
00025         std += tmp * tmp;
00026     }
00027     std = sqrt( std / ( num_iters - 1 ) );
00028     return ( std );
00029 }
00030 
00031 void
00032 do_std_dev( long long *a, int *s, double std, double ave )
00033 {
00034     int i, j;
00035     double dev[10];
00036 
00037     for ( i = 0; i < 10; i++ ) {
00038         dev[i] = std * ( i + 1 );
00039         s[i] = 0;
00040     }
00041 
00042     for ( i = 0; i < num_iters; i++ ) {
00043         for ( j = 0; j < 10; j++ ) {
00044             if ( ( ( double ) a[i] - dev[j] ) > ave )
00045                 s[j]++;
00046         }
00047     }
00048 }
00049 
00050 void
00051 do_dist( long long *a, long long min, long long max, int bins, int *d )
00052 {
00053     int i, j;
00054     int dmax = 0;
00055     int range = ( int ) ( max - min + 1 );  /* avoid edge conditions */
00056 
00057     /* clear the distribution array */
00058     for ( i = 0; i < bins; i++ ) {
00059         d[i] = 0;
00060     }
00061 
00062     /* scan the array to distribute cost per bin */
00063     for ( i = 0; i < num_iters; i++ ) {
00064         j = ( ( int ) ( a[i] - min ) * bins ) / range;
00065         d[j]++;
00066         if ( j && ( dmax < d[j] ) )
00067             dmax = d[j];
00068     }
00069 
00070     /* scale each bin to a max of 100 */
00071     for ( i = 1; i < bins; i++ ) {
00072         d[i] = ( d[i] * 100 ) / dmax;
00073     }
00074 }
00075 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines