From d5af9dea72cfa307940f6e1904032245c71d15f2 Mon Sep 17 00:00:00 2001 From: Russel Arbore <russel.jma@gmail.com> Date: Tue, 4 Mar 2025 09:41:38 -0600 Subject: [PATCH] BFS bench add useful error messages --- juno_samples/rodinia/bfs/benches/bfs_bench.rs | 6 +++--- juno_samples/rodinia/bfs/src/graph_parser.rs | 12 +++++++----- juno_samples/rodinia/bfs/src/lib.rs | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/juno_samples/rodinia/bfs/benches/bfs_bench.rs b/juno_samples/rodinia/bfs/benches/bfs_bench.rs index dbe6db38..9c09c180 100644 --- a/juno_samples/rodinia/bfs/benches/bfs_bench.rs +++ b/juno_samples/rodinia/bfs/benches/bfs_bench.rs @@ -14,7 +14,7 @@ fn bfs_bench(c: &mut Criterion) { let mut r = runner!(bfs); let input = "data/graph4096.txt"; - let (nodes, source, edges) = parse_graph(input.into()); + let (nodes, source, edges) = parse_graph(input.into()).unwrap(); let n = nodes.len() as u64; let m = edges.len() as u64; let nodes = HerculesImmBox::from(&nodes as &[Node]); @@ -26,7 +26,7 @@ fn bfs_bench(c: &mut Criterion) { }); let input = "data/graph65536.txt"; - let (nodes, source, edges) = parse_graph(input.into()); + let (nodes, source, edges) = parse_graph(input.into()).unwrap(); let n = nodes.len() as u64; let m = edges.len() as u64; let nodes = HerculesImmBox::from(&nodes as &[Node]); @@ -38,7 +38,7 @@ fn bfs_bench(c: &mut Criterion) { }); let input = "/scratch/aaronjc4/rodinia_3.1/data/bfs/graph64M.txt"; - let (nodes, source, edges) = parse_graph(input.into()); + let (nodes, source, edges) = parse_graph(input.into()).expect("PANIC: Couldn't read input file for 64M benchmark. Currently, this benchmark uses a hard-coded path, so it can only be run on the lab machines."); let n = nodes.len() as u64; let m = edges.len() as u64; let nodes = HerculesImmBox::from(&nodes as &[Node]); diff --git a/juno_samples/rodinia/bfs/src/graph_parser.rs b/juno_samples/rodinia/bfs/src/graph_parser.rs index fecd2a3e..f761d8ea 100644 --- a/juno_samples/rodinia/bfs/src/graph_parser.rs +++ b/juno_samples/rodinia/bfs/src/graph_parser.rs @@ -11,16 +11,18 @@ pub struct Node { pub num_edges: u32, } -pub fn parse_graph(file: String) -> (Vec<Node>, u32, Vec<u32>) { - let mut file = File::open(file).expect("Error opening input file"); +pub fn parse_graph(file: String) -> Result<(Vec<Node>, u32, Vec<u32>), String> { + let mut file = File::open(file).map_err(|err| format!("Error opening input file: {}", err))?; let mut contents = String::new(); file.read_to_string(&mut contents) - .expect("Error reading input file"); + .map_err(|err| format!("Error reading input file: {}", err))?; let mut parser = nom::combinator::all_consuming(graph_parser); - let (_, result) = parser.parse(&contents).expect("Parser error"); + let (_, result) = parser + .parse(&contents) + .map_err(|err| format!("Parsing error: {}", err))?; - result + Ok(result) } fn graph_parser<'a>(text: &'a str) -> nom::IResult<&'a str, (Vec<Node>, u32, Vec<u32>)> { diff --git a/juno_samples/rodinia/bfs/src/lib.rs b/juno_samples/rodinia/bfs/src/lib.rs index f6403540..e48dfe22 100644 --- a/juno_samples/rodinia/bfs/src/lib.rs +++ b/juno_samples/rodinia/bfs/src/lib.rs @@ -36,7 +36,7 @@ fn run_bfs(nodes: &[Node], source: u32, edges: &[u32]) -> Vec<i32> { pub fn bfs_harness(args: BFSInputs) { let BFSInputs { input } = args; - let (nodes, source, edges) = parse_graph(input); + let (nodes, source, edges) = parse_graph(input).unwrap(); let costs_juno = run_bfs(&nodes, source, &edges); let costs_ref = rust_bfs::bfs(&nodes, source, &edges); -- GitLab