2012-05-14 18:54:43 -05:00
|
|
|
/**
|
|
|
|
|
2012-06-18 15:34:15 -05:00
|
|
|
An implementation of the Graph500 Breadth First Search problem in Rust.
|
2012-05-14 18:54:43 -05:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
use std;
|
|
|
|
import std::time;
|
|
|
|
import std::map;
|
2012-07-11 17:00:40 -05:00
|
|
|
import std::map::map;
|
2012-05-14 18:54:43 -05:00
|
|
|
import std::map::hashmap;
|
|
|
|
import std::deque;
|
|
|
|
import std::deque::t;
|
2012-05-30 12:36:29 -05:00
|
|
|
import std::par;
|
2012-05-14 18:54:43 -05:00
|
|
|
import io::writer_util;
|
|
|
|
import comm::*;
|
2012-05-15 17:21:35 -05:00
|
|
|
import int::abs;
|
2012-05-14 18:54:43 -05:00
|
|
|
|
|
|
|
type node_id = i64;
|
2012-06-29 18:26:56 -05:00
|
|
|
type graph = ~[~[node_id]];
|
|
|
|
type bfs_result = ~[node_id];
|
2012-05-14 18:54:43 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
|
2012-05-30 18:31:16 -05:00
|
|
|
let r = rand::xorshift();
|
2012-05-14 18:54:43 -05:00
|
|
|
|
|
|
|
fn choose_edge(i: node_id, j: node_id, scale: uint, r: rand::rng)
|
|
|
|
-> (node_id, node_id) {
|
|
|
|
|
|
|
|
let A = 0.57;
|
|
|
|
let B = 0.19;
|
|
|
|
let C = 0.19;
|
|
|
|
|
|
|
|
if scale == 0u {
|
|
|
|
(i, j)
|
|
|
|
}
|
|
|
|
else {
|
2012-05-22 17:29:49 -05:00
|
|
|
let i = i * 2i64;
|
|
|
|
let j = j * 2i64;
|
2012-05-14 18:54:43 -05:00
|
|
|
let scale = scale - 1u;
|
|
|
|
|
2012-05-22 13:06:59 -05:00
|
|
|
let x = r.gen_float();
|
2012-05-14 18:54:43 -05:00
|
|
|
|
|
|
|
if x < A {
|
|
|
|
choose_edge(i, j, scale, r)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let x = x - A;
|
|
|
|
if x < B {
|
2012-05-22 17:29:49 -05:00
|
|
|
choose_edge(i + 1i64, j, scale, r)
|
2012-05-14 18:54:43 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
let x = x - B;
|
|
|
|
if x < C {
|
2012-05-22 17:29:49 -05:00
|
|
|
choose_edge(i, j + 1i64, scale, r)
|
2012-05-14 18:54:43 -05:00
|
|
|
}
|
|
|
|
else {
|
2012-05-22 17:29:49 -05:00
|
|
|
choose_edge(i + 1i64, j + 1i64, scale, r)
|
2012-05-14 18:54:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do vec::from_fn((1u << scale) * edgefactor) |_i| {
|
2012-05-22 17:29:49 -05:00
|
|
|
choose_edge(0i64, 0i64, scale, r)
|
2012-05-14 18:54:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 17:42:56 -05:00
|
|
|
pure fn node_hash(n: &node_id) -> uint { *n as uint }
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
|
2012-06-30 18:19:07 -05:00
|
|
|
let graph = do vec::from_fn(N) |_i| {
|
2012-08-02 17:42:56 -05:00
|
|
|
map::hashmap::<node_id, ()>(node_hash, sys::shape_eq)
|
2012-05-22 17:29:49 -05:00
|
|
|
};
|
2012-05-14 18:54:43 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do vec::each(edges) |e| {
|
2012-05-14 18:54:43 -05:00
|
|
|
let (i, j) = e;
|
|
|
|
map::set_add(graph[i], j);
|
|
|
|
map::set_add(graph[j], i);
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do graph.map() |v| {
|
2012-05-16 17:45:21 -05:00
|
|
|
map::vec_from_set(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn gen_search_keys(graph: graph, n: uint) -> ~[node_id] {
|
2012-08-02 17:42:56 -05:00
|
|
|
let keys = map::hashmap::<node_id, ()>(node_hash, sys::shape_eq);
|
2012-05-16 17:45:21 -05:00
|
|
|
let r = rand::rng();
|
|
|
|
|
|
|
|
while keys.size() < n {
|
2012-05-22 17:29:49 -05:00
|
|
|
let k = r.gen_uint_range(0u, graph.len());
|
2012-05-16 17:45:21 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
if graph[k].len() > 0u && vec::any(graph[k], |i| {
|
2012-05-22 17:29:49 -05:00
|
|
|
i != k as node_id
|
2012-06-26 15:55:56 -05:00
|
|
|
}) {
|
2012-05-22 17:29:49 -05:00
|
|
|
map::set_add(keys, k as node_id);
|
2012-05-16 17:45:21 -05:00
|
|
|
}
|
2012-05-16 17:03:03 -05:00
|
|
|
}
|
2012-05-16 17:45:21 -05:00
|
|
|
map::vec_from_set(keys)
|
2012-05-14 18:54:43 -05:00
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* Returns a vector of all the parents in the BFS tree rooted at key.
|
|
|
|
*
|
|
|
|
* Nodes that are unreachable have a parent of -1.
|
|
|
|
*/
|
2012-05-15 17:21:35 -05:00
|
|
|
fn bfs(graph: graph, key: node_id) -> bfs_result {
|
2012-06-29 18:26:56 -05:00
|
|
|
let marks : ~[mut node_id]
|
2012-05-22 17:29:49 -05:00
|
|
|
= vec::to_mut(vec::from_elem(vec::len(graph), -1i64));
|
2012-05-14 18:54:43 -05:00
|
|
|
|
2012-05-30 16:54:38 -05:00
|
|
|
let Q = deque::create();
|
2012-05-14 18:54:43 -05:00
|
|
|
|
|
|
|
Q.add_back(key);
|
|
|
|
marks[key] = key;
|
|
|
|
|
|
|
|
while Q.size() > 0u {
|
|
|
|
let t = Q.pop_front();
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do graph[t].each() |k| {
|
2012-05-22 17:29:49 -05:00
|
|
|
if marks[k] == -1i64 {
|
2012-05-14 18:54:43 -05:00
|
|
|
marks[k] = t;
|
|
|
|
Q.add_back(k);
|
|
|
|
}
|
|
|
|
true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
vec::from_mut(marks)
|
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* Another version of the bfs function.
|
|
|
|
*
|
|
|
|
* This one uses the same algorithm as the parallel one, just without
|
|
|
|
* using the parallel vector operators.
|
|
|
|
*/
|
2012-05-16 17:52:00 -05:00
|
|
|
fn bfs2(graph: graph, key: node_id) -> bfs_result {
|
|
|
|
// This works by doing functional updates of a color vector.
|
|
|
|
|
|
|
|
enum color {
|
|
|
|
white,
|
|
|
|
// node_id marks which node turned this gray/black.
|
|
|
|
// the node id later becomes the parent.
|
|
|
|
gray(node_id),
|
|
|
|
black(node_id)
|
|
|
|
};
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
let mut colors = do vec::from_fn(graph.len()) |i| {
|
2012-05-16 17:52:00 -05:00
|
|
|
if i as node_id == key {
|
|
|
|
gray(key)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
white
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fn is_gray(c: color) -> bool {
|
|
|
|
alt c {
|
2012-08-03 21:59:04 -05:00
|
|
|
gray(_) => { true }
|
|
|
|
_ => { false }
|
2012-05-16 17:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut i = 0u;
|
|
|
|
while vec::any(colors, is_gray) {
|
|
|
|
// Do the BFS.
|
2012-07-30 18:01:07 -05:00
|
|
|
log(info, fmt!{"PBFS iteration %?", i});
|
2012-05-16 17:52:00 -05:00
|
|
|
i += 1u;
|
2012-06-30 18:19:07 -05:00
|
|
|
colors = do colors.mapi() |i, c| {
|
2012-05-16 17:52:00 -05:00
|
|
|
let c : color = c;
|
|
|
|
alt c {
|
2012-08-03 21:59:04 -05:00
|
|
|
white => {
|
2012-05-16 17:52:00 -05:00
|
|
|
let i = i as node_id;
|
|
|
|
|
|
|
|
let neighbors = graph[i];
|
|
|
|
|
|
|
|
let mut color = white;
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do neighbors.each() |k| {
|
2012-05-16 17:52:00 -05:00
|
|
|
if is_gray(colors[k]) {
|
|
|
|
color = gray(k);
|
|
|
|
false
|
|
|
|
}
|
|
|
|
else { true }
|
|
|
|
};
|
|
|
|
|
|
|
|
color
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
gray(parent) => { black(parent) }
|
|
|
|
black(parent) => { black(parent) }
|
2012-05-16 17:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the results.
|
2012-06-30 18:19:07 -05:00
|
|
|
do vec::map(colors) |c| {
|
2012-05-16 17:52:00 -05:00
|
|
|
alt c {
|
2012-08-03 21:59:04 -05:00
|
|
|
white => { -1i64 }
|
|
|
|
black(parent) => { parent }
|
|
|
|
_ => { fail ~"Found remaining gray nodes in BFS" }
|
2012-05-16 17:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// A parallel version of the bfs function.
|
2012-05-30 17:32:19 -05:00
|
|
|
fn pbfs(&&graph: arc::arc<graph>, key: node_id) -> bfs_result {
|
2012-05-16 17:03:03 -05:00
|
|
|
// This works by doing functional updates of a color vector.
|
|
|
|
|
|
|
|
enum color {
|
|
|
|
white,
|
|
|
|
// node_id marks which node turned this gray/black.
|
|
|
|
// the node id later becomes the parent.
|
|
|
|
gray(node_id),
|
|
|
|
black(node_id)
|
|
|
|
};
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
let mut colors = do vec::from_fn((*arc::get(&graph)).len()) |i| {
|
2012-05-16 17:03:03 -05:00
|
|
|
if i as node_id == key {
|
|
|
|
gray(key)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
white
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-21 18:26:28 -05:00
|
|
|
#[inline(always)]
|
2012-05-16 17:03:03 -05:00
|
|
|
fn is_gray(c: color) -> bool {
|
|
|
|
alt c {
|
2012-08-03 21:59:04 -05:00
|
|
|
gray(_) => { true }
|
|
|
|
_ => { false }
|
2012-05-16 17:03:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut i = 0u;
|
|
|
|
while par::any(colors, is_gray) {
|
|
|
|
// Do the BFS.
|
2012-07-30 18:01:07 -05:00
|
|
|
log(info, fmt!{"PBFS iteration %?", i});
|
2012-05-16 17:03:03 -05:00
|
|
|
i += 1u;
|
2012-05-18 16:39:58 -05:00
|
|
|
let old_len = colors.len();
|
2012-05-25 17:29:27 -05:00
|
|
|
|
2012-05-30 17:18:45 -05:00
|
|
|
let color = arc::arc(colors);
|
|
|
|
|
2012-07-04 14:04:28 -05:00
|
|
|
colors = do par::mapi_factory(*arc::get(&color)) {
|
2012-05-30 17:18:45 -05:00
|
|
|
let colors = arc::clone(&color);
|
|
|
|
let graph = arc::clone(&graph);
|
|
|
|
fn~(i: uint, c: color) -> color {
|
|
|
|
let c : color = c;
|
|
|
|
let colors = arc::get(&colors);
|
|
|
|
let graph = arc::get(&graph);
|
|
|
|
alt c {
|
2012-08-03 21:59:04 -05:00
|
|
|
white => {
|
2012-05-30 17:18:45 -05:00
|
|
|
let i = i as node_id;
|
|
|
|
|
2012-05-30 18:31:16 -05:00
|
|
|
let neighbors = graph[i];
|
2012-05-30 17:18:45 -05:00
|
|
|
|
|
|
|
let mut color = white;
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do neighbors.each() |k| {
|
2012-05-30 18:31:16 -05:00
|
|
|
if is_gray(colors[k]) {
|
2012-05-30 17:18:45 -05:00
|
|
|
color = gray(k);
|
|
|
|
false
|
|
|
|
}
|
|
|
|
else { true }
|
2012-05-21 18:26:28 -05:00
|
|
|
};
|
2012-05-30 17:18:45 -05:00
|
|
|
color
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
gray(parent) => { black(parent) }
|
|
|
|
black(parent) => { black(parent) }
|
2012-05-30 17:18:45 -05:00
|
|
|
}
|
2012-05-16 17:03:03 -05:00
|
|
|
}
|
2012-05-18 16:39:58 -05:00
|
|
|
};
|
|
|
|
assert(colors.len() == old_len);
|
2012-05-16 17:03:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the results.
|
2012-06-30 18:19:07 -05:00
|
|
|
do par::map(colors) |c| {
|
2012-05-16 17:03:03 -05:00
|
|
|
alt c {
|
2012-08-03 21:59:04 -05:00
|
|
|
white => { -1i64 }
|
|
|
|
black(parent) => { parent }
|
|
|
|
_ => { fail ~"Found remaining gray nodes in BFS" }
|
2012-05-16 17:03:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Performs at least some of the validation in the Graph500 spec.
|
2012-06-29 18:26:56 -05:00
|
|
|
fn validate(edges: ~[(node_id, node_id)],
|
2012-05-15 17:21:35 -05:00
|
|
|
root: node_id, tree: bfs_result) -> bool {
|
|
|
|
// There are 5 things to test. Below is code for each of them.
|
|
|
|
|
|
|
|
// 1. The BFS tree is a tree and does not contain cycles.
|
|
|
|
//
|
|
|
|
// We do this by iterating over the tree, and tracing each of the
|
|
|
|
// parent chains back to the root. While we do this, we also
|
|
|
|
// compute the levels for each node.
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
log(info, ~"Verifying tree structure...");
|
2012-05-15 17:21:35 -05:00
|
|
|
|
|
|
|
let mut status = true;
|
2012-06-30 18:19:07 -05:00
|
|
|
let level = do tree.map() |parent| {
|
2012-05-15 17:21:35 -05:00
|
|
|
let mut parent = parent;
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut path = ~[];
|
2012-05-15 17:21:35 -05:00
|
|
|
|
2012-05-22 17:29:49 -05:00
|
|
|
if parent == -1i64 {
|
2012-05-15 17:21:35 -05:00
|
|
|
// This node was not in the tree.
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while parent != root {
|
|
|
|
if vec::contains(path, parent) {
|
|
|
|
status = false;
|
|
|
|
}
|
|
|
|
|
2012-06-25 12:55:29 -05:00
|
|
|
vec::push(path, parent);
|
2012-05-15 17:21:35 -05:00
|
|
|
parent = tree[parent];
|
|
|
|
}
|
|
|
|
|
|
|
|
// The length of the path back to the root is the current
|
|
|
|
// level.
|
|
|
|
path.len() as int
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
if !status { return status }
|
2012-05-15 17:21:35 -05:00
|
|
|
|
|
|
|
// 2. Each tree edge connects vertices whose BFS levels differ by
|
|
|
|
// exactly one.
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
log(info, ~"Verifying tree edges...");
|
2012-05-15 17:21:35 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
let status = do tree.alli() |k, parent| {
|
2012-05-22 17:29:49 -05:00
|
|
|
if parent != root && parent != -1i64 {
|
2012-05-15 17:21:35 -05:00
|
|
|
level[parent] == level[k] - 1
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
if !status { return status }
|
2012-05-15 17:21:35 -05:00
|
|
|
|
|
|
|
// 3. Every edge in the input list has vertices with levels that
|
|
|
|
// differ by at most one or that both are not in the BFS tree.
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
log(info, ~"Verifying graph edges...");
|
2012-05-15 17:21:35 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
let status = do edges.all() |e| {
|
2012-05-15 17:21:35 -05:00
|
|
|
let (u, v) = e;
|
|
|
|
|
|
|
|
abs(level[u] - level[v]) <= 1
|
|
|
|
};
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
if !status { return status }
|
2012-05-15 17:21:35 -05:00
|
|
|
|
|
|
|
// 4. The BFS tree spans an entire connected component's vertices.
|
|
|
|
|
|
|
|
// This is harder. We'll skip it for now...
|
|
|
|
|
|
|
|
// 5. A node and its parent are joined by an edge of the original
|
|
|
|
// graph.
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
log(info, ~"Verifying tree and graph edges...");
|
2012-05-15 17:21:35 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
let status = do par::alli(tree) |u, v| {
|
2012-05-22 17:29:49 -05:00
|
|
|
let u = u as node_id;
|
|
|
|
if v == -1i64 || u == root {
|
2012-05-15 17:21:35 -05:00
|
|
|
true
|
|
|
|
}
|
|
|
|
else {
|
2012-05-22 17:29:49 -05:00
|
|
|
edges.contains((u, v)) || edges.contains((v, u))
|
2012-05-15 17:21:35 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
if !status { return status }
|
2012-05-15 17:21:35 -05:00
|
|
|
|
|
|
|
// If we get through here, all the tests passed!
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn main(args: ~[~str]) {
|
|
|
|
let args = if os::getenv(~"RUST_BENCH").is_some() {
|
|
|
|
~[~"", ~"15", ~"48"]
|
2012-05-24 00:53:50 -05:00
|
|
|
} else if args.len() <= 1u {
|
2012-07-14 00:57:48 -05:00
|
|
|
~[~"", ~"10", ~"16"]
|
2012-05-24 00:53:50 -05:00
|
|
|
} else {
|
|
|
|
args
|
|
|
|
};
|
|
|
|
|
|
|
|
let scale = uint::from_str(args[1]).get();
|
|
|
|
let num_keys = uint::from_str(args[2]).get();
|
2012-05-16 17:45:21 -05:00
|
|
|
let do_validate = false;
|
2012-05-30 17:45:29 -05:00
|
|
|
let do_sequential = true;
|
2012-05-14 18:54:43 -05:00
|
|
|
|
|
|
|
let start = time::precise_time_s();
|
|
|
|
let edges = make_edges(scale, 16u);
|
|
|
|
let stop = time::precise_time_s();
|
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
io::stdout().write_line(fmt!{"Generated %? edges in %? seconds.",
|
|
|
|
vec::len(edges), stop - start});
|
2012-05-14 18:54:43 -05:00
|
|
|
|
|
|
|
let start = time::precise_time_s();
|
|
|
|
let graph = make_graph(1u << scale, edges);
|
|
|
|
let stop = time::precise_time_s();
|
|
|
|
|
|
|
|
let mut total_edges = 0u;
|
2012-06-30 18:19:07 -05:00
|
|
|
vec::each(graph, |edges| { total_edges += edges.len(); true });
|
2012-05-14 18:54:43 -05:00
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
io::stdout().write_line(fmt!{"Generated graph with %? edges in %? seconds.",
|
2012-05-14 18:54:43 -05:00
|
|
|
total_edges / 2u,
|
2012-07-30 18:01:07 -05:00
|
|
|
stop - start});
|
2012-05-15 17:21:35 -05:00
|
|
|
|
2012-05-16 17:45:21 -05:00
|
|
|
let mut total_seq = 0.0;
|
|
|
|
let mut total_par = 0.0;
|
|
|
|
|
2012-05-30 17:32:19 -05:00
|
|
|
let graph_arc = arc::arc(copy graph);
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do gen_search_keys(graph, num_keys).map() |root| {
|
2012-07-14 00:57:48 -05:00
|
|
|
io::stdout().write_line(~"");
|
2012-07-30 18:01:07 -05:00
|
|
|
io::stdout().write_line(fmt!{"Search key: %?", root});
|
2012-05-15 17:21:35 -05:00
|
|
|
|
2012-05-16 17:54:50 -05:00
|
|
|
if do_sequential {
|
2012-05-16 17:45:21 -05:00
|
|
|
let start = time::precise_time_s();
|
2012-05-16 17:54:50 -05:00
|
|
|
let bfs_tree = bfs(graph, root);
|
2012-05-16 17:45:21 -05:00
|
|
|
let stop = time::precise_time_s();
|
2012-05-16 17:52:00 -05:00
|
|
|
|
2012-05-16 17:54:50 -05:00
|
|
|
//total_seq += stop - start;
|
2012-05-16 17:52:00 -05:00
|
|
|
|
2012-05-16 17:54:50 -05:00
|
|
|
io::stdout().write_line(
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"Sequential BFS completed in %? seconds.",
|
|
|
|
stop - start});
|
2012-05-16 17:54:50 -05:00
|
|
|
|
|
|
|
if do_validate {
|
|
|
|
let start = time::precise_time_s();
|
|
|
|
assert(validate(edges, root, bfs_tree));
|
|
|
|
let stop = time::precise_time_s();
|
|
|
|
|
|
|
|
io::stdout().write_line(
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"Validation completed in %? seconds.",
|
|
|
|
stop - start});
|
2012-05-16 17:54:50 -05:00
|
|
|
}
|
|
|
|
|
2012-05-16 17:52:00 -05:00
|
|
|
let start = time::precise_time_s();
|
2012-05-16 17:54:50 -05:00
|
|
|
let bfs_tree = bfs2(graph, root);
|
2012-05-16 17:52:00 -05:00
|
|
|
let stop = time::precise_time_s();
|
2012-05-16 17:45:21 -05:00
|
|
|
|
2012-05-16 17:54:50 -05:00
|
|
|
total_seq += stop - start;
|
|
|
|
|
|
|
|
io::stdout().write_line(
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"Alternate Sequential BFS completed in %? seconds.",
|
|
|
|
stop - start});
|
2012-05-16 17:54:50 -05:00
|
|
|
|
|
|
|
if do_validate {
|
|
|
|
let start = time::precise_time_s();
|
|
|
|
assert(validate(edges, root, bfs_tree));
|
|
|
|
let stop = time::precise_time_s();
|
|
|
|
|
|
|
|
io::stdout().write_line(
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"Validation completed in %? seconds.",
|
|
|
|
stop - start});
|
2012-05-16 17:54:50 -05:00
|
|
|
}
|
2012-05-16 17:45:21 -05:00
|
|
|
}
|
2012-05-16 17:54:50 -05:00
|
|
|
|
2012-05-16 17:45:21 -05:00
|
|
|
let start = time::precise_time_s();
|
2012-05-30 17:32:19 -05:00
|
|
|
let bfs_tree = pbfs(graph_arc, root);
|
2012-05-16 17:45:21 -05:00
|
|
|
let stop = time::precise_time_s();
|
|
|
|
|
|
|
|
total_par += stop - start;
|
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
io::stdout().write_line(fmt!{"Parallel BFS completed in %? seconds.",
|
|
|
|
stop - start});
|
2012-05-16 17:45:21 -05:00
|
|
|
|
|
|
|
if do_validate {
|
|
|
|
let start = time::precise_time_s();
|
|
|
|
assert(validate(edges, root, bfs_tree));
|
|
|
|
let stop = time::precise_time_s();
|
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
io::stdout().write_line(fmt!{"Validation completed in %? seconds.",
|
|
|
|
stop - start});
|
2012-05-16 17:45:21 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
io::stdout().write_line(~"");
|
2012-05-16 17:45:21 -05:00
|
|
|
io::stdout().write_line(
|
2012-07-30 18:01:07 -05:00
|
|
|
fmt!{"Total sequential: %? \t Total Parallel: %? \t Speedup: %?x",
|
|
|
|
total_seq, total_par, total_seq / total_par});
|
2012-05-15 17:21:35 -05:00
|
|
|
}
|