forked from graph500/graph500
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph500.c
362 lines (317 loc) · 9.48 KB
/
graph500.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/* -*- mode: C; mode: folding; 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 <errno.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <alloca.h> /* Portable enough... */
#include <fcntl.h>
/* getopt should be in unistd.h */
#include <unistd.h>
#if !defined(__MTA__)
#include <getopt.h>
#endif
#include "graph500.h"
#include "rmat.h"
#include "kronecker.h"
#include "verify.h"
#include "prng.h"
#include "timer.h"
#include "xalloc.h"
#include "options.h"
#include "generator/splittable_mrg.h"
#include "generator/graph_generator.h"
#include "generator/make_graph.h"
static int64_t nvtx_scale;
static int64_t bfs_root[NBFS_max];
static double generation_time;
static double construction_time;
static double bfs_time[NBFS_max];
static int64_t bfs_nedge[NBFS_max];
static packed_edge * restrict IJ;
static int64_t nedge;
static void run_bfs (void);
static void output_results (const int64_t SCALE, int64_t nvtx_scale,
int64_t edgefactor,
const double A, const double B,
const double C, const double D,
const double generation_time,
const double construction_time,
const int NBFS,
const double *bfs_time, const int64_t *bfs_nedge);
int
main (int argc, char **argv)
{
int64_t desired_nedge;
if (sizeof (int64_t) < 8) {
fprintf (stderr, "No 64-bit support.\n");
return EXIT_FAILURE;
}
if (argc > 1)
get_options (argc, argv);
nvtx_scale = ((int64_t)1)<<SCALE;
init_random ();
desired_nedge = nvtx_scale * edgefactor;
/* Catch a few possible overflows. */
assert (desired_nedge >= nvtx_scale);
assert (desired_nedge >= edgefactor);
/*
If running the benchmark under an architecture simulator, replace
the following if () {} else {} with a statement pointing IJ
to wherever the edge list is mapped into the simulator's memory.
*/
if (!dumpname) {
if (VERBOSE) fprintf (stderr, "Generating edge list...");
if (use_RMAT) {
nedge = desired_nedge;
IJ = xmalloc_large_ext (nedge * sizeof (*IJ));
TIME(generation_time, rmat_edgelist (IJ, nedge, SCALE, A, B, C));
} else {
TIME(generation_time, make_graph (SCALE, desired_nedge, userseed, userseed, &nedge, (packed_edge**)(&IJ)));
}
if (VERBOSE) fprintf (stderr, " done.\n");
} else {
int fd;
ssize_t sz;
if ((fd = open (dumpname, O_RDONLY)) < 0) {
perror ("Cannot open input graph file");
return EXIT_FAILURE;
}
sz = nedge * sizeof (*IJ);
if (sz != read (fd, IJ, sz)) {
perror ("Error reading input graph file");
return EXIT_FAILURE;
}
close (fd);
}
run_bfs ();
xfree_large (IJ);
output_results (SCALE, nvtx_scale, edgefactor, A, B, C, D,
generation_time, construction_time, NBFS, bfs_time, bfs_nedge);
return EXIT_SUCCESS;
}
void
run_bfs (void)
{
int * restrict has_adj;
int m, err;
int64_t k, t, nvtx_connected = 0;
if (VERBOSE) fprintf (stderr, "Creating graph...");
TIME(construction_time, err = create_graph_from_edgelist (IJ, nedge));
if (VERBOSE) fprintf (stderr, "done.\n");
if (err) {
fprintf (stderr, "Failure creating graph.\n");
exit (EXIT_FAILURE);
}
/*
If running the benchmark under an architecture simulator, replace
the following if () {} else {} with a statement pointing bfs_root
to wherever the BFS roots are mapped into the simulator's memory.
*/
if (!rootname) {
has_adj = xmalloc_large (nvtx_scale * sizeof (*has_adj));
OMP("omp parallel") {
OMP("omp for")
for (k = 0; k < nvtx_scale; ++k)
has_adj[k] = 0;
MTA("mta assert nodep") OMP("omp for")
for (k = 0; k < nedge; ++k) {
const int64_t i = get_v0_from_edge(&IJ[k]);
const int64_t j = get_v1_from_edge(&IJ[k]);
if (i != j)
has_adj[i] = has_adj[j] = 1;
}
OMP("omp for reduction(+:nvtx_connected)")
for (k = 0; k < nvtx_scale; ++k)
if (has_adj[k]) ++nvtx_connected;
}
/* Sample from {0, ..., nvtx_scale-1} without replacement, but
only from vertices with degree > 0. */
m = 0;
t = 0;
for (k = 0; k < nvtx_scale && m < NBFS && t < nvtx_connected; ++k) {
if (has_adj[k]) {
double R = mrg_get_double_orig (prng_state);
if ((nvtx_connected - t)*R > NBFS - m) ++t;
else bfs_root[m++] = t++;
}
}
if (t >= nvtx_connected && m < NBFS) {
if (m > 0) {
fprintf (stderr, "Cannot find %d sample roots of non-self degree > 0, using %d.\n",
NBFS, m);
NBFS = m;
} else {
fprintf (stderr, "Cannot find any sample roots of non-self degree > 0.\n");
exit (EXIT_FAILURE);
}
}
xfree_large (has_adj);
} else {
int fd;
ssize_t sz;
if ((fd = open (rootname, O_RDONLY)) < 0) {
perror ("Cannot open input BFS root file");
exit (EXIT_FAILURE);
}
sz = NBFS * sizeof (*bfs_root);
if (sz != read (fd, bfs_root, sz)) {
perror ("Error reading input BFS root file");
exit (EXIT_FAILURE);
}
close (fd);
}
for (m = 0; m < NBFS; ++m) {
int64_t *bfs_tree, max_bfsvtx;
/* Re-allocate. Some systems may randomize the addres... */
bfs_tree = xmalloc_large (nvtx_scale * sizeof (*bfs_tree));
assert (bfs_root[m] < nvtx_scale);
if (VERBOSE) fprintf (stderr, "Running bfs %d...", m);
TIME(bfs_time[m], err = make_bfs_tree (bfs_tree, &max_bfsvtx, bfs_root[m]));
if (VERBOSE) fprintf (stderr, "done\n");
if (err) {
perror ("make_bfs_tree failed");
abort ();
}
if (!getenv("SKIP_VALIDATION")) {
if (VERBOSE) fprintf (stderr, "Verifying bfs %d...", m);
bfs_nedge[m] = verify_bfs_tree (bfs_tree, max_bfsvtx, bfs_root[m], IJ, nedge);
if (VERBOSE) fprintf (stderr, "done\n");
if (bfs_nedge[m] < 0) {
fprintf (stderr, "bfs %d from %" PRId64 " failed verification (%" PRId64 ")\n",
m, bfs_root[m], bfs_nedge[m]);
abort ();
}
}
xfree_large (bfs_tree);
}
destroy_graph ();
}
#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;
}
void
statistics (double *out, double *data, int64_t n)
{
long double s, mean;
double t;
int k;
/* 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 int64_t SCALE, int64_t nvtx_scale, int64_t edgefactor,
const double A, const double B, const double C, const double D,
const double generation_time,
const double construction_time,
const int NBFS, const double *bfs_time, const int64_t *bfs_nedge)
{
int k;
int64_t sz;
double *tm;
double *stats;
tm = alloca (NBFS * sizeof (*tm));
stats = alloca (NSTAT * sizeof (*stats));
if (!tm || !stats) {
perror ("Error allocating within final statistics calculation.");
abort ();
}
sz = (1L << SCALE) * edgefactor * 2 * sizeof (int64_t);
printf ("SCALE: %" PRId64 "\nnvtx: %" PRId64 "\nedgefactor: %" PRId64 "\n"
"terasize: %20.17e\n",
SCALE, nvtx_scale, edgefactor, sz/1.0e12);
printf ("A: %20.17e\nB: %20.17e\nC: %20.17e\nD: %20.17e\n", A, B, C, D);
printf ("generation_time: %20.17e\n", generation_time);
printf ("construction_time: %20.17e\n", construction_time);
printf ("nbfs: %d\n", NBFS);
memcpy (tm, bfs_time, NBFS*sizeof(tm[0]));
statistics (stats, tm, NBFS);
PRINT_STATS("time", 0);
for (k = 0; k < NBFS; ++k)
tm[k] = bfs_nedge[k];
statistics (stats, tm, NBFS);
PRINT_STATS("nedge", 0);
for (k = 0; k < NBFS; ++k)
tm[k] = bfs_nedge[k] / bfs_time[k];
statistics (stats, tm, NBFS);
PRINT_STATS("TEPS", 1);
}