forked from TimelyDataflow/differential-dataflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49e70cc
commit 816858b
Showing
8 changed files
with
160 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
extern crate rand; | ||
extern crate timely; | ||
// extern crate timely_communication; | ||
extern crate differential_dataflow; | ||
|
||
use rand::{Rng, SeedableRng, StdRng}; | ||
|
||
use timely::dataflow::*; | ||
use timely::dataflow::operators::probe::Handle; | ||
|
||
use differential_dataflow::input::Input; | ||
use differential_dataflow::Collection; | ||
use differential_dataflow::operators::*; | ||
use differential_dataflow::lattice::Lattice; | ||
|
||
type Node = u32; | ||
type Edge = (Node, Node); | ||
|
||
fn main() { | ||
|
||
let nodes: u32 = std::env::args().nth(1).unwrap().parse().unwrap(); | ||
let edges: u32 = std::env::args().nth(2).unwrap().parse().unwrap(); | ||
let batch: u32 = std::env::args().nth(3).unwrap().parse().unwrap(); | ||
let rounds: u32 = std::env::args().nth(4).unwrap().parse().unwrap(); | ||
let inspect: bool = std::env::args().nth(5).unwrap() == "inspect"; | ||
|
||
let allocator = timely::communication::allocator::Thread; | ||
// let logging_config: timely::logging::LoggerConfig = Default::default(); | ||
// let timely_logging = logging_config.timely_logging; | ||
// let now = ::std::time::Instant::now(); | ||
let mut worker = timely::dataflow::scopes::Root::new(allocator); | ||
|
||
let timer = ::std::time::Instant::now(); | ||
|
||
// define BFS dataflow; return handles to roots and edges inputs | ||
let mut probe = Handle::new(); | ||
let (mut roots, mut graph) = worker.dataflow(|scope| { | ||
|
||
let (root_input, roots) = scope.new_collection(); | ||
let (edge_input, graph) = scope.new_collection(); | ||
|
||
let mut result = bfs(&graph, &roots); | ||
|
||
if !inspect { | ||
result = result.filter(|_| false); | ||
} | ||
|
||
result.map(|(_,l)| l) | ||
.consolidate() | ||
.inspect(|x| println!("\t{:?}", x)) | ||
.probe_with(&mut probe); | ||
|
||
(root_input, edge_input) | ||
}); | ||
|
||
let seed: &[_] = &[1, 2, 3, 4]; | ||
let mut rng1: StdRng = SeedableRng::from_seed(seed); // rng for edge additions | ||
let mut rng2: StdRng = SeedableRng::from_seed(seed); // rng for edge deletions | ||
|
||
roots.insert(0); | ||
roots.close(); | ||
|
||
println!("performing BFS on {} nodes, {} edges:", nodes, edges); | ||
|
||
if worker.index() == 0 { | ||
for _ in 0 .. edges { | ||
graph.insert((rng1.gen_range(0, nodes), rng1.gen_range(0, nodes))); | ||
} | ||
} | ||
|
||
println!("{:?}\tloaded", timer.elapsed()); | ||
|
||
graph.advance_to(1); | ||
graph.flush(); | ||
worker.step_while(|| probe.less_than(graph.time())); | ||
|
||
println!("{:?}\tstable", timer.elapsed()); | ||
|
||
for round in 0 .. rounds { | ||
for element in 0 .. batch { | ||
if worker.index() == 0 { | ||
graph.insert((rng1.gen_range(0, nodes), rng1.gen_range(0, nodes))); | ||
graph.remove((rng2.gen_range(0, nodes), rng2.gen_range(0, nodes))); | ||
} | ||
graph.advance_to(2 + round * batch + element); | ||
} | ||
graph.flush(); | ||
|
||
let timer2 = ::std::time::Instant::now(); | ||
worker.step_while(|| probe.less_than(&graph.time())); | ||
|
||
if worker.index() == 0 { | ||
let elapsed = timer2.elapsed(); | ||
println!("{:?}\t{:?}:\t{}", timer.elapsed(), round, elapsed.as_secs() * 1000000000 + (elapsed.subsec_nanos() as u64)); | ||
} | ||
} | ||
println!("finished; elapsed: {:?}", timer.elapsed()); | ||
|
||
} | ||
|
||
// returns pairs (n, s) indicating node n can be reached from a root in s steps. | ||
fn bfs<G: Scope>(edges: &Collection<G, Edge>, roots: &Collection<G, Node>) -> Collection<G, (Node, u32)> | ||
where G::Timestamp: Lattice+Ord { | ||
|
||
// initialize roots as reaching themselves at distance 0 | ||
let nodes = roots.map(|x| (x, 0)); | ||
|
||
// repeatedly update minimal distances each node can be reached from each root | ||
nodes.iterate(|inner| { | ||
|
||
let edges = edges.enter(&inner.scope()); | ||
let nodes = nodes.enter(&inner.scope()); | ||
|
||
inner.join_map(&edges, |_k,l,d| (*d, l+1)) | ||
.concat(&nodes) | ||
.group(|_, s, t| t.push((*s[0].0, 1))) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
book |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters