From cf3f58cf830affa9e0616ace103aa8c213bff481 Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:28:14 +0100 Subject: [PATCH 01/11] add simple kernel --- honeycomb-kernels/src/lib.rs | 1 + honeycomb-kernels/src/shift/mod.rs | 1 + .../src/shift/neighbors_average.rs | 45 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 honeycomb-kernels/src/shift/mod.rs create mode 100644 honeycomb-kernels/src/shift/neighbors_average.rs diff --git a/honeycomb-kernels/src/lib.rs b/honeycomb-kernels/src/lib.rs index ecb0f1b3b..9551f7530 100644 --- a/honeycomb-kernels/src/lib.rs +++ b/honeycomb-kernels/src/lib.rs @@ -22,5 +22,6 @@ // ------ MODULE DECLARATIONS pub mod grisubal; +pub mod shift; pub mod splits; pub mod triangulation; diff --git a/honeycomb-kernels/src/shift/mod.rs b/honeycomb-kernels/src/shift/mod.rs new file mode 100644 index 000000000..1b0245ab0 --- /dev/null +++ b/honeycomb-kernels/src/shift/mod.rs @@ -0,0 +1 @@ +mod neighbors_average; diff --git a/honeycomb-kernels/src/shift/neighbors_average.rs b/honeycomb-kernels/src/shift/neighbors_average.rs new file mode 100644 index 000000000..56724da94 --- /dev/null +++ b/honeycomb-kernels/src/shift/neighbors_average.rs @@ -0,0 +1,45 @@ +use honeycomb_core::{ + cmap::{CMap2, DartIdType, Orbit2, OrbitPolicy, VertexIdType, NULL_DART_ID}, + prelude::{CoordsFloat, Vertex2}, + stm::atomically, +}; + +pub fn shift(cmap: &CMap2) { + // fetch all vertices that are not on the boundary of the map + let vertices: Vec = cmap + .fetch_vertices() + .identifiers + .into_iter() + .filter(|v| { + !Orbit2::new(&cmap, OrbitPolicy::Vertex, *v as DartIdType) + .any(|d| cmap.beta::<2>(d) == NULL_DART_ID) + }) + .collect(); + + let neighbors: Vec> = vertices + .iter() + .map(|v| { + Orbit2::new(&cmap, OrbitPolicy::Vertex, *v as DartIdType) + .map(|d| cmap.vertex_id(cmap.beta::<2>(d))) + .collect() + }) + .collect(); + + // main loop + vertices + .iter() + .zip(neighbors.iter()) + .for_each(|(vid, neigh)| { + atomically(|trans| { + let mut new_val: Vertex2 = Vertex2::default(); + for v in neigh { + let vertex = cmap.read_vertex(trans, *v)?.unwrap(); + new_val.0 += vertex.0; + new_val.1 += vertex.1; + } + new_val.0 /= T::from(neigh.len()).unwrap(); + new_val.1 /= T::from(neigh.len()).unwrap(); + cmap.write_vertex(trans, *vid, new_val) + }); + }); +} From fdd7912a5bf3e9ca0a4b8b6428efa697e615c91a Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:01:02 +0100 Subject: [PATCH 02/11] bench shift function --- benches/Cargo.toml | 6 +++ benches/benches/shift.rs | 28 ++++++++++++ honeycomb-kernels/Cargo.toml | 1 + honeycomb-kernels/src/shift/mod.rs | 2 + .../src/shift/neighbors_average.rs | 45 +++++++++++-------- 5 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 benches/benches/shift.rs diff --git a/benches/Cargo.toml b/benches/Cargo.toml index bb5c80ac6..28b288eb7 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -82,6 +82,12 @@ name = "grisubal-grid-size" path = "benches/grisubal/grid_size.rs" harness = false + +[[bench]] +name = "shift" +path = "benches/shift.rs" +harness = false + [[bench]] name = "triangulate-quads" path = "benches/triangulate/quads.rs" diff --git a/benches/benches/shift.rs b/benches/benches/shift.rs new file mode 100644 index 000000000..6e22c8ebc --- /dev/null +++ b/benches/benches/shift.rs @@ -0,0 +1,28 @@ +// ------ IMPORTS + +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; +use honeycomb::{kernels::shift::shift_vertices_to_neigh_avg, prelude::CMap2}; +use honeycomb_benches::FloatType; +use honeycomb_core::cmap::CMapBuilder; + +// ------ CONTENT + +pub fn criterion_benchmark(c: &mut Criterion) { + let path = "../../../meshing-samples/vtk/2D/many_quads.vtk"; + + let mut group = c.benchmark_group("shift"); + + let mut map: CMap2 = CMapBuilder::from(path).build().unwrap(); + + group.bench_function(BenchmarkId::new("to-neighbor-avg", ""), |b| { + b.iter(|| { + shift_vertices_to_neigh_avg(&map, 200); + black_box(&mut map); + }) + }); + + group.finish(); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/honeycomb-kernels/Cargo.toml b/honeycomb-kernels/Cargo.toml index ec6d71f3e..df0075d73 100644 --- a/honeycomb-kernels/Cargo.toml +++ b/honeycomb-kernels/Cargo.toml @@ -15,6 +15,7 @@ publish = true [dependencies] honeycomb-core = { workspace = true, features = ["io", "utils"] } num-traits.workspace = true +rayon = "1.10.0" thiserror.workspace = true vtkio.workspace = true diff --git a/honeycomb-kernels/src/shift/mod.rs b/honeycomb-kernels/src/shift/mod.rs index 1b0245ab0..8c52062d7 100644 --- a/honeycomb-kernels/src/shift/mod.rs +++ b/honeycomb-kernels/src/shift/mod.rs @@ -1 +1,3 @@ mod neighbors_average; + +pub use neighbors_average::shift as shift_vertices_to_neigh_avg; diff --git a/honeycomb-kernels/src/shift/neighbors_average.rs b/honeycomb-kernels/src/shift/neighbors_average.rs index 56724da94..2b17aa345 100644 --- a/honeycomb-kernels/src/shift/neighbors_average.rs +++ b/honeycomb-kernels/src/shift/neighbors_average.rs @@ -3,13 +3,14 @@ use honeycomb_core::{ prelude::{CoordsFloat, Vertex2}, stm::atomically, }; +use rayon::prelude::*; -pub fn shift(cmap: &CMap2) { +pub fn shift(cmap: &CMap2, n_rounds: usize) { // fetch all vertices that are not on the boundary of the map let vertices: Vec = cmap .fetch_vertices() .identifiers - .into_iter() + .into_par_iter() .filter(|v| { !Orbit2::new(&cmap, OrbitPolicy::Vertex, *v as DartIdType) .any(|d| cmap.beta::<2>(d) == NULL_DART_ID) @@ -17,7 +18,7 @@ pub fn shift(cmap: &CMap2) { .collect(); let neighbors: Vec> = vertices - .iter() + .par_iter() .map(|v| { Orbit2::new(&cmap, OrbitPolicy::Vertex, *v as DartIdType) .map(|d| cmap.vertex_id(cmap.beta::<2>(d))) @@ -26,20 +27,28 @@ pub fn shift(cmap: &CMap2) { .collect(); // main loop - vertices - .iter() - .zip(neighbors.iter()) - .for_each(|(vid, neigh)| { - atomically(|trans| { - let mut new_val: Vertex2 = Vertex2::default(); - for v in neigh { - let vertex = cmap.read_vertex(trans, *v)?.unwrap(); - new_val.0 += vertex.0; - new_val.1 += vertex.1; - } - new_val.0 /= T::from(neigh.len()).unwrap(); - new_val.1 /= T::from(neigh.len()).unwrap(); - cmap.write_vertex(trans, *vid, new_val) + let mut round = 0; + loop { + vertices + .iter() + .zip(neighbors.iter()) + .par_bridge() + .for_each(|(vid, neigh)| { + atomically(|trans| { + let mut new_val: Vertex2 = Vertex2::default(); + for v in neigh { + let vertex = cmap.read_vertex(trans, *v)?.unwrap(); + new_val.0 += vertex.0; + new_val.1 += vertex.1; + } + new_val.0 /= T::from(neigh.len()).unwrap(); + new_val.1 /= T::from(neigh.len()).unwrap(); + cmap.write_vertex(trans, *vid, new_val) + }); }); - }); + round += 1; + if round >= n_rounds { + break; + } + } } From 2c68d07ffe9093a33fb24cdcfc3f6f5a0936da36 Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:26:24 +0100 Subject: [PATCH 03/11] stm experimentation --- honeycomb-core/Cargo.toml | 3 ++- honeycomb-core/src/attributes/collections.rs | 2 +- honeycomb-core/src/attributes/manager.rs | 2 +- honeycomb-core/src/attributes/tests.rs | 2 +- honeycomb-core/src/attributes/traits.rs | 2 +- honeycomb-core/src/cmap/components/betas.rs | 2 +- honeycomb-core/src/cmap/components/unused.rs | 2 +- honeycomb-core/src/cmap/dim2/basic_ops.rs | 2 +- honeycomb-core/src/cmap/dim2/embed.rs | 2 +- honeycomb-core/src/cmap/dim2/links/one.rs | 2 +- honeycomb-core/src/cmap/dim2/links/two.rs | 2 +- honeycomb-core/src/cmap/dim2/sews/one.rs | 2 +- honeycomb-core/src/cmap/dim2/sews/two.rs | 2 +- honeycomb-core/src/cmap/dim2/utils.rs | 2 +- honeycomb-core/src/cmap/error.rs | 2 +- honeycomb-core/src/lib.rs | 2 +- honeycomb-kernels/src/shift/neighbors_average.rs | 2 +- 17 files changed, 18 insertions(+), 17 deletions(-) diff --git a/honeycomb-core/Cargo.toml b/honeycomb-core/Cargo.toml index c005a4879..b039c20e6 100644 --- a/honeycomb-core/Cargo.toml +++ b/honeycomb-core/Cargo.toml @@ -19,8 +19,9 @@ utils = [] # deps [dependencies] +fast-stm = { git = "https://github.com/imrn99/fast-stm.git", rev = "94a9ff5" } downcast-rs.workspace = true -loom.workspace= true +loom.workspace = true num-traits.workspace = true stm.workspace = true thiserror.workspace = true diff --git a/honeycomb-core/src/attributes/collections.rs b/honeycomb-core/src/attributes/collections.rs index d16d58307..ce2d59cca 100644 --- a/honeycomb-core/src/attributes/collections.rs +++ b/honeycomb-core/src/attributes/collections.rs @@ -10,8 +10,8 @@ use crate::{ cmap::{CMapError, CMapResult}, prelude::DartIdType, }; +use fast_stm::{atomically, StmResult, TVar, Transaction}; use num_traits::ToPrimitive; -use stm::{atomically, StmResult, TVar, Transaction}; // ------ CONTENT diff --git a/honeycomb-core/src/attributes/manager.rs b/honeycomb-core/src/attributes/manager.rs index 21a70e91a..731aec7c0 100644 --- a/honeycomb-core/src/attributes/manager.rs +++ b/honeycomb-core/src/attributes/manager.rs @@ -5,7 +5,7 @@ // ------ IMPORTS -use stm::{StmResult, Transaction}; +use fast_stm::{StmResult, Transaction}; use super::{AttributeBind, AttributeStorage, AttributeUpdate, UnknownAttributeStorage}; use crate::{ diff --git a/honeycomb-core/src/attributes/tests.rs b/honeycomb-core/src/attributes/tests.rs index 6ab44fddf..a311f3b3f 100644 --- a/honeycomb-core/src/attributes/tests.rs +++ b/honeycomb-core/src/attributes/tests.rs @@ -1,7 +1,7 @@ // ------ IMPORTS +use fast_stm::{atomically, StmError, Transaction, TransactionControl}; use loom::sync::Arc; -use stm::{atomically, StmError, Transaction, TransactionControl}; use super::{ AttrSparseVec, AttrStorageManager, AttributeBind, AttributeStorage, AttributeUpdate, diff --git a/honeycomb-core/src/attributes/traits.rs b/honeycomb-core/src/attributes/traits.rs index ead9ba67d..76b7fca50 100644 --- a/honeycomb-core/src/attributes/traits.rs +++ b/honeycomb-core/src/attributes/traits.rs @@ -10,9 +10,9 @@ use crate::{ prelude::{DartIdType, OrbitPolicy}, }; use downcast_rs::{impl_downcast, Downcast}; +use fast_stm::{atomically, StmResult, Transaction}; use std::any::Any; use std::fmt::Debug; -use stm::{atomically, StmResult, Transaction}; // ------ CONTENT diff --git a/honeycomb-core/src/cmap/components/betas.rs b/honeycomb-core/src/cmap/components/betas.rs index e58db9411..d4e4516da 100644 --- a/honeycomb-core/src/cmap/components/betas.rs +++ b/honeycomb-core/src/cmap/components/betas.rs @@ -2,7 +2,7 @@ use std::ops::{Index, IndexMut}; -use stm::{StmError, TVar, Transaction}; +use fast_stm::{StmError, TVar, Transaction}; use crate::cmap::NULL_DART_ID; diff --git a/honeycomb-core/src/cmap/components/unused.rs b/honeycomb-core/src/cmap/components/unused.rs index 5d85baada..1de378df4 100644 --- a/honeycomb-core/src/cmap/components/unused.rs +++ b/honeycomb-core/src/cmap/components/unused.rs @@ -5,7 +5,7 @@ use std::{ slice::Iter, }; -use stm::TVar; +use fast_stm::TVar; use super::identifiers::DartIdType; diff --git a/honeycomb-core/src/cmap/dim2/basic_ops.rs b/honeycomb-core/src/cmap/dim2/basic_ops.rs index 889727bf0..c1c996cf6 100644 --- a/honeycomb-core/src/cmap/dim2/basic_ops.rs +++ b/honeycomb-core/src/cmap/dim2/basic_ops.rs @@ -17,8 +17,8 @@ use crate::{ cmap::{EdgeCollection, FaceCollection, VertexCollection}, geometry::CoordsFloat, }; +use fast_stm::{atomically, StmError, Transaction}; use std::collections::{BTreeSet, VecDeque}; -use stm::{atomically, StmError, Transaction}; // ------ CONTENT diff --git a/honeycomb-core/src/cmap/dim2/embed.rs b/honeycomb-core/src/cmap/dim2/embed.rs index 2d0794a35..0ba97a92d 100644 --- a/honeycomb-core/src/cmap/dim2/embed.rs +++ b/honeycomb-core/src/cmap/dim2/embed.rs @@ -6,7 +6,7 @@ // ------ IMPORT -use stm::{StmResult, Transaction}; +use fast_stm::{StmResult, Transaction}; use crate::prelude::{AttributeBind, AttributeUpdate, CMap2, Vertex2, VertexIdType}; use crate::{ diff --git a/honeycomb-core/src/cmap/dim2/links/one.rs b/honeycomb-core/src/cmap/dim2/links/one.rs index 3c720e976..b1daa1db8 100644 --- a/honeycomb-core/src/cmap/dim2/links/one.rs +++ b/honeycomb-core/src/cmap/dim2/links/one.rs @@ -1,6 +1,6 @@ //! 1D link implementations -use stm::{atomically, StmResult, Transaction}; +use fast_stm::{atomically, StmResult, Transaction}; use crate::{ cmap::{CMap2, DartIdType}, diff --git a/honeycomb-core/src/cmap/dim2/links/two.rs b/honeycomb-core/src/cmap/dim2/links/two.rs index 339754985..e9c9b0ef2 100644 --- a/honeycomb-core/src/cmap/dim2/links/two.rs +++ b/honeycomb-core/src/cmap/dim2/links/two.rs @@ -1,6 +1,6 @@ //! 2D link implementations -use stm::{atomically, StmResult, Transaction}; +use fast_stm::{atomically, StmResult, Transaction}; use crate::{ cmap::{CMap2, DartIdType}, diff --git a/honeycomb-core/src/cmap/dim2/sews/one.rs b/honeycomb-core/src/cmap/dim2/sews/one.rs index ed9316bea..941a470be 100644 --- a/honeycomb-core/src/cmap/dim2/sews/one.rs +++ b/honeycomb-core/src/cmap/dim2/sews/one.rs @@ -1,6 +1,6 @@ //! 1D sew implementations -use stm::{atomically, StmResult, Transaction}; +use fast_stm::{atomically, StmResult, Transaction}; use crate::{ attributes::UnknownAttributeStorage, diff --git a/honeycomb-core/src/cmap/dim2/sews/two.rs b/honeycomb-core/src/cmap/dim2/sews/two.rs index ceff0c918..2090ae787 100644 --- a/honeycomb-core/src/cmap/dim2/sews/two.rs +++ b/honeycomb-core/src/cmap/dim2/sews/two.rs @@ -1,6 +1,6 @@ //! 2D sew implementations -use stm::{atomically, StmResult, Transaction}; +use fast_stm::{atomically, StmResult, Transaction}; use crate::{ attributes::{AttributeStorage, UnknownAttributeStorage}, diff --git a/honeycomb-core/src/cmap/dim2/utils.rs b/honeycomb-core/src/cmap/dim2/utils.rs index adc33354b..61f78ae70 100644 --- a/honeycomb-core/src/cmap/dim2/utils.rs +++ b/honeycomb-core/src/cmap/dim2/utils.rs @@ -14,8 +14,8 @@ use super::CMAP2_BETA; use crate::geometry::CoordsFloat; use crate::prelude::{CMap2, DartIdType}; +use fast_stm::atomically; use std::{fs::File, io::Write}; -use stm::atomically; // ------ CONTENT diff --git a/honeycomb-core/src/cmap/error.rs b/honeycomb-core/src/cmap/error.rs index 3bdcf34c3..b087cd0ca 100644 --- a/honeycomb-core/src/cmap/error.rs +++ b/honeycomb-core/src/cmap/error.rs @@ -1,6 +1,6 @@ //! Main error type -use stm::StmError; +use fast_stm::StmError; /// Convenience type alias. pub type CMapResult = Result; diff --git a/honeycomb-core/src/lib.rs b/honeycomb-core/src/lib.rs index ffd3bb5e4..e375a0848 100644 --- a/honeycomb-core/src/lib.rs +++ b/honeycomb-core/src/lib.rs @@ -37,7 +37,7 @@ pub mod cmap; pub mod geometry; -pub use stm; // re-export since we use their items in the API +pub use fast_stm; // re-export since we use their items in the API /// commonly used items pub mod prelude; diff --git a/honeycomb-kernels/src/shift/neighbors_average.rs b/honeycomb-kernels/src/shift/neighbors_average.rs index 2b17aa345..5feefa51d 100644 --- a/honeycomb-kernels/src/shift/neighbors_average.rs +++ b/honeycomb-kernels/src/shift/neighbors_average.rs @@ -1,7 +1,7 @@ use honeycomb_core::{ cmap::{CMap2, DartIdType, Orbit2, OrbitPolicy, VertexIdType, NULL_DART_ID}, + fast_stm::atomically, prelude::{CoordsFloat, Vertex2}, - stm::atomically, }; use rayon::prelude::*; From 61c4404779df9aeb2f80f4bea2110bb2fde1cac6 Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Wed, 27 Nov 2024 09:01:41 +0100 Subject: [PATCH 04/11] add binary for perf --- benches/Cargo.toml | 5 +++++ benches/src/shift.rs | 24 ++++++++++++++++++++++++ honeycomb-core/Cargo.toml | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 benches/src/shift.rs diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 28b288eb7..de2d62ef5 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -34,6 +34,11 @@ path = "src/builder.rs" name = "grisubal" path = "src/grisubal.rs" +[[bin]] +name = "shift" +path = "src/shift.rs" + + # benches ## Core benchmarks diff --git a/benches/src/shift.rs b/benches/src/shift.rs new file mode 100644 index 000000000..1141a4070 --- /dev/null +++ b/benches/src/shift.rs @@ -0,0 +1,24 @@ +use honeycomb::{ + kernels::shift::shift_vertices_to_neigh_avg, + prelude::{CMap2, CMapBuilder}, +}; + +fn main() { + // ./binary ~/path/to/file.vtk n_rounds + let args: Vec = std::env::args().collect(); + let path = if let Some(path) = args.get(1) { + path.clone() + } else { + "examples/quads.vtk".to_string() + }; + let n_rounds = args + .get(2) + .and_then(|s| s.parse::().ok()) + .unwrap_or(100); + + let map: CMap2 = CMapBuilder::default().vtk_file(path).build().unwrap(); + + shift_vertices_to_neigh_avg(&map, n_rounds); + + std::hint::black_box(map); +} diff --git a/honeycomb-core/Cargo.toml b/honeycomb-core/Cargo.toml index b039c20e6..162165c26 100644 --- a/honeycomb-core/Cargo.toml +++ b/honeycomb-core/Cargo.toml @@ -19,7 +19,7 @@ utils = [] # deps [dependencies] -fast-stm = { git = "https://github.com/imrn99/fast-stm.git", rev = "94a9ff5" } +fast-stm = { git = "https://github.com/imrn99/fast-stm.git", rev = "9179010" } downcast-rs.workspace = true loom.workspace = true num-traits.workspace = true From 4f7ce38db5fe258fac659320d1b2b3b263d9a17f Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Wed, 27 Nov 2024 10:47:37 +0100 Subject: [PATCH 05/11] add oncollide --- benches/Cargo.toml | 4 ++ benches/src/shift.rs | 62 ++++++++++++++++++++---- benches/src/shift_noncollide.rs | 84 +++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 benches/src/shift_noncollide.rs diff --git a/benches/Cargo.toml b/benches/Cargo.toml index de2d62ef5..87c5567d6 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -17,6 +17,7 @@ _single_precision = [] [dependencies] cfg-if.workspace = true honeycomb.workspace = true +rayon = "1.10.0" [dev-dependencies] honeycomb-core = { workspace = true, features = ["utils"] } @@ -38,6 +39,9 @@ path = "src/grisubal.rs" name = "shift" path = "src/shift.rs" +[[bin]] +name = "shift-nc" +path = "src/shift_noncollide.rs" # benches diff --git a/benches/src/shift.rs b/benches/src/shift.rs index 1141a4070..a88fca622 100644 --- a/benches/src/shift.rs +++ b/benches/src/shift.rs @@ -1,24 +1,66 @@ -use honeycomb::{ - kernels::shift::shift_vertices_to_neigh_avg, - prelude::{CMap2, CMapBuilder}, +use rayon::prelude::*; + +use honeycomb::core::fast_stm::atomically; +use honeycomb::prelude::{ + CMap2, CMapBuilder, DartIdType, Orbit2, OrbitPolicy, Vertex2, VertexIdType, NULL_DART_ID, }; fn main() { // ./binary ~/path/to/file.vtk n_rounds let args: Vec = std::env::args().collect(); - let path = if let Some(path) = args.get(1) { - path.clone() - } else { - "examples/quads.vtk".to_string() - }; + let n_squares = args + .get(1) + .and_then(|s| s.parse::().ok()) + .unwrap_or(256); let n_rounds = args .get(2) .and_then(|s| s.parse::().ok()) .unwrap_or(100); - let map: CMap2 = CMapBuilder::default().vtk_file(path).build().unwrap(); + let map: CMap2 = CMapBuilder::unit_grid(n_squares).build().unwrap(); + + // fetch all vertices that are not on the boundary of the map + let tmp: Vec<(VertexIdType, Vec)> = map + .fetch_vertices() + .identifiers + .into_iter() + .filter_map(|v| { + if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) + .any(|d| map.beta::<2>(d) == NULL_DART_ID) + { + None + } else { + Some(( + v, + Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) + .map(|d| map.vertex_id(map.beta::<2>(d))) + .collect(), + )) + } + }) + .collect(); + // main loop + let mut round = 0; + loop { + tmp.par_iter().for_each(|(vid, neigh)| { + atomically(|trans| { + let mut new_val = Vertex2::default(); + for v in neigh { + let vertex = map.read_vertex(trans, *v)?.unwrap(); + new_val.0 += vertex.0; + new_val.1 += vertex.1; + } + new_val.0 /= neigh.len() as f64; + new_val.1 /= neigh.len() as f64; + map.write_vertex(trans, *vid, new_val) + }); + }); - shift_vertices_to_neigh_avg(&map, n_rounds); + round += 1; + if round >= n_rounds { + break; + } + } std::hint::black_box(map); } diff --git a/benches/src/shift_noncollide.rs b/benches/src/shift_noncollide.rs new file mode 100644 index 000000000..efd266f8f --- /dev/null +++ b/benches/src/shift_noncollide.rs @@ -0,0 +1,84 @@ +use rayon::prelude::*; + +use honeycomb::core::fast_stm::atomically; +use honeycomb::prelude::{ + CMap2, CMapBuilder, DartIdType, Orbit2, OrbitPolicy, Vertex2, VertexIdType, NULL_DART_ID, +}; + +fn main() { + // ./binary ~/path/to/file.vtk n_rounds + let args: Vec = std::env::args().collect(); + let n_squares = args + .get(1) + .and_then(|s| s.parse::().ok()) + .unwrap_or(256); + let n_rounds = args + .get(2) + .and_then(|s| s.parse::().ok()) + .unwrap_or(100); + + let map: CMap2 = CMapBuilder::unit_grid(n_squares).build().unwrap(); + + // fetch all vertices that are not on the boundary of the map + let tmp = map + .fetch_vertices() + .identifiers + .into_iter() + .filter_map(|v| { + if Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) + .any(|d| map.beta::<2>(d) == NULL_DART_ID) + { + None + } else { + Some(( + v, + Orbit2::new(&map, OrbitPolicy::Vertex, v as DartIdType) + .map(|d| map.vertex_id(map.beta::<2>(d))) + .collect(), + )) + } + }); + + #[allow(clippy::type_complexity)] + let (first_batch, second_batch): ( + Vec<(VertexIdType, Vec)>, + Vec<(VertexIdType, Vec)>, + ) = tmp.partition(|(v, _)| ((v - 1) / 4) % 2 == 0); // this yields 2 ind. batches, just trust me + + // main loop + let mut round = 0; + loop { + first_batch.par_iter().for_each(|(vid, neigh)| { + atomically(|trans| { + let mut new_val = Vertex2::default(); + for v in neigh { + let vertex = map.read_vertex(trans, *v)?.unwrap(); + new_val.0 += vertex.0; + new_val.1 += vertex.1; + } + new_val.0 /= neigh.len() as f64; + new_val.1 /= neigh.len() as f64; + map.write_vertex(trans, *vid, new_val) + }); + }); + second_batch.par_iter().for_each(|(vid, neigh)| { + atomically(|trans| { + let mut new_val = Vertex2::default(); + for v in neigh { + let vertex = map.read_vertex(trans, *v)?.unwrap(); + new_val.0 += vertex.0; + new_val.1 += vertex.1; + } + new_val.0 /= neigh.len() as f64; + new_val.1 /= neigh.len() as f64; + map.write_vertex(trans, *vid, new_val) + }); + }); + round += 1; + if round >= n_rounds { + break; + } + } + + std::hint::black_box(map); +} From b88000f2c99c47d82fb776f40398a2cd1f7aba7b Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:17:23 +0100 Subject: [PATCH 06/11] revert to regular stm --- benches/src/shift.rs | 2 +- benches/src/shift_noncollide.rs | 2 +- honeycomb-core/Cargo.toml | 3 +-- honeycomb-core/src/attributes/collections.rs | 2 +- honeycomb-core/src/attributes/manager.rs | 2 +- honeycomb-core/src/attributes/tests.rs | 2 +- honeycomb-core/src/attributes/traits.rs | 2 +- honeycomb-core/src/cmap/components/betas.rs | 2 +- honeycomb-core/src/cmap/components/unused.rs | 2 +- honeycomb-core/src/cmap/dim2/basic_ops.rs | 2 +- honeycomb-core/src/cmap/dim2/embed.rs | 2 +- honeycomb-core/src/cmap/dim2/links/one.rs | 2 +- honeycomb-core/src/cmap/dim2/links/two.rs | 2 +- honeycomb-core/src/cmap/dim2/sews/one.rs | 2 +- honeycomb-core/src/cmap/dim2/sews/two.rs | 2 +- honeycomb-core/src/cmap/dim2/utils.rs | 2 +- honeycomb-core/src/cmap/error.rs | 2 +- honeycomb-core/src/lib.rs | 2 +- honeycomb-kernels/src/shift/neighbors_average.rs | 2 +- 19 files changed, 19 insertions(+), 20 deletions(-) diff --git a/benches/src/shift.rs b/benches/src/shift.rs index a88fca622..d4b29884a 100644 --- a/benches/src/shift.rs +++ b/benches/src/shift.rs @@ -1,6 +1,6 @@ use rayon::prelude::*; -use honeycomb::core::fast_stm::atomically; +use honeycomb::core::stm::atomically; use honeycomb::prelude::{ CMap2, CMapBuilder, DartIdType, Orbit2, OrbitPolicy, Vertex2, VertexIdType, NULL_DART_ID, }; diff --git a/benches/src/shift_noncollide.rs b/benches/src/shift_noncollide.rs index efd266f8f..86d367392 100644 --- a/benches/src/shift_noncollide.rs +++ b/benches/src/shift_noncollide.rs @@ -1,6 +1,6 @@ use rayon::prelude::*; -use honeycomb::core::fast_stm::atomically; +use honeycomb::core::stm::atomically; use honeycomb::prelude::{ CMap2, CMapBuilder, DartIdType, Orbit2, OrbitPolicy, Vertex2, VertexIdType, NULL_DART_ID, }; diff --git a/honeycomb-core/Cargo.toml b/honeycomb-core/Cargo.toml index 162165c26..c005a4879 100644 --- a/honeycomb-core/Cargo.toml +++ b/honeycomb-core/Cargo.toml @@ -19,9 +19,8 @@ utils = [] # deps [dependencies] -fast-stm = { git = "https://github.com/imrn99/fast-stm.git", rev = "9179010" } downcast-rs.workspace = true -loom.workspace = true +loom.workspace= true num-traits.workspace = true stm.workspace = true thiserror.workspace = true diff --git a/honeycomb-core/src/attributes/collections.rs b/honeycomb-core/src/attributes/collections.rs index ce2d59cca..d16d58307 100644 --- a/honeycomb-core/src/attributes/collections.rs +++ b/honeycomb-core/src/attributes/collections.rs @@ -10,8 +10,8 @@ use crate::{ cmap::{CMapError, CMapResult}, prelude::DartIdType, }; -use fast_stm::{atomically, StmResult, TVar, Transaction}; use num_traits::ToPrimitive; +use stm::{atomically, StmResult, TVar, Transaction}; // ------ CONTENT diff --git a/honeycomb-core/src/attributes/manager.rs b/honeycomb-core/src/attributes/manager.rs index 731aec7c0..21a70e91a 100644 --- a/honeycomb-core/src/attributes/manager.rs +++ b/honeycomb-core/src/attributes/manager.rs @@ -5,7 +5,7 @@ // ------ IMPORTS -use fast_stm::{StmResult, Transaction}; +use stm::{StmResult, Transaction}; use super::{AttributeBind, AttributeStorage, AttributeUpdate, UnknownAttributeStorage}; use crate::{ diff --git a/honeycomb-core/src/attributes/tests.rs b/honeycomb-core/src/attributes/tests.rs index a311f3b3f..6ab44fddf 100644 --- a/honeycomb-core/src/attributes/tests.rs +++ b/honeycomb-core/src/attributes/tests.rs @@ -1,7 +1,7 @@ // ------ IMPORTS -use fast_stm::{atomically, StmError, Transaction, TransactionControl}; use loom::sync::Arc; +use stm::{atomically, StmError, Transaction, TransactionControl}; use super::{ AttrSparseVec, AttrStorageManager, AttributeBind, AttributeStorage, AttributeUpdate, diff --git a/honeycomb-core/src/attributes/traits.rs b/honeycomb-core/src/attributes/traits.rs index 76b7fca50..ead9ba67d 100644 --- a/honeycomb-core/src/attributes/traits.rs +++ b/honeycomb-core/src/attributes/traits.rs @@ -10,9 +10,9 @@ use crate::{ prelude::{DartIdType, OrbitPolicy}, }; use downcast_rs::{impl_downcast, Downcast}; -use fast_stm::{atomically, StmResult, Transaction}; use std::any::Any; use std::fmt::Debug; +use stm::{atomically, StmResult, Transaction}; // ------ CONTENT diff --git a/honeycomb-core/src/cmap/components/betas.rs b/honeycomb-core/src/cmap/components/betas.rs index d4e4516da..e58db9411 100644 --- a/honeycomb-core/src/cmap/components/betas.rs +++ b/honeycomb-core/src/cmap/components/betas.rs @@ -2,7 +2,7 @@ use std::ops::{Index, IndexMut}; -use fast_stm::{StmError, TVar, Transaction}; +use stm::{StmError, TVar, Transaction}; use crate::cmap::NULL_DART_ID; diff --git a/honeycomb-core/src/cmap/components/unused.rs b/honeycomb-core/src/cmap/components/unused.rs index 1de378df4..5d85baada 100644 --- a/honeycomb-core/src/cmap/components/unused.rs +++ b/honeycomb-core/src/cmap/components/unused.rs @@ -5,7 +5,7 @@ use std::{ slice::Iter, }; -use fast_stm::TVar; +use stm::TVar; use super::identifiers::DartIdType; diff --git a/honeycomb-core/src/cmap/dim2/basic_ops.rs b/honeycomb-core/src/cmap/dim2/basic_ops.rs index c1c996cf6..889727bf0 100644 --- a/honeycomb-core/src/cmap/dim2/basic_ops.rs +++ b/honeycomb-core/src/cmap/dim2/basic_ops.rs @@ -17,8 +17,8 @@ use crate::{ cmap::{EdgeCollection, FaceCollection, VertexCollection}, geometry::CoordsFloat, }; -use fast_stm::{atomically, StmError, Transaction}; use std::collections::{BTreeSet, VecDeque}; +use stm::{atomically, StmError, Transaction}; // ------ CONTENT diff --git a/honeycomb-core/src/cmap/dim2/embed.rs b/honeycomb-core/src/cmap/dim2/embed.rs index 0ba97a92d..2d0794a35 100644 --- a/honeycomb-core/src/cmap/dim2/embed.rs +++ b/honeycomb-core/src/cmap/dim2/embed.rs @@ -6,7 +6,7 @@ // ------ IMPORT -use fast_stm::{StmResult, Transaction}; +use stm::{StmResult, Transaction}; use crate::prelude::{AttributeBind, AttributeUpdate, CMap2, Vertex2, VertexIdType}; use crate::{ diff --git a/honeycomb-core/src/cmap/dim2/links/one.rs b/honeycomb-core/src/cmap/dim2/links/one.rs index b1daa1db8..3c720e976 100644 --- a/honeycomb-core/src/cmap/dim2/links/one.rs +++ b/honeycomb-core/src/cmap/dim2/links/one.rs @@ -1,6 +1,6 @@ //! 1D link implementations -use fast_stm::{atomically, StmResult, Transaction}; +use stm::{atomically, StmResult, Transaction}; use crate::{ cmap::{CMap2, DartIdType}, diff --git a/honeycomb-core/src/cmap/dim2/links/two.rs b/honeycomb-core/src/cmap/dim2/links/two.rs index e9c9b0ef2..339754985 100644 --- a/honeycomb-core/src/cmap/dim2/links/two.rs +++ b/honeycomb-core/src/cmap/dim2/links/two.rs @@ -1,6 +1,6 @@ //! 2D link implementations -use fast_stm::{atomically, StmResult, Transaction}; +use stm::{atomically, StmResult, Transaction}; use crate::{ cmap::{CMap2, DartIdType}, diff --git a/honeycomb-core/src/cmap/dim2/sews/one.rs b/honeycomb-core/src/cmap/dim2/sews/one.rs index 941a470be..ed9316bea 100644 --- a/honeycomb-core/src/cmap/dim2/sews/one.rs +++ b/honeycomb-core/src/cmap/dim2/sews/one.rs @@ -1,6 +1,6 @@ //! 1D sew implementations -use fast_stm::{atomically, StmResult, Transaction}; +use stm::{atomically, StmResult, Transaction}; use crate::{ attributes::UnknownAttributeStorage, diff --git a/honeycomb-core/src/cmap/dim2/sews/two.rs b/honeycomb-core/src/cmap/dim2/sews/two.rs index 2090ae787..ceff0c918 100644 --- a/honeycomb-core/src/cmap/dim2/sews/two.rs +++ b/honeycomb-core/src/cmap/dim2/sews/two.rs @@ -1,6 +1,6 @@ //! 2D sew implementations -use fast_stm::{atomically, StmResult, Transaction}; +use stm::{atomically, StmResult, Transaction}; use crate::{ attributes::{AttributeStorage, UnknownAttributeStorage}, diff --git a/honeycomb-core/src/cmap/dim2/utils.rs b/honeycomb-core/src/cmap/dim2/utils.rs index 61f78ae70..adc33354b 100644 --- a/honeycomb-core/src/cmap/dim2/utils.rs +++ b/honeycomb-core/src/cmap/dim2/utils.rs @@ -14,8 +14,8 @@ use super::CMAP2_BETA; use crate::geometry::CoordsFloat; use crate::prelude::{CMap2, DartIdType}; -use fast_stm::atomically; use std::{fs::File, io::Write}; +use stm::atomically; // ------ CONTENT diff --git a/honeycomb-core/src/cmap/error.rs b/honeycomb-core/src/cmap/error.rs index b087cd0ca..3bdcf34c3 100644 --- a/honeycomb-core/src/cmap/error.rs +++ b/honeycomb-core/src/cmap/error.rs @@ -1,6 +1,6 @@ //! Main error type -use fast_stm::StmError; +use stm::StmError; /// Convenience type alias. pub type CMapResult = Result; diff --git a/honeycomb-core/src/lib.rs b/honeycomb-core/src/lib.rs index e375a0848..ffd3bb5e4 100644 --- a/honeycomb-core/src/lib.rs +++ b/honeycomb-core/src/lib.rs @@ -37,7 +37,7 @@ pub mod cmap; pub mod geometry; -pub use fast_stm; // re-export since we use their items in the API +pub use stm; // re-export since we use their items in the API /// commonly used items pub mod prelude; diff --git a/honeycomb-kernels/src/shift/neighbors_average.rs b/honeycomb-kernels/src/shift/neighbors_average.rs index 5feefa51d..2b17aa345 100644 --- a/honeycomb-kernels/src/shift/neighbors_average.rs +++ b/honeycomb-kernels/src/shift/neighbors_average.rs @@ -1,7 +1,7 @@ use honeycomb_core::{ cmap::{CMap2, DartIdType, Orbit2, OrbitPolicy, VertexIdType, NULL_DART_ID}, - fast_stm::atomically, prelude::{CoordsFloat, Vertex2}, + stm::atomically, }; use rayon::prelude::*; From 78b824d09fa4341e28bb9146d2cd63b6e4cf533c Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:16:38 +0100 Subject: [PATCH 07/11] remove the kernel function & criterion bench --- benches/Cargo.toml | 7 +-- benches/benches/shift.rs | 28 ---------- honeycomb-kernels/src/lib.rs | 1 - honeycomb-kernels/src/shift/mod.rs | 3 -- .../src/shift/neighbors_average.rs | 54 ------------------- 5 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 benches/benches/shift.rs delete mode 100644 honeycomb-kernels/src/shift/mod.rs delete mode 100644 honeycomb-kernels/src/shift/neighbors_average.rs diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 87c5567d6..d7fdbf64b 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -91,13 +91,8 @@ name = "grisubal-grid-size" path = "benches/grisubal/grid_size.rs" harness = false - -[[bench]] -name = "shift" -path = "benches/shift.rs" -harness = false - [[bench]] name = "triangulate-quads" path = "benches/triangulate/quads.rs" harness = false + diff --git a/benches/benches/shift.rs b/benches/benches/shift.rs deleted file mode 100644 index 6e22c8ebc..000000000 --- a/benches/benches/shift.rs +++ /dev/null @@ -1,28 +0,0 @@ -// ------ IMPORTS - -use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; -use honeycomb::{kernels::shift::shift_vertices_to_neigh_avg, prelude::CMap2}; -use honeycomb_benches::FloatType; -use honeycomb_core::cmap::CMapBuilder; - -// ------ CONTENT - -pub fn criterion_benchmark(c: &mut Criterion) { - let path = "../../../meshing-samples/vtk/2D/many_quads.vtk"; - - let mut group = c.benchmark_group("shift"); - - let mut map: CMap2 = CMapBuilder::from(path).build().unwrap(); - - group.bench_function(BenchmarkId::new("to-neighbor-avg", ""), |b| { - b.iter(|| { - shift_vertices_to_neigh_avg(&map, 200); - black_box(&mut map); - }) - }); - - group.finish(); -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); diff --git a/honeycomb-kernels/src/lib.rs b/honeycomb-kernels/src/lib.rs index 9551f7530..ecb0f1b3b 100644 --- a/honeycomb-kernels/src/lib.rs +++ b/honeycomb-kernels/src/lib.rs @@ -22,6 +22,5 @@ // ------ MODULE DECLARATIONS pub mod grisubal; -pub mod shift; pub mod splits; pub mod triangulation; diff --git a/honeycomb-kernels/src/shift/mod.rs b/honeycomb-kernels/src/shift/mod.rs deleted file mode 100644 index 8c52062d7..000000000 --- a/honeycomb-kernels/src/shift/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod neighbors_average; - -pub use neighbors_average::shift as shift_vertices_to_neigh_avg; diff --git a/honeycomb-kernels/src/shift/neighbors_average.rs b/honeycomb-kernels/src/shift/neighbors_average.rs deleted file mode 100644 index 2b17aa345..000000000 --- a/honeycomb-kernels/src/shift/neighbors_average.rs +++ /dev/null @@ -1,54 +0,0 @@ -use honeycomb_core::{ - cmap::{CMap2, DartIdType, Orbit2, OrbitPolicy, VertexIdType, NULL_DART_ID}, - prelude::{CoordsFloat, Vertex2}, - stm::atomically, -}; -use rayon::prelude::*; - -pub fn shift(cmap: &CMap2, n_rounds: usize) { - // fetch all vertices that are not on the boundary of the map - let vertices: Vec = cmap - .fetch_vertices() - .identifiers - .into_par_iter() - .filter(|v| { - !Orbit2::new(&cmap, OrbitPolicy::Vertex, *v as DartIdType) - .any(|d| cmap.beta::<2>(d) == NULL_DART_ID) - }) - .collect(); - - let neighbors: Vec> = vertices - .par_iter() - .map(|v| { - Orbit2::new(&cmap, OrbitPolicy::Vertex, *v as DartIdType) - .map(|d| cmap.vertex_id(cmap.beta::<2>(d))) - .collect() - }) - .collect(); - - // main loop - let mut round = 0; - loop { - vertices - .iter() - .zip(neighbors.iter()) - .par_bridge() - .for_each(|(vid, neigh)| { - atomically(|trans| { - let mut new_val: Vertex2 = Vertex2::default(); - for v in neigh { - let vertex = cmap.read_vertex(trans, *v)?.unwrap(); - new_val.0 += vertex.0; - new_val.1 += vertex.1; - } - new_val.0 /= T::from(neigh.len()).unwrap(); - new_val.1 /= T::from(neigh.len()).unwrap(); - cmap.write_vertex(trans, *vid, new_val) - }); - }); - round += 1; - if round >= n_rounds { - break; - } - } -} From ea97cdd591e6dcbc106fa6bf0e3141ad15b2dbe8 Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:28:38 +0100 Subject: [PATCH 08/11] move rayon dep to workspace --- Cargo.toml | 1 + benches/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ea659005a..87e6d3c95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ honeycomb-render = { version = "0.6.0", path = "./honeycomb-render" } # common cfg-if = "1" +rayon = "1.10.0" rustversion = "1.0.18" thiserror = "2.0.3" diff --git a/benches/Cargo.toml b/benches/Cargo.toml index d7fdbf64b..146e80776 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -17,7 +17,7 @@ _single_precision = [] [dependencies] cfg-if.workspace = true honeycomb.workspace = true -rayon = "1.10.0" +rayon.workspace = true [dev-dependencies] honeycomb-core = { workspace = true, features = ["utils"] } From ab9ae8d7105e65d34e02990924d52cede442728f Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:37:03 +0100 Subject: [PATCH 09/11] fix comment --- benches/src/shift.rs | 2 +- benches/src/shift_noncollide.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benches/src/shift.rs b/benches/src/shift.rs index d4b29884a..8586d9c7f 100644 --- a/benches/src/shift.rs +++ b/benches/src/shift.rs @@ -6,7 +6,7 @@ use honeycomb::prelude::{ }; fn main() { - // ./binary ~/path/to/file.vtk n_rounds + // ./binary grid_size n_rounds let args: Vec = std::env::args().collect(); let n_squares = args .get(1) diff --git a/benches/src/shift_noncollide.rs b/benches/src/shift_noncollide.rs index 86d367392..0e064ef69 100644 --- a/benches/src/shift_noncollide.rs +++ b/benches/src/shift_noncollide.rs @@ -6,7 +6,7 @@ use honeycomb::prelude::{ }; fn main() { - // ./binary ~/path/to/file.vtk n_rounds + // ./binary grid_size n_rounds let args: Vec = std::env::args().collect(); let n_squares = args .get(1) From fed3027b02b4dc0e41e017ed395474226752d724 Mon Sep 17 00:00:00 2001 From: imrn99 <95699343+imrn99@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:54:36 +0100 Subject: [PATCH 10/11] rename binary file --- benches/Cargo.toml | 2 +- benches/src/{shift_noncollide.rs => shift_no_conflict.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename benches/src/{shift_noncollide.rs => shift_no_conflict.rs} (100%) diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 146e80776..9854204a0 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -41,7 +41,7 @@ path = "src/shift.rs" [[bin]] name = "shift-nc" -path = "src/shift_noncollide.rs" +path = "src/shift_no_conflict.rs" # benches diff --git a/benches/src/shift_noncollide.rs b/benches/src/shift_no_conflict.rs similarity index 100% rename from benches/src/shift_noncollide.rs rename to benches/src/shift_no_conflict.rs From cb24350632b66e2dca516c01809a994f7e2107d5 Mon Sep 17 00:00:00 2001 From: imrn99 Date: Tue, 3 Dec 2024 14:31:55 +0100 Subject: [PATCH 11/11] add desxcriptions --- benches/src/shift.rs | 29 ++++++++++++++++++++++++++++ benches/src/shift_no_conflict.rs | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/benches/src/shift.rs b/benches/src/shift.rs index 8586d9c7f..0045d515f 100644 --- a/benches/src/shift.rs +++ b/benches/src/shift.rs @@ -1,3 +1,32 @@ +//! Simple vertex relaxation routine. +//! +//! # Usage +//! +//! ``` +//! cargo build --release --bin=shift +//! ./target/release/shift +//! ``` +//! +//! With: +//! - `GRID_SIZE` the dimension of the generated (square) grid along one axis +//! - `N_ROUNDS` the number of iterations of the relaxa6tion algorithm +//! +//! # Description +//! +//! ## Routine +//! +//! The algorithm fetches all vertices that are not on the border of the map, fetch all identifiers of each +//! respective vertices' neighbors. Then, for all vertices: +//! +//! - compute the average between neighbors +//1 - overwrite current vertex value with computed average +//! +//! ## Benchmark +//! +//! This binary is meant to be use to evaluate scalability of geometry-only kernels. It is parallelized using +//! rayon, and the number of thread used for execution can be controlled using `taskset`. By controlling this, +//! and the grid size, we can evaluate both strong and weak scaling characteristics. + use rayon::prelude::*; use honeycomb::core::stm::atomically; diff --git a/benches/src/shift_no_conflict.rs b/benches/src/shift_no_conflict.rs index 0e064ef69..4bff8bb87 100644 --- a/benches/src/shift_no_conflict.rs +++ b/benches/src/shift_no_conflict.rs @@ -1,3 +1,36 @@ +//! Simple vertex relaxation routine. +//! +//! # Usage +//! +//! ``` +//! cargo build --release --bin=shift +//! ./target/release/shift +//! ``` +//! +//! With: +//! - `GRID_SIZE` the dimension of the generated (square) grid along one axis +//! - `N_ROUNDS` the number of iterations of the relaxa6tion algorithm +//! +//! # Description +//! +//! ## Routine +//! +//! The algorithm fetches all vertices that are not on the border of the map, fetch all identifiers of each +//! respective vertices' neighbors. The set of vertices is then split into independent subset, to create +//! groups with no RW access conflicts. Then, for all vertices of each set: +//! +//! - compute the average between neighbors +//1 - overwrite current vertex value with computed average +//! +//! ## Benchmark +//! +//! This binary is meant to be use to evaluate scalability of geometry-only kernels. It is parallelized using +//! rayon, and the number of thread used for execution can be controlled using `taskset`. By controlling this, +//! and the grid size, we can evaluate both strong and weak scaling characteristics. +//! +//! Using this, along with the regular `shift` binary highlights the cost of access conflict and transaction +//! cancellations. + use rayon::prelude::*; use honeycomb::core::stm::atomically;