Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize the Packer #11

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,16 @@ pub fn pack_spheres<C: Container, R: IndependentSample<f64>>(
let curr_sphere = rng.choose(&front).ok_or(Error::NoneFront)?.clone();
// V := {s(c', r') ∈ S : d(c₀, c') ≤ r₀ + r' + 2r}
set_v.clear();
set_v.par_extend(spheres.par_iter().cloned().filter(|s_dash| {
s_dash != &curr_sphere
&& nalgebra::distance(&curr_sphere.center, &s_dash.center)
<= curr_sphere.radius + s_dash.radius + 2. * new_radius
}));
set_v.par_extend(
spheres
.par_iter()
.filter(|&s_dash| {
s_dash != &curr_sphere
&& nalgebra::distance(&curr_sphere.center, &s_dash.center)
<= curr_sphere.radius + s_dash.radius + 2. * new_radius
})
.cloned(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that totally makes sense. :) I'm out of town today, so will run those quick benches tomorrow when I get home and see how they compare.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm not getting any timing difference with this change at all. Do you have any benches of your own that I can take a look at? Perhaps it's only my machine?

);

for (s_i, s_j) in pairs(&set_v) {
set_f.clear();
Expand Down Expand Up @@ -442,12 +447,10 @@ fn identify_f<C: Container>(
)?;

// Make sure the spheres are bounded by the containing geometry and do not overlap any spheres in V
if container.contains(&s_4_positive) && !set_v.par_iter().any(|v| v.overlaps(&s_4_positive))
{
if container.contains(&s_4_positive) && !set_v.iter().any(|v| v.overlaps(&s_4_positive)) {
set_f.push(s_4_positive);
}
if container.contains(&s_4_negative) && !set_v.par_iter().any(|v| v.overlaps(&s_4_negative))
{
if container.contains(&s_4_negative) && !set_v.iter().any(|v| v.overlaps(&s_4_negative)) {
set_f.push(s_4_negative);
}
}
Expand Down