-
Notifications
You must be signed in to change notification settings - Fork 37
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
Remove dynamic allocations from swarm particle creation #996
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this seems like a pretty minor change, but good for performance. And I like the new API, which feels cleaner. 👍
Alright this is ready for review/merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm not far enough into particles to be annoyed by the slight interface change, and this is clean and easy enough to understand with the example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and the changes make sense from a performance point of view.
The main snarkyke case-y comment I have why you chose you use camel case (and even refactor some existing variables) versus snake case.
I'm general in favor of consistent style across the code base.
Co-authored-by: Philipp Grete <[email protected]>
Co-authored-by: Philipp Grete <[email protected]>
Co-authored-by: Philipp Grete <[email protected]>
…enon into brryan/no_swarm_dynamic_alloc
@pgrete You are absolutely right about the case style issue with variable names, I was mistakenly taking this in the wrong direction. Thanks for pointing that out. If I didnt miss anything, I've switched every variable in swarm over to camel case. This should be ready for merge now if you're happy |
Alright all concerns look to be addressed to me so setting this to automerge, thanks all for reviews. |
PR Summary
Swarm
s previously created multipleParArray
s during theAddEmptyParticles
call to create new particles. This PR pre-allocates that memory during resize operations and returns an accessor to new particle indices, resolving that issue.This necessarily breaks previous usage of the
AddEmptyParticles
function and will affect all downstream codes using particles.API change:
ParArray1D<bool> Swarm::AddEmptyParticles(const int num_to_add, ParArrayND<int> &new_indices)
is now
NewParticlesContext Swarm::AddEmptyParticles(const int num_to_add)
where
NewParticlesContext
adds the methodsint GetNewParticlesMaxIndex()
that returns the max index of the new particles -> swarm index map, andint GetNewParticleIndex(const int n)
converts a new particle index to the swarm index.PR Checklist