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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
crate::ix!();
#[cfg(target_feature="mpi")]
pub fn kdd_exp_main<GH>(
rank: i32,
size: i32,
world: &dyn Communicator)
-> Result<(),BetweennessCentralityError>
where GH: BccGraphHashInterface,
Graph<GH>: HasEdge + NumEdges
{
let mut args = std::env::args();
// -----------------------------[these are for scanning]
let mut num_edges: usize = 0;
let mut num_threads: usize = 0;
let mut rand_seed: i32 = 0;
let mut t1: i32 = 0;
let mut t2: i32 = 0;
let mut t3: i32 = 0;
let mut t4: i32 = 0;
let mut do_icent: bool = false;
let mut do_bcc_icent: bool = false;
let mut ext_edges: bool = false;
let mut do_fast_brandes: bool = false;
let mut do_brandes: bool = false;
let mut do_qube: bool = false;
let mut do_inc_qube: bool = false;
let mut op: Operation = Operation::default();
// for qube and incremental qube, old
// implementation will be used, and no
// parallelization
//
let mut path_vec: Vec<String> = vec![];
let mut edge_vec2: Vec<Vec<Edge>> = vec![];
let mut brandes_tm_vec: Vec<Duration> = vec![];
let universe = mpi::initialize().unwrap();
let world = universe.world();
let mut status: MPI_Status = zeroed!();;
if args.len() != 2 {
if rank == 0 {
debug!("Pass one parameter, path with experiment details");
debug!("deletion");
debug!("num_edges, num_threads, rand_seed");
debug!("external_edges, do_icent, do_bcc_icent");
debug!("do_fast_brandes, do_brandes, do_qube, do_inc_qube");
debug!("list of graph paths");
debug!("if external_edges is nonzero a file with graph_name.edges is expected");
debug!("external edges are assumed to be in the graph");
debug!("external edges should not be bridges");
debug!("if deletion is 1, bcc_icent with deletions will be invoked");
}
return Ok(());
} else {
{
let mut fin = std::fs::File::open(
args.nth(1).unwrap()
).unwrap().bytes().map(|ch| ch.unwrap());
let mut del_int: i32 = read!("{}",fin);
if del_int == 1 {
op = Operation::Deletion;
} else {
op = Operation::Insertion;
}
text_io::scan!(fin => "{}, {}, {}", num_edges, num_threads, rand_seed);
text_io::scan!(fin => "{}, {}, {}", t1, t2, t3);
ext_edges = (t1 != 0);
do_icent = (t2 != 0);
do_bcc_icent = (t3 != 0);
text_io::scan!(fin => "{}, {}, {}, {}", t1, t2, t3, t4);
do_fast_brandes = (t1 != 0);
do_brandes = (t2 != 0);
do_qube = (t3 != 0);
do_inc_qube = (t4 != 0);
while let Ok(path) = try_read!("{}", fin) {
path_vec.push(path);
}
}
// fill edges, read from file if needed
//
if ext_edges {
// these are edges in the graph, and
// have to be removed then inserted in
// order
//
for i in 0..path_vec.len() {
let mut edge_vec: Vec<Edge> = vec![];
let edge_file_path: String
= format!("{}.edges", path_vec[i]);
let fin = File::open(&edge_file_path)?;
let mut v1: usize = 0;
let mut v2: usize = 0;
for line in io::BufReader::new(fin).lines() {
if let Ok(line) = line {
let mut parts = line.split(" ");
v1 = parts.nth(0).unwrap().parse::<usize>()?;
v2 = parts.nth(1).unwrap().parse::<usize>()?;
edge_vec.push(Edge::new_with_ids(v1,v2));
}
}
edge_vec2.push(edge_vec);
}
} else {
for parents in 0..path_vec.len() {
let mut graph = arcmut![Graph::<GH>::from_filename(&path_vec[parents])];
let mut edge_vec: Vec<Edge> = vec![];
// gen_rand_edges(num_edges, graph, edge_vec);
// edge_vec2.push_back(edge_vec);
if rank == 0 {
let mut rng = WyRand::new_seed(rand_seed.try_into()?);
if let mut graph = graph.lock()? {
// master generates random
// edges and sends to everyone
//
edge_vec = match op {
Operation::Insertion => gen_rand_edges(&mut rng, num_edges, &mut *graph)?,
Operation::Deletion => gen_rand_edges_deletions::<Graph<GH>,GH>(num_edges, &mut *graph),
};
// TMP code to make sure new
// random edges are
// generated.. Safely remove!
//
// for(int re = 0; re < edge_vec.len(); ++re) {
// debug!("e(%d, %d)", edge_vec[re].first, edge_vec[re].second);
// }
//
// debug!("RANK[%d] -- e[0]: %u %u", rank, edge_vec[4].first, edge_vec[4].second);
//
for parents in 1..size {
/*
world.process_at_rank(parents)
.send_with_tag(&edge_vec,0);
*/
unsafe {
MPI_Send(
edge_vec.as_ptr() as *const libc::c_void,
(edge_vec.len() * size_of::<Edge>()).try_into()?,
RSMPI_UINT8_T,
parents,
0,
RSMPI_COMM_WORLD
);
}
}
}
} else {
// slaves get random edges
// from the master
//
edge_vec.resize(
num_edges,
Edge::default()
);
/*
world.process_at_rank(0)
.send_with_tag(&edge_vec, MPI_ANY_TAG);
*/
unsafe {
MPI_Send(
edge_vec.as_ptr() as *const libc::c_void,
(edge_vec.len() * size_of::<Edge>()).try_into()?,
RSMPI_UINT8_T,
0,
MPI_ANY_TAG,
RSMPI_COMM_WORLD
);
}
// debug!("RANK[%d] -- e[0]: %u %u", rank, edge_vec[4].first, edge_vec[4].second);
}
edge_vec2.push(edge_vec);
}
}
}
brandes_tm_vec.resize(
path_vec.len(),
Duration::from_secs(1)
);
let mut tm: Timer = default!();
let mut scores: Vec<f64> = vec![];
let mut brandes_time = Duration::from_secs(0);
if do_bcc_icent {
if rank == 0 {
debug!("");
debug!(
"Starting BiconnectedComponents+iCentral [{} threads] [{}]...",
num_threads,
match op == Operation::Deletion {
true => "Deletion",
false => "Insertion"
}
);
debug!("========================================");
}
for i in 0..path_vec.len() {
let mut graph = Graph::<GH>::from_filename(&path_vec[i]);
let config = TimingUpdateConfig {
do_brandes: false,
del_edge: ext_edges,
num_threads,
op,
limit_sources: None
};
timing_update_bc_graph(
&mut graph,
&mut edge_vec2[i],
&CompType::BiconnectedComponent,
Some(brandes_tm_vec[i]),
config
);
// synchronization barrier so that no
// one starts next graph before others
//
world.barrier();
}
}
Ok(())
}