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

Particle creation with minimum distance is not thread safe #718

Open
marcel-dcs opened this issue Nov 21, 2023 · 1 comment
Open

Particle creation with minimum distance is not thread safe #718

marcel-dcs opened this issue Nov 21, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@marcel-dcs
Copy link

I did not manage to use createParticles with a min_dist option (to prevent overlapping particles) when using multiple threads. At first I expected an incorrect usage on my end, but there appears to be a bug in the unit test for this functionality. The checkRandomDistances function has the following two issues:

  1. The min_dist is converted to an int, which casts the 0.47 value to 0 (which is why the check never fails)
    see: https://github.com/ECP-copa/Cabana/blob/master/core/unit_test/tstParticleInit.hpp#L52

  2. The inner loop over j should start at i+1, to prevent checks for i==j and duplicate checks
    see: https://github.com/ECP-copa/Cabana/blob/master/core/unit_test/tstParticleInit.hpp#L59

After correcting for these, the ParticleInit unit test fails. Therefore, it looks like the insertion with a minimum distance is not thread safe: the id used here, might not match the actual position where the particle is inserted in the particle_list (here). If so, some particles accepted for insertion might overlap with others inserted around the same time.

@streeve
Copy link
Member

streeve commented Nov 21, 2023

Thanks for the detailed report! I'll look into how best to fix

@streeve streeve added the bug Something isn't working label Nov 21, 2023
@streeve streeve self-assigned this Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants