From 94950efe71d9cbf4ef1840eafd9c8799b7106966 Mon Sep 17 00:00:00 2001
From: Aaron Councilman <aaronjc4@illinois.edu>
Date: Tue, 4 Mar 2025 13:53:07 -0600
Subject: [PATCH] Load inputs once in benches

---
 juno_samples/rodinia/bfs/benches/bfs_bench.rs |  41 ++-----
 juno_samples/rodinia/cfd/benches/cfd_bench.rs | 112 +++++++++---------
 2 files changed, 67 insertions(+), 86 deletions(-)

diff --git a/juno_samples/rodinia/bfs/benches/bfs_bench.rs b/juno_samples/rodinia/bfs/benches/bfs_bench.rs
index f87b4e09..ea8ba0ed 100644
--- a/juno_samples/rodinia/bfs/benches/bfs_bench.rs
+++ b/juno_samples/rodinia/bfs/benches/bfs_bench.rs
@@ -13,41 +13,22 @@ fn bfs_bench(c: &mut Criterion) {
 
     let mut r = runner!(bfs);
 
-    group.bench_function("bfs bench 4096", |b| {
-        let input = "data/graph4096.txt";
-        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]);
-        let edges = HerculesImmBox::from(&edges as &[u32]);
-        b.iter(|| {
-            async_std::task::block_on(async { r.run(n, m, nodes.to(), source, edges.to()).await });
-        })
-    });
-
-    group.bench_function("bfs bench 65536", |b| {
-        let input = "data/graph65536.txt";
-        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]);
-        let edges = HerculesImmBox::from(&edges as &[u32]);
-        b.iter(|| {
-            async_std::task::block_on(async { r.run(n, m, nodes.to(), source, edges.to()).await });
-        })
-    });
-
-    group.bench_function("bfs bench 64M", |b| {
-        let input = "/scratch/aaronjc4/rodinia_3.1/data/bfs/graph64M.txt";
+    let mut bench = |name, input: &'_ str| {
         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]);
         let edges = HerculesImmBox::from(&edges as &[u32]);
-        b.iter(|| {
-            async_std::task::block_on(async { r.run(n, m, nodes.to(), source, edges.to()).await });
-        })
-    });
+        group.bench_function(name, |b| {
+            b.iter(|| {
+                async_std::task::block_on(async { r.run(n, m, nodes.to(), source, edges.to()).await });
+            })
+        });
+    };
+
+    bench("bfs bench 4096", "data/graph4096.txt");
+    bench("bfs bench 65536", "data/graph65536.txt");
+    bench("bfs bench 64M", "/scratch/aaronjc4/rodinia_3.1/data/bfs/graph64M.txt");
 }
 
 criterion_group!(benches, bfs_bench);
diff --git a/juno_samples/rodinia/cfd/benches/cfd_bench.rs b/juno_samples/rodinia/cfd/benches/cfd_bench.rs
index aa6d7727..5b4db044 100644
--- a/juno_samples/rodinia/cfd/benches/cfd_bench.rs
+++ b/juno_samples/rodinia/cfd/benches/cfd_bench.rs
@@ -13,38 +13,38 @@ fn cfd_bench(c: &mut Criterion) {
     group.sample_size(10);
 
     let mut euler_bench = |name, data_file, iterations| {
-        group.bench_function(name, |b| {
-            let mut r = runner!(euler);
-            let block_size = 16;
-            let FarFieldConditions {
-                ff_variable,
-                ff_fc_momentum_x,
-                ff_fc_momentum_y,
-                ff_fc_momentum_z,
-                ff_fc_density_energy,
-            } = set_far_field_conditions();
-            let GeometryData {
-                nelr,
-                areas,
-                elements_surrounding_elements,
-                normals,
-            } = read_domain_geometry(data_file, block_size).expect("PANIC: Couldn't read input for CFD benchmark. Currently, the path for the largest CFD benchmark is hard-coded, so it can only be run on the lab machines.");
-            let mut variables = initialize_variables(nelr, &ff_variable);
+        let mut r = runner!(euler);
+        let block_size = 16;
+        let FarFieldConditions {
+            ff_variable,
+            ff_fc_momentum_x,
+            ff_fc_momentum_y,
+            ff_fc_momentum_z,
+            ff_fc_density_energy,
+        } = set_far_field_conditions();
+        let GeometryData {
+            nelr,
+            areas,
+            elements_surrounding_elements,
+            normals,
+        } = read_domain_geometry(data_file, block_size).expect("PANIC: Couldn't read input for CFD benchmark. Currently, the path for the largest CFD benchmark is hard-coded, so it can only be run on the lab machines.");
+        let mut variables = initialize_variables(nelr, &ff_variable);
 
-            let mut v_density = HerculesMutBox::from(variables.density.as_mut_slice());
-            let mut v_momentum_x = HerculesMutBox::from(variables.momentum.x.as_mut_slice());
-            let mut v_momentum_y = HerculesMutBox::from(variables.momentum.y.as_mut_slice());
-            let mut v_momentum_z = HerculesMutBox::from(variables.momentum.z.as_mut_slice());
-            let mut v_energy = HerculesMutBox::from(variables.energy.as_mut_slice());
+        let mut v_density = HerculesMutBox::from(variables.density.as_mut_slice());
+        let mut v_momentum_x = HerculesMutBox::from(variables.momentum.x.as_mut_slice());
+        let mut v_momentum_y = HerculesMutBox::from(variables.momentum.y.as_mut_slice());
+        let mut v_momentum_z = HerculesMutBox::from(variables.momentum.z.as_mut_slice());
+        let mut v_energy = HerculesMutBox::from(variables.energy.as_mut_slice());
 
-            let areas = HerculesImmBox::from(areas.as_slice());
-            let elements_surrounding_elements =
-                HerculesImmBox::from(elements_surrounding_elements.as_slice());
+        let areas = HerculesImmBox::from(areas.as_slice());
+        let elements_surrounding_elements =
+            HerculesImmBox::from(elements_surrounding_elements.as_slice());
 
-            let normals_x = HerculesImmBox::from(normals.x.as_slice());
-            let normals_y = HerculesImmBox::from(normals.y.as_slice());
-            let normals_z = HerculesImmBox::from(normals.z.as_slice());
+        let normals_x = HerculesImmBox::from(normals.x.as_slice());
+        let normals_y = HerculesImmBox::from(normals.y.as_slice());
+        let normals_z = HerculesImmBox::from(normals.z.as_slice());
 
+        group.bench_function(name, |b| {
             b.iter(|| {
                 async_std::task::block_on(async {
                     r.run(
@@ -91,38 +91,38 @@ fn cfd_bench(c: &mut Criterion) {
     );
 
     let mut pre_euler_bench = |name, data_file, iterations| {
-        group.bench_function(name, |b| {
-            let mut r = runner!(pre_euler);
-            let block_size = 16;
-            let FarFieldConditions {
-                ff_variable,
-                ff_fc_momentum_x,
-                ff_fc_momentum_y,
-                ff_fc_momentum_z,
-                ff_fc_density_energy,
-            } = set_far_field_conditions();
-            let GeometryData {
-                nelr,
-                areas,
-                elements_surrounding_elements,
-                normals,
-            } = read_domain_geometry(data_file, block_size).expect("PANIC: Couldn't read input for CFD benchmark. Currently, the path for the largest CFD benchmark is hard-coded, so it can only be run on the lab machines.");
-            let mut variables = initialize_variables(nelr, &ff_variable);
+        let mut r = runner!(pre_euler);
+        let block_size = 16;
+        let FarFieldConditions {
+            ff_variable,
+            ff_fc_momentum_x,
+            ff_fc_momentum_y,
+            ff_fc_momentum_z,
+            ff_fc_density_energy,
+        } = set_far_field_conditions();
+        let GeometryData {
+            nelr,
+            areas,
+            elements_surrounding_elements,
+            normals,
+        } = read_domain_geometry(data_file, block_size).expect("PANIC: Couldn't read input for CFD benchmark. Currently, the path for the largest CFD benchmark is hard-coded, so it can only be run on the lab machines.");
+        let mut variables = initialize_variables(nelr, &ff_variable);
 
-            let mut v_density = HerculesMutBox::from(variables.density.as_mut_slice());
-            let mut v_momentum_x = HerculesMutBox::from(variables.momentum.x.as_mut_slice());
-            let mut v_momentum_y = HerculesMutBox::from(variables.momentum.y.as_mut_slice());
-            let mut v_momentum_z = HerculesMutBox::from(variables.momentum.z.as_mut_slice());
-            let mut v_energy = HerculesMutBox::from(variables.energy.as_mut_slice());
+        let mut v_density = HerculesMutBox::from(variables.density.as_mut_slice());
+        let mut v_momentum_x = HerculesMutBox::from(variables.momentum.x.as_mut_slice());
+        let mut v_momentum_y = HerculesMutBox::from(variables.momentum.y.as_mut_slice());
+        let mut v_momentum_z = HerculesMutBox::from(variables.momentum.z.as_mut_slice());
+        let mut v_energy = HerculesMutBox::from(variables.energy.as_mut_slice());
 
-            let areas = HerculesImmBox::from(areas.as_slice());
-            let elements_surrounding_elements =
-                HerculesImmBox::from(elements_surrounding_elements.as_slice());
+        let areas = HerculesImmBox::from(areas.as_slice());
+        let elements_surrounding_elements =
+            HerculesImmBox::from(elements_surrounding_elements.as_slice());
 
-            let normals_x = HerculesImmBox::from(normals.x.as_slice());
-            let normals_y = HerculesImmBox::from(normals.y.as_slice());
-            let normals_z = HerculesImmBox::from(normals.z.as_slice());
+        let normals_x = HerculesImmBox::from(normals.x.as_slice());
+        let normals_y = HerculesImmBox::from(normals.y.as_slice());
+        let normals_z = HerculesImmBox::from(normals.z.as_slice());
 
+        group.bench_function(name, |b| {
             b.iter(|| {
                 async_std::task::block_on(async {
                     r.run(
-- 
GitLab