Reserve space in particle redistribution#4731
Merged
WeiqunZhang merged 9 commits intoAMReX-Codes:developmentfrom Jan 21, 2026
Merged
Reserve space in particle redistribution#4731WeiqunZhang merged 9 commits intoAMReX-Codes:developmentfrom
WeiqunZhang merged 9 commits intoAMReX-Codes:developmentfrom
Conversation
When redistributing particles, we need to resize a number of vectors. This sometimes causes out-of-memory issues for GPU runs, because the vector resize may fragment the memory arena. To address the issue, we try to minimize the number of memory reallocation calls by reserving space before we unpack local and remote communication buffers. Previously, resize may cause memory reallocation in both unpacking operations. We have also collected all the vectors that need to be resized into one place. This will allows to explore different strategies for how to resize a number of vectors.
WeiqunZhang
commented
Oct 25, 2025
Src/Particle/AMReX_ParticleTile.H
Outdated
| } | ||
| } | ||
|
|
||
| // xxxxx TODO: Can we come up a better strategy? |
Member
Author
There was a problem hiding this comment.
Maybe we can try to shrink the size first if a vector has say 2x capacity than needed. Then we can order the vectors by their future capacity, and reserve big vectors first.
Member
Author
There was a problem hiding this comment.
If a reserve fails, maybe we should try to defragment these vectors that are under our control. We can order them by their pointer address, and then try to move the vectors to lower addresses.
WeiqunZhang
commented
Oct 25, 2025
WeiqunZhang
commented
Oct 25, 2025
asalmgren
approved these changes
Jan 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When redistributing particles, we need to resize a number of vectors. This sometimes causes out-of-memory issues for GPU runs, because the vector resize may fragment the memory arena. To address the issue, we try to minimize the number of memory reallocation calls by reserving space before we unpack local and remote communication buffers. Previously, resize may cause memory reallocation in both unpacking operations.
We have also collected all the vectors that need to be resized into one place. This will allows to explore different strategies for how to resize a number of vectors.