optional parallel processing
This commit is contained in:
parent
e912c7b414
commit
a56705383f
2 changed files with 24 additions and 13 deletions
|
|
@ -44,7 +44,9 @@ fn main() {
|
||||||
println!("Generated Delaunay triangulation");
|
println!("Generated Delaunay triangulation");
|
||||||
|
|
||||||
// Pre-process triangles
|
// 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
|
// Execute delfin function with the generated GeometryData
|
||||||
let min_area: f32 = 1000.0; // threshold for voidness
|
let min_area: f32 = 1000.0; // threshold for voidness
|
||||||
|
|
|
||||||
33
src/lib.rs
33
src/lib.rs
|
|
@ -258,18 +258,27 @@ impl Xenobalanus {
|
||||||
self.triangulation = result.triangles
|
self.triangulation = result.triangles
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn preprocess(&mut self, types: usize) {
|
pub fn preprocess(&mut self, types: usize, parallel: bool) {
|
||||||
let geometry_data = Arc::new(Mutex::new(GeometryData::new()));
|
if parallel {
|
||||||
|
|
||||||
self.triangulation.par_chunks(3).enumerate().for_each(|(index, tri_idx)| {
|
let geometry_data = Arc::new(Mutex::new(GeometryData::new()));
|
||||||
let gd = geometry_data.clone(); // Clone Arc for use in each thread, not the data itself
|
|
||||||
|
self.triangulation.par_chunks(3).enumerate().for_each(|(index, tri_idx)| {
|
||||||
// Perform locked update
|
let gd = geometry_data.clone(); // Clone Arc for use in each thread, not the data itself
|
||||||
let mut gd_lock = gd.lock().unwrap();
|
|
||||||
gd_lock.add_triangle(index, &self.points, tri_idx, types);
|
// Perform locked update
|
||||||
});
|
let mut gd_lock = gd.lock().unwrap();
|
||||||
|
gd_lock.add_triangle(index, &self.points, tri_idx, types);
|
||||||
self.geometry_data = Arc::try_unwrap(geometry_data).unwrap().into_inner().unwrap();
|
});
|
||||||
|
|
||||||
|
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(
|
pub fn delfin(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue