-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph500.c
215 lines (185 loc) · 5.54 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
/* -*- 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 "graph500-impl.h"
#include "globals.h"
#include "generator.h"
#include "verify.h"
#include "prng.h"
#include "timer.h"
#include "xalloc.h"
#include "options.h"
#include "output_results.h"
static int64_t bfs_root[NROOT_MAX];
static double generation_time;
static double construction_time;
static double bfs_time[NROOT_MAX];
static int64_t bfs_depth[NROOT_MAX];
static double bfs_verify_time[NROOT_MAX];
static double sssp_time[NROOT_MAX];
static int64_t sssp_depth[NROOT_MAX];
static double sssp_verify_time[NROOT_MAX];
static packed_edge * restrict IJ = NULL;
static void run_bfs (void);
int
main (int argc, char **argv)
{
get_options (argc, argv);
init_prng ();
if (VERBOSE)
fprintf (stderr, "Running with %" PRId64 " vertices and %" PRId64 " edges.\n",
NV, NE);
generation_time = construction_time = 0;
/*
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 defined(STORED_EDGELIST)
size_t sz = NE * sizeof (*IJ);
IJ = xmalloc_large (sz);
if (!dumpname) {
if (VERBOSE) fprintf (stderr, "Generating edge list...");
TIME(generation_time, make_graph (IJ));
if (VERBOSE) fprintf (stderr, " done.\n");
} else {
int fd;
if (VERBOSE) fprintf (stderr, "Reading edge list...");
if ((fd = open (dumpname, O_RDONLY)) < 0) {
perror ("Cannot open input graph file");
return EXIT_FAILURE;
}
if (sz != read (fd, IJ, sz)) {
perror ("Error reading input graph file");
return EXIT_FAILURE;
}
close (fd);
if (VERBOSE) fprintf (stderr, " done.\n");
}
#else
if (dumpname) {
fprintf (stderr, "Reading the edge list but not storing it is unsupported."
" Sorry. But not really.\n");
return EXIT_FAILURE;
}
#endif
run_bfs ();
xfree_large (IJ);
extern char IMPLEMENTATION[];
output_results (IMPLEMENTATION,
generation_time, construction_time,
bfs_root,
bfs_time, bfs_depth, bfs_verify_time,
sssp_time, sssp_depth, sssp_verify_time);
return EXIT_SUCCESS;
}
void
run_bfs (void)
{
int m, err;
int64_t * tree = NULL;
int64_t * tree_depth = NULL;
if (VERBOSE) fprintf (stderr, "Creating graph...");
TIME(construction_time, err = create_graph_from_edgelist (IJ, NE, NV));
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) {
sample_roots (bfs_root, NROOT, NE);
} else {
int fd;
ssize_t sz;
if ((fd = open (rootname, O_RDONLY)) < 0) {
perror ("Cannot open input BFS root file");
exit (EXIT_FAILURE);
}
sz = NROOT * sizeof (*bfs_root);
if (sz != read (fd, bfs_root, sz)) {
perror ("Error reading input BFS root file");
exit (EXIT_FAILURE);
}
close (fd);
}
tree = xmalloc_large (NV * sizeof (*tree));
tree_depth = xmalloc_large (NV * sizeof (*tree_depth));
for (m = 0; m < NROOT; ++m) {
int64_t * depth = NULL;
assert (bfs_root[m] < NV);
if (VERBOSE) fprintf (stderr, "Running bfs %d from %" PRId64 "...", m,
bfs_root[m]);
#if defined(USE_BFS_TREE_DEPTH)
depth = tree_depth;
#endif
TIME(bfs_time[m], err = make_bfs_tree (tree, depth, bfs_root[m]));
if (VERBOSE) fprintf (stderr, " done\n");
if (err) {
if (VERBOSE) perror ("make_bfs_tree failed");
bfs_time[m] = -1;
bfs_depth[m] = -1;
bfs_verify_time[m] = -1;
} else if (!SKIP_VERIFY) {
if (VERBOSE) fprintf (stderr, "Verifying bfs %d...", m);
TIME(bfs_verify_time[m],
bfs_depth[m] = verify_tree (tree, depth, 1,
bfs_root[m], bfs_time[m],
IJ, NE));
if (VERBOSE) fprintf (stderr, "done\n");
if (bfs_depth[m] < 0) {
fprintf (stderr, "bfs %d from %" PRId64 " failed verification (%" PRId64 ")\n",
m, bfs_root[m], bfs_depth[m]);
abort ();
}
}
}
for (m = 0; m < NROOT; ++m) {
assert (bfs_root[m] < NV);
if (VERBOSE) fprintf (stderr, "Running sssp %d from %" PRId64 "...", m,
bfs_root[m]);
TIME(sssp_time[m], err = make_sssp_tree (tree, tree_depth,
bfs_root[m]));
if (VERBOSE) fprintf (stderr, " done\n");
if (err) {
if (VERBOSE) perror ("make_sssp_tree failed");
sssp_time[m] = -1;
sssp_depth[m] = -1;
sssp_verify_time[m] = -1;
} else if (!SKIP_VERIFY) {
if (VERBOSE) fprintf (stderr, "Verifying sssp %d...", m);
TIME(sssp_verify_time[m],
sssp_depth[m] = verify_tree (tree, tree_depth, 0,
bfs_root[m], sssp_time[m],
IJ, NE));
if (VERBOSE) fprintf (stderr, "done\n");
if (sssp_depth[m] < 0) {
fprintf (stderr, "sssp %d from %" PRId64 " failed verification (%" PRId64 ")\n",
m, bfs_root[m], sssp_depth[m]);
abort ();
}
}
}
xfree_large (tree_depth);
xfree_large (tree);
destroy_graph ();
}