optional parallel processing

This commit is contained in:
randogoth 2024-04-07 16:25:48 +03:00
parent e912c7b414
commit a56705383f
2 changed files with 24 additions and 13 deletions

View file

@ -44,7 +44,9 @@ fn main() {
println!("Generated Delaunay triangulation");
// Pre-process triangles
xeno.preprocess(0);
// 1 - attractors, 2 - voids, 0 - both
// true/false - parallel processing
xeno.preprocess(0, false);
// Execute delfin function with the generated GeometryData
let min_area: f32 = 1000.0; // threshold for voidness

View file

@ -258,7 +258,9 @@ impl Xenobalanus {
self.triangulation = result.triangles
}
pub fn preprocess(&mut self, types: usize) {
pub fn preprocess(&mut self, types: usize, parallel: bool) {
if parallel {
let geometry_data = Arc::new(Mutex::new(GeometryData::new()));
self.triangulation.par_chunks(3).enumerate().for_each(|(index, tri_idx)| {
@ -270,6 +272,13 @@ impl Xenobalanus {
});
self.geometry_data = Arc::try_unwrap(geometry_data).unwrap().into_inner().unwrap();
} else {
self.triangulation.chunks(3).enumerate().for_each(|(index, tri_idx)| {
self.geometry_data.add_triangle(index, &self.points, tri_idx, types);
});
}
}
pub fn delfin(