-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_results.c
188 lines (168 loc) · 4.72 KB
/
output_results.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* -*- mode: C; fill-column: 70; -*- */
/* Copyright 2010-2011, Georgia Institute of Technology, USA. */
/* See COPYING for license. */
#include "compat.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <alloca.h> /* Portable enough... */
/* getopt should be in unistd.h */
#include "globals.h"
#include "packed_edge.h"
#include "prng.h"
#define NSTAT 9
#define PRINT_STATS(lbl, israte) \
do { \
printf ("min_%s: %20.17e\n", lbl, stats[0]); \
printf ("firstquartile_%s: %20.17e\n", lbl, stats[1]); \
printf ("median_%s: %20.17e\n", lbl, stats[2]); \
printf ("thirdquartile_%s: %20.17e\n", lbl, stats[3]); \
printf ("max_%s: %20.17e\n", lbl, stats[4]); \
if (!israte) { \
printf ("mean_%s: %20.17e\n", lbl, stats[5]); \
printf ("stddev_%s: %20.17e\n", lbl, stats[6]); \
} else { \
printf ("harmonic_mean_%s: %20.17e\n", lbl, stats[7]); \
printf ("harmonic_stddev_%s: %20.17e\n", lbl, stats[8]); \
} \
} while (0)
static int
dcmp (const void *a, const void *b)
{
const double da = *(const double*)a;
const double db = *(const double*)b;
if (da > db) return 1;
if (db > da) return -1;
if (da == db) return 0;
fprintf (stderr, "No NaNs permitted in output.\n");
abort ();
return 0;
}
static void
statistics (double *out, double *data, int64_t n)
{
long double s, mean;
double t;
int k;
/* Check if in range. */
{
int err = 0;
for (int i = 0; i < n; ++i)
if (data[i] < 0) err = 1;
if (err) {
for (int i = 0; i < NSTAT; ++i)
out[i] = NAN;
return;
}
}
/* Quartiles */
qsort (data, n, sizeof (*data), dcmp);
out[0] = data[0];
t = (n+1) / 4.0;
k = (int) t;
if (t == k)
out[1] = data[k];
else
out[1] = 3*(data[k]/4.0) + data[k+1]/4.0;
t = (n+1) / 2.0;
k = (int) t;
if (t == k)
out[2] = data[k];
else
out[2] = data[k]/2.0 + data[k+1]/2.0;
t = 3*((n+1) / 4.0);
k = (int) t;
if (t == k)
out[3] = data[k];
else
out[3] = data[k]/4.0 + 3*(data[k+1]/4.0);
out[4] = data[n-1];
s = data[n-1];
for (k = n-1; k > 0; --k)
s += data[k-1];
mean = s/n;
out[5] = mean;
s = data[n-1] - mean;
s *= s;
for (k = n-1; k > 0; --k) {
long double tmp = data[k-1] - mean;
s += tmp * tmp;
}
out[6] = sqrt (s/(n-1));
s = (data[0]? 1.0L/data[0] : 0);
for (k = 1; k < n; ++k)
s += (data[k]? 1.0L/data[k] : 0);
out[7] = n/s;
mean = s/n;
/*
Nilan Norris, The Standard Errors of the Geometric and Harmonic
Means and Their Application to Index Numbers, 1940.
http://www.jstor.org/stable/2235723
*/
s = (data[0]? 1.0L/data[0] : 0) - mean;
s *= s;
for (k = 1; k < n; ++k) {
long double tmp = (data[k]? 1.0L/data[k] : 0) - mean;
s += tmp * tmp;
}
s = (sqrt (s)/(n-1)) * out[7] * out[7];
out[8] = s;
}
void
output_results (const char * implementation,
const double generation_time,
const double construction_time,
const int64_t *root,
const double *bfs_time, const int64_t *bfs_depth,
const double *bfs_verify_time,
const double *sssp_time, const int64_t *sssp_depth,
const double *sssp_verify_time)
{
int k;
int64_t sz;
double *tm;
double *stats;
char *s;
tm = alloca (NROOT * sizeof (*tm));
stats = alloca (NSTAT * sizeof (*stats));
if (!tm || !stats) {
perror ("Error allocating within final statistics calculation.");
abort ();
}
s = getenv ("MACHINE");
if (!s) s = "unknown";
printf ("MACHINE: %s\n", s);
s = getenv ("COMMENT");
if (s) printf ("COMMENT: %s\n", s);
printf ("IMPLEMENTATION: %s\n", implementation);
printf ("SCALE: %d\nEDGEFACTOR: %d\nNROOT: %d\nMAXWEIGHT: %d\n",
SCALE, EF, NROOT, MAXWEIGHT);
sz = NE * sizeof (packed_edge);
printf ("TERASIZE: %.8e\n", sz/1.0e12);
printf ("PRNGCHECK: %" PRId32 "\n", prng_check ());
printf ("A: %e\nB: %e\n", (double)A, (double)B);
printf ("K0TIME: %.8e\n", generation_time);
printf ("K1TIME: %.8e\n", construction_time);
for (k = 0; k < NROOT; ++k)
tm[k] = NE / bfs_time[k];
statistics (stats, tm, NROOT);
printf ("K2TEPSMAX: %.8e\n", stats[4]);
printf ("K2TEPSMEAN: %.8e\n", stats[7]);
printf ("K2TEPSSTDDEV: %.8e\n", stats[8]);
for (k = 0; k < NROOT; ++k)
tm[k] = NE / sssp_time[k];
statistics (stats, tm, NROOT);
printf ("K3TEPSMAX: %.8e\n", stats[4]);
printf ("K3TEPSMEAN: %.8e\n", stats[7]);
printf ("K3TEPSSTDDEV: %.8e\n", stats[8]);
printf ("\nroot,k2time,k2max,k2vtime,k3time,k3max,k3vtime\n");
for (k = 0; k < NROOT; ++k)
printf ("%" PRId64 ","
"%.8e,%" PRId64 ",%.8e,"
"%.8e,%" PRId64 ",%.8e\n",
root[k],
bfs_time[k], bfs_depth[k], bfs_verify_time[k],
sssp_time[k], sssp_depth[k], sssp_verify_time[k]);
}