forked from jmrosinski/GPTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashstats.c
91 lines (84 loc) · 2.44 KB
/
hashstats.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "private.h"
#include <stdio.h>
static float meanhashvalue (Hashentry *, int);
void GPTLprint_hashstats (FILE *fp, int nthreads, Hashentry **hashtable, int tablesize)
{
int t; /* thread index */
int i, ii;
int totent; /* per-thread collision count (diagnostic) */
int nument; /* per-index collision count (diagnostic) */
/*
** Diagnostics for collisions and GPTL memory usage
*/
int num_zero; /* number of buckets with 0 collisions */
int num_one; /* number of buckets with 1 collision */
int num_two; /* number of buckets with 2 collisions */
int num_more; /* number of buckets with more than 2 collisions */
int most; /* biggest collision count */
bool first;
for (t = 0; t < nthreads; t++) {
first = true;
totent = 0;
num_zero = 0;
num_one = 0;
num_two = 0;
num_more = 0;
most = 0;
for (i = 0; i < tablesize; i++) {
nument = hashtable[t][i].nument;
if (nument > 1) {
totent += nument-1;
if (first) {
first = false;
fprintf (fp, "\nthread %d had some hash collisions:\n", t);
}
fprintf (fp, "hashtable[%d][%d] had %d entries:", t, i, nument);
for (ii = 0; ii < nument; ii++)
fprintf (fp, " %s", hashtable[t][i].entries[ii]->name);
fprintf (fp, "\n");
}
switch (nument) {
case 0:
++num_zero;
break;
case 1:
++num_one;
break;
case 2:
++num_two;
break;
default:
++num_more;
break;
}
most = MAX (most, nument);
}
if (totent > 0) {
fprintf (fp, "Total collisions thread %d = %d\n", t, totent);
fprintf (fp, "Entry information:\n");
fprintf (fp, "num_zero = %d num_one = %d num_two = %d num_more = %d\n",
num_zero, num_one, num_two, num_more);
fprintf (fp, "Most = %d\n", most);
}
}
fprintf (fp, "Size of hash table was %d\n", tablesize);
fprintf (fp, "Mean hash index for thread 0 was %f\n", meanhashvalue (hashtable[0], tablesize));
}
static float meanhashvalue (Hashentry *hashtable, int tablesize)
{
float sum = 0.; /* used to calculate mean */
int nument;
int totent = 0; /* number of entries */
int i;
for (i = 1; i < tablesize; ++i) {
nument = hashtable[i].nument;
if (nument > 0) {
sum += (float) (nument * i);
totent += hashtable[i].nument;
}
}
if (totent == 0)
return (float) 0.;
else
return sum / totent;
}