Skip to content

Commit fd604b9

Browse files
committed
---
yaml --- r: 12936 b: refs/heads/master c: cba2761 h: refs/heads/master v: v3
1 parent 5bff51c commit fd604b9

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 4312fa44b9cab69aa08834016484cfec47f19843
2+
refs/heads/master: cba2761cc4b0c1a8600928828f980bfb4466472d
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/test/bench/graph500-bfs.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,78 @@ fn bfs(graph: graph, key: node_id) -> bfs_result {
168168
vec::from_mut(marks)
169169
}
170170

171+
#[doc="Another version of the bfs function.
172+
173+
This one uses the same algorithm as the parallel one, just without
174+
using the parallel vector operators."]
175+
fn bfs2(graph: graph, key: node_id) -> bfs_result {
176+
// This works by doing functional updates of a color vector.
177+
178+
enum color {
179+
white,
180+
// node_id marks which node turned this gray/black.
181+
// the node id later becomes the parent.
182+
gray(node_id),
183+
black(node_id)
184+
};
185+
186+
let mut colors = vec::from_fn(graph.len()) {|i|
187+
if i as node_id == key {
188+
gray(key)
189+
}
190+
else {
191+
white
192+
}
193+
};
194+
195+
fn is_gray(c: color) -> bool {
196+
alt c {
197+
gray(_) { true }
198+
_ { false }
199+
}
200+
}
201+
202+
let mut i = 0u;
203+
while vec::any(colors, is_gray) {
204+
// Do the BFS.
205+
log(info, #fmt("PBFS iteration %?", i));
206+
i += 1u;
207+
colors = colors.mapi() {|i, c|
208+
let c : color = c;
209+
alt c {
210+
white {
211+
let i = i as node_id;
212+
213+
let neighbors = graph[i];
214+
215+
let mut color = white;
216+
217+
neighbors.each() {|k|
218+
if is_gray(colors[k]) {
219+
color = gray(k);
220+
false
221+
}
222+
else { true }
223+
};
224+
225+
color
226+
}
227+
gray(parent) { black(parent) }
228+
black(parent) { black(parent) }
229+
}
230+
}
231+
}
232+
233+
// Convert the results.
234+
vec::map(colors) {|c|
235+
alt c {
236+
white { -1 }
237+
black(parent) { parent }
238+
_ { fail "Found remaining gray nodes in BFS" }
239+
}
240+
}
241+
}
242+
171243
#[doc="A parallel version of the bfs function."]
172244
fn pbfs(graph: graph, key: node_id) -> bfs_result {
173245
// This works by doing functional updates of a color vector.
@@ -378,6 +450,25 @@ fn main() {
378450
stop - start));
379451
}
380452

453+
let start = time::precise_time_s();
454+
let bfs_tree = bfs2(graph, root);
455+
let stop = time::precise_time_s();
456+
457+
//total_seq += stop - start;
458+
459+
io::stdout().write_line(
460+
#fmt("Slow Sequential BFS completed in %? seconds.",
461+
stop - start));
462+
463+
if do_validate {
464+
let start = time::precise_time_s();
465+
assert(validate(edges, root, bfs_tree));
466+
let stop = time::precise_time_s();
467+
468+
io::stdout().write_line(#fmt("Validation completed in %? seconds.",
469+
stop - start));
470+
}
471+
381472
let start = time::precise_time_s();
382473
let bfs_tree = pbfs(graph, root);
383474
let stop = time::precise_time_s();

0 commit comments

Comments
 (0)