PAPI  5.7.0.0
cost_utils.c File Reference
Include dependency graph for cost_utils.c:

Go to the source code of this file.

Macros

#define NUM_ITERS   1000000
 

Functions

double do_stats (long long *array, long long *min, long long *max, double *average)
 
void do_std_dev (long long *a, int *s, double std, double ave)
 
void do_dist (long long *a, long long min, long long max, int bins, int *d)
 
static int cmpfunc (const void *a, const void *b)
 
int do_percentile (long long *a, long long *percent25, long long *percent50, long long *percent75, long long *percent99)
 

Variables

int num_iters = NUM_ITERS
 

Macro Definition Documentation

◆ NUM_ITERS

#define NUM_ITERS   1000000

Definition at line 6 of file cost_utils.c.

Function Documentation

◆ cmpfunc()

static int cmpfunc ( const void *  a,
const void *  b 
)
static

Definition at line 82 of file cost_utils.c.

82  {
83 
84  if ( *(long long *)a - *(long long *)b < 0 ) {
85  return -1;
86  }
87 
88  if ( *(long long int*)a - *(long long int*)b > 0 ) {
89  return 1;
90  }
91 
92  return 0;
93 }
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
Here is the caller graph for this function:

◆ do_dist()

void do_dist ( long long *  a,
long long  min,
long long  max,
int  bins,
int *  d 
)

Definition at line 56 of file cost_utils.c.

57 {
58  int i, j;
59  int dmax = 0;
60  int range = ( int ) ( max - min + 1 ); /* avoid edge conditions */
61 
62  /* clear the distribution array */
63  for ( i = 0; i < bins; i++ ) {
64  d[i] = 0;
65  }
66 
67  /* scan the array to distribute cost per bin */
68  for ( i = 0; i < num_iters; i++ ) {
69  j = ( ( int ) ( a[i] - min ) * bins ) / range;
70  d[j]++;
71  if ( j && ( dmax < d[j] ) )
72  dmax = d[j];
73  }
74 
75  /* scale each bin to a max of 100 */
76  for ( i = 1; i < bins; i++ ) {
77  d[i] = ( d[i] * 100 ) / dmax;
78  }
79 }
#define min(x, y)
Definition: darwin-common.h:4
int range
Definition: fileop.c:139
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
int i
Definition: fileop.c:140
int num_iters
Definition: cost_utils.c:8

◆ do_percentile()

int do_percentile ( long long *  a,
long long *  percent25,
long long *  percent50,
long long *  percent75,
long long *  percent99 
)

Definition at line 96 of file cost_utils.c.

100  {
101 
102  long long *a_sort;
103  int i_25,i_50,i_75,i_99;
104 
105  /* Allocate room for a copy of the results */
106  a_sort = calloc(num_iters,sizeof(long long));
107  if (a_sort==NULL) {
108  fprintf(stderr,"Memory allocation error!\n");
109  return -1;
110  }
111 
112  /* Make a copy of the results */
113  memcpy(a_sort,a,num_iters*sizeof(long long));
114 
115  /* Calculate indices */
116  i_25=(int)num_iters/4;
117  i_50=(int)num_iters/2;
118  // index for 75%, not quite accurate because it doesn't
119  // take even or odd into consideration
120  i_75=(int)num_iters/4*3;
121  i_99=(int)num_iters/10*9.9;
122 
123  qsort(a_sort,num_iters-1,sizeof(long long),cmpfunc);
124 
125  *percent25=a_sort[i_25];
126  *percent50=a_sort[i_50];
127  *percent75=a_sort[i_75];
128  *percent99=a_sort[i_99];
129 
130  free(a_sort);
131 
132  return 0;
133 }
static int cmpfunc(const void *a, const void *b)
Definition: cost_utils.c:82
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
int num_iters
Definition: cost_utils.c:8
Here is the call graph for this function:

◆ do_stats()

double do_stats ( long long *  array,
long long *  min,
long long *  max,
double *  average 
)

Definition at line 12 of file cost_utils.c.

13 {
14  int i;
15  double std, tmp;
16 
17  *min = *max = array[0];
18  *average = 0;
19  for ( i = 0; i < num_iters; i++ ) {
20  *average += ( double ) array[i];
21  if ( *min > array[i] )
22  *min = array[i];
23  if ( *max < array[i] )
24  *max = array[i];
25  }
26  *average = *average / ( double ) num_iters;
27  std = 0;
28  for ( i = 0; i < num_iters; i++ ) {
29  tmp = ( double ) array[i] - ( *average );
30  std += tmp * tmp;
31  }
32  std = sqrt( std / ( num_iters - 1 ) );
33  return ( std );
34 }
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
double tmp
#define min(x, y)
Definition: darwin-common.h:4
int i
Definition: fileop.c:140
int num_iters
Definition: cost_utils.c:8

◆ do_std_dev()

void do_std_dev ( long long *  a,
int *  s,
double  std,
double  ave 
)

Definition at line 37 of file cost_utils.c.

38 {
39  int i, j;
40  double dev[10];
41 
42  for ( i = 0; i < 10; i++ ) {
43  dev[i] = std * ( i + 1 );
44  s[i] = 0;
45  }
46 
47  for ( i = 0; i < num_iters; i++ ) {
48  for ( j = 0; j < 10; j++ ) {
49  if ( ( ( double ) a[i] - dev[j] ) > ave )
50  s[j]++;
51  }
52  }
53 }
double s
Definition: byte_profile.c:36
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
int i
Definition: fileop.c:140
int num_iters
Definition: cost_utils.c:8

Variable Documentation

◆ num_iters

int num_iters = NUM_ITERS

Definition at line 8 of file cost_utils.c.