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
// extern crate rand;
// // extern crate time;
// extern crate getopts;
// extern crate timely;
// extern crate graph_map;
// extern crate differential_dataflow;
// // extern crate vec_map;
// use std::time::Instant;
// use std::hash::Hash;
// use std::mem;
// use rand::{Rng, SeedableRng, StdRng};
// use timely::dataflow::*;
// use timely::dataflow::operators::*;
// use differential_dataflow::Collection;
// use differential_dataflow::collection::LeastUpperBound;
// use differential_dataflow::operators::*;
// use differential_dataflow::operators::join::JoinUnsigned;
// use differential_dataflow::operators::group::GroupUnsigned;
// use graph_map::GraphMMap;
// // use vec_map::VecMap;
// type Node = u32;
// type Edge = (Node, Node);
// fn main() {
// // snag a filename to use for the input graph.
// let filename = std::env::args().nth(1).unwrap();
// timely::execute_from_args(std::env::args().skip(1), move |computation| {
// let peers = computation.peers();
// let index = computation.index();
// // // What you might do if you used GraphMMap:
// let graph = GraphMMap::new(&filename);
// let (mut input, probe) = computation.scoped::<u64,_,_>(|scope| {
// let (input, stream) = scope.new_input();
// let roots = Collection::new(vec![(1,1)].into_iter().to_stream(scope));
// let graph = Collection::new(stream);
// let probe = _reach(&graph, &roots).inner.probe().0;
// // let probe = _connected_components(&graph).inner.probe().0;
// // let probe = _bfs(&graph, &roots).inner.probe().0;
// (input, probe)
// });
// let timer = Instant::now();
// for node in 0..graph.nodes() {
// if node % peers == index {
// for &edge in graph.edges(node) {
// input.send(((node as u32, edge), 1));
// }
// }
// }
// input.advance_to(1);
// while probe.lt(input.time()) { computation.step(); }
// println!("loaded: {:?}", timer.elapsed());
// let mut latencies = Vec::with_capacity(1100);
// let seed: &[_] = &[1, 2, 3, 4];
// let mut rng: StdRng = SeedableRng::from_seed(seed); // rng for edge additions
// let mut counts = 0;
// for count in 0..latencies.capacity() {
// //graph.nodes() {
// let mut updates = Vec::with_capacity(1);
// while updates.len() < updates.capacity() {
// let node = rng.gen_range(0, graph.nodes());
// updates.push(node);
// }
// let start = Instant::now();
// if count % peers == index {
// for &node in &updates {
// for &edge in graph.edges(node) {
// input.send(((node as u32, edge), -1));
// counts += 1;
// }
// }
// }
// input.advance_to((count as u64) + 2);
// while probe.lt(input.time()) { computation.step(); }
// latencies.push(start.elapsed());
// }
// let mut latencies = latencies.into_iter().skip(100).collect::<Vec<_>>();
// let mut sum = 0;
// for &time in &latencies {
// sum += time.as_secs() * 1000000000 + time.subsec_nanos() as u64;
// }
// println!("average latency: {}; edges: {}", sum / latencies.len() as u64, counts);
// if index == 0 {
// latencies.sort();
// for &time in &latencies {
// let nanos = time.as_secs() * 1000000000 + time.subsec_nanos() as u64;
// println!("{}", nanos as f64 / 1000.0);
// }
// }
// }).unwrap();
// }
// // returns pairs (n, s) indicating node n can be reached from a root in s steps.
// fn _reach<G: Scope>(edges: &Collection<G, Edge>, roots: &Collection<G, Node>) -> Collection<G, Node>
// where G::Timestamp: LeastUpperBound {
// // initialize roots as reaching themselves at distance 0
// // repeatedly update minimal distances each node can be reached from each root
// roots.iterate(|inner| {
// let edges = edges.enter(&inner.scope());
// let nodes = roots.enter(&inner.scope());
// edges.semijoin_u(&inner)
// .map(|(_,d)| d)
// .concat(&nodes)
// .distinct()
// })
// }
// fn _connected_components<G: Scope>(edges: &Collection<G, Edge>) -> Collection<G, (Node, Node)>
// where G::Timestamp: LeastUpperBound+Hash {
// // each edge (x,y) means that we need at least a label for the min of x and y.
// let nodes = edges.map_in_place(|pair| {
// let min = std::cmp::min(pair.0, pair.1);
// *pair = (min, min);
// })
// .consolidate_by(|x| x.0);
// // each edge should exist in both directions.
// let edges = edges.map_in_place(|x| mem::swap(&mut x.0, &mut x.1))
// .concat(&edges);
// // don't actually use these labels, just grab the type
// nodes.filter(|_| false)
// .iterate(|inner| {
// let edges = edges.enter(&inner.scope());
// let nodes = nodes.enter_at(&inner.scope(), |r| 256 * (64 - (r.0).0.leading_zeros() as u64));
// inner.join_map_u(&edges, |_k,l,d| (*d,*l))
// .concat(&nodes)
// .group_u(|_, mut s, t| { t.push((*s.peek().unwrap().0, 1)); } )
// })
// }
// // 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: LeastUpperBound {
// // 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_u(&edges, |_k,l,d| (*d, l+1))
// .concat(&nodes)
// .group_u(|_, s, t| t.push((*s.peek().unwrap().0, 1)))
// })
// }