PAPI  5.4.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 "papi_test.h"
2 
4 
5 /* computes min, max, and mean for an array; returns std deviation */
6 double
7 do_stats( long long *array, long long *min, long long *max, double *average )
8 {
9  int i;
10  double std, tmp;
11 
12  *min = *max = array[0];
13  *average = 0;
14  for ( i = 0; i < num_iters; i++ ) {
15  *average += ( double ) array[i];
16  if ( *min > array[i] )
17  *min = array[i];
18  if ( *max < array[i] )
19  *max = array[i];
20  }
21  *average = *average / ( double ) num_iters;
22  std = 0;
23  for ( i = 0; i < num_iters; i++ ) {
24  tmp = ( double ) array[i] - ( *average );
25  std += tmp * tmp;
26  }
27  std = sqrt( std / ( num_iters - 1 ) );
28  return ( std );
29 }
30 
31 void
32 do_std_dev( long long *a, int *s, double std, double ave )
33 {
34  int i, j;
35  double dev[10];
36 
37  for ( i = 0; i < 10; i++ ) {
38  dev[i] = std * ( i + 1 );
39  s[i] = 0;
40  }
41 
42  for ( i = 0; i < num_iters; i++ ) {
43  for ( j = 0; j < 10; j++ ) {
44  if ( ( ( double ) a[i] - dev[j] ) > ave )
45  s[j]++;
46  }
47  }
48 }
49 
50 void
51 do_dist( long long *a, long long min, long long max, int bins, int *d )
52 {
53  int i, j;
54  int dmax = 0;
55  int range = ( int ) ( max - min + 1 ); /* avoid edge conditions */
56 
57  /* clear the distribution array */
58  for ( i = 0; i < bins; i++ ) {
59  d[i] = 0;
60  }
61 
62  /* scan the array to distribute cost per bin */
63  for ( i = 0; i < num_iters; i++ ) {
64  j = ( ( int ) ( a[i] - min ) * bins ) / range;
65  d[j]++;
66  if ( j && ( dmax < d[j] ) )
67  dmax = d[j];
68  }
69 
70  /* scale each bin to a max of 100 */
71  for ( i = 1; i < bins; i++ ) {
72  d[i] = ( d[i] * 100 ) / dmax;
73  }
74 }
75 
off64_t max
Definition: libasync.c:331
#define NUM_ITERS
Definition: multiplex.c:19
volatile int num_iters
static double
Definition: fileop.c:1281
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
double do_stats(long long *array, long long *min, long long *max, double *average)
Definition: cost_utils.c:7
int i
Definition: fileop.c:140
s
Definition: iozone.c:20289
#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:51
int range
Definition: fileop.c:139
void do_std_dev(long long *a, int *s, double std, double ave)
Definition: cost_utils.c:32
int
Definition: iozone.c:18528
long j
Definition: iozone.c:19135
long long tmp
Definition: iozone.c:12031