wcc/
wcc.rs

1fn main() {
2    let (input_graph, output_file) = {
3        let args = std::env::args().skip(1).collect::<Vec<_>>();
4
5        if args.len() != 1 && args.len() != 2 {
6            println!("Usage: wcc <converted graph directory> [output_file]");
7            return;
8        }
9
10        let output = {
11            if args.len() == 2 {
12                Some(args[1].clone())
13            } else {
14                None
15            }
16        };
17
18        (args[0].clone(), output)
19    };
20
21    let graph = graph_csr::Graph::<u32>::load_graph(&input_graph).unwrap();
22
23    let mut compute_graph = graph_csr::compute::ComputeGraph::<u32, u32>::new(&graph);
24
25    // Initialize
26    compute_graph.fill_active(true);
27    for i in 0..graph.n_nodes() {
28        compute_graph.set_data(i, i as u32);
29    }
30    compute_graph.step(); // Set data
31
32    let mut i = 0;
33    while compute_graph.n_active() > 0 {
34        let time_start = std::time::Instant::now();
35        compute_graph.push(|src, dst| graph_csr::compute::helper::atomic_min(src, dst, |v| v));
36        let time_end = std::time::Instant::now();
37        compute_graph.step();
38
39        i += 1;
40        println!(
41            "Iteration {} took {}ms",
42            i,
43            (time_end - time_start).as_millis()
44        );
45    }
46
47    // Print results
48    print!("[ ");
49    for (idx, data) in compute_graph
50        .get_data_as_slice()
51        .iter()
52        .enumerate()
53        .take(30)
54    {
55        print!(
56            "{}:{}, ",
57            idx,
58            data.load(std::sync::atomic::Ordering::Relaxed)
59        );
60    }
61    println!("]");
62
63    // Save file
64    if let Some(output_file) = output_file {
65        println!("Saving file to {}", output_file);
66        compute_graph.save_data_to_file(&output_file).unwrap();
67    }
68}