Skip to content

Commit 8a232c3

Browse files
Add tracking for in/out degree
1 parent a8282fa commit 8a232c3

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

src/cli.rs

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ pub fn main(opt: Opt) -> Result<(), Error> {
5353
let seconds: f64 = duration.as_secs() as f64;
5454
let millis: f64 = duration.subsec_nanos() as f64 * 0.000_000_001_f64;
5555
println!("Time: {:0.3}s", seconds + millis);
56+
57+
if opt.verbose {
58+
println!("Max region graph in/out-degree: {} {}",
59+
output.region_degrees.max_in_degree(),
60+
output.region_degrees.max_out_degree());
61+
if output.region_degrees.has_multidegree() {
62+
println!("Found multidegree");
63+
} else {
64+
println!("No multidegree");
65+
}
66+
}
5667
}
5768
if !opt.skip_tuples {
5869
output.dump(&opt.output_directory, tables).expect("Failed to write output");

src/output/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::io::{self, Write};
1818
use std::path::PathBuf;
1919

2020
mod dump;
21+
mod tracking;
2122
mod timely;
2223

2324

@@ -31,6 +32,7 @@ crate struct Output {
3132
restricts: FxHashMap<Point, BTreeMap<Region, BTreeSet<Loan>>>,
3233
region_live_at: FxHashMap<Point, Vec<Region>>,
3334
subset: FxHashMap<Point, BTreeMap<Region, BTreeSet<Region>>>,
35+
crate region_degrees: tracking::RegionDegrees,
3436
}
3537

3638
impl Output {
@@ -46,6 +48,7 @@ impl Output {
4648
restricts: FxHashMap::default(),
4749
region_live_at: FxHashMap::default(),
4850
subset: FxHashMap::default(),
51+
region_degrees: tracking::RegionDegrees::new(),
4952
dump_enabled,
5053
}
5154
}

src/output/timely.rs

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub(super) fn timely_dataflow(dump_enabled: bool, all_facts: AllFacts) -> Output
215215
.entry(*r1)
216216
.or_insert(BTreeSet::new())
217217
.insert(*r2);
218+
result.region_degrees.update_degrees(*r1, *r2, *location);
218219
}
219220
}
220221
});

src/output/tracking.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use crate::facts::{Point, Region};
12+
use fxhash::FxHashMap;
13+
14+
#[derive(Clone, Debug)]
15+
crate struct RegionDegrees {
16+
in_degree: FxHashMap<(Region, Point), usize>,
17+
out_degree: FxHashMap<(Region, Point), usize>,
18+
}
19+
20+
impl RegionDegrees {
21+
crate fn new() -> Self {
22+
Self {
23+
in_degree: Default::default(),
24+
out_degree: Default::default(),
25+
}
26+
}
27+
28+
crate fn update_degrees(&mut self, r1: Region, r2: Region, p: Point) {
29+
*self.in_degree.entry((r2, p)).or_insert(0) += 1;
30+
*self.out_degree.entry((r1, p)).or_insert(0) += 1;
31+
}
32+
33+
crate fn max_out_degree(&self) -> usize {
34+
*self.out_degree.values().max().unwrap_or(&0)
35+
}
36+
37+
crate fn max_in_degree(&self) -> usize {
38+
*self.in_degree.values().max().unwrap_or(&0)
39+
}
40+
41+
crate fn has_multidegree(&self) -> bool {
42+
for (region_point, in_count) in &self.in_degree {
43+
match self.out_degree.get(region_point) {
44+
Some(out_count) => if *out_count > 1 && *in_count > 1 {
45+
return true;
46+
}
47+
None => {}
48+
}
49+
}
50+
return false;
51+
}
52+
}

0 commit comments

Comments
 (0)