PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cost_utils.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <math.h>
3 
4 #define NUM_ITERS 1000000
5 
7 
8 /* computes min, max, and mean for an array; returns std deviation */
9 double
10 do_stats( long long *array, long long *min, long long *max, double *average )
11 {
12  int i;
13  double std, tmp;
14 
15  *min = *max = array[0];
16  *average = 0;
17  for ( i = 0; i < num_iters; i++ ) {
18  *average += ( double ) array[i];
19  if ( *min > array[i] )
20  *min = array[i];
21  if ( *max < array[i] )
22  *max = array[i];
23  }
24  *average = *average / ( double ) num_iters;
25  std = 0;
26  for ( i = 0; i < num_iters; i++ ) {
27  tmp = ( double ) array[i] - ( *average );
28  std += tmp * tmp;
29  }
30  std = sqrt( std / ( num_iters - 1 ) );
31  return ( std );
32 }
33 
34 void
35 do_std_dev( long long *a, int *s, double std, double ave )
36 {
37  int i, j;
38  double dev[10];
39 
40  for ( i = 0; i < 10; i++ ) {
41  dev[i] = std * ( i + 1 );
42  s[i] = 0;
43  }
44 
45  for ( i = 0; i < num_iters; i++ ) {
46  for ( j = 0; j < 10; j++ ) {
47  if ( ( ( double ) a[i] - dev[j] ) > ave )
48  s[j]++;
49  }
50  }
51 }
52 
53 void
54 do_dist( long long *a, long long min, long long max, int bins, int *d )
55 {
56  int i, j;
57  int dmax = 0;
58  int range = ( int ) ( max - min + 1 ); /* avoid edge conditions */
59 
60  /* clear the distribution array */
61  for ( i = 0; i < bins; i++ ) {
62  d[i] = 0;
63  }
64 
65  /* scan the array to distribute cost per bin */
66  for ( i = 0; i < num_iters; i++ ) {
67  j = ( ( int ) ( a[i] - min ) * bins ) / range;
68  d[j]++;
69  if ( j && ( dmax < d[j] ) )
70  dmax = d[j];
71  }
72 
73  /* scale each bin to a max of 100 */
74  for ( i = 1; i < bins; i++ ) {
75  d[i] = ( d[i] * 100 ) / dmax;
76  }
77 }
78 
off64_t max
Definition: libasync.c:331
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
static double
Definition: fileop.c:1281
double do_stats(long long *array, long long *min, long long *max, double *average)
Definition: cost_utils.c:10
int i
Definition: fileop.c:140
s
Definition: iozone.c:20289
#define NUM_ITERS
Definition: cost_utils.c:4
#define min(x, y)
Definition: darwin-common.h:4
void do_dist(long long *a, long long min, long long max, int bins, int *d)
Definition: cost_utils.c:54
int range
Definition: fileop.c:139
void do_std_dev(long long *a, int *s, double std, double ave)
Definition: cost_utils.c:35
int
Definition: iozone.c:18528
long j
Definition: iozone.c:19135
long long tmp
Definition: iozone.c:12031
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
int num_iters
Definition: cost_utils.c:6