Improve support for Particles with PolymorphicArenaAllocator#4603
Conversation
| void SetArena (Arena* a) { | ||
| m_arena = a; | ||
| } |
There was a problem hiding this comment.
@AlexanderSinn @atmyers I am wondering: should we add an assert here that setting the arena can only be done once?
There are already good asserts / exceptions now if a PC with an unset allocator is trying to add particles. Thus, the logic here could be as easy as: assert if m_arena is not nullptr when callint SetArena. What do you think?
I want to avoid that someone calls SetArena for an already defined PC with live particles and gets into an unexpected state by that.
| void SetArena (Arena* a) { | |
| m_arena = a; | |
| } | |
| void SetArena (Arena* a) { | |
| AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_arena == nullptr, "SetArena can only be called once per PC!"); | |
| m_arena = a; | |
| } |
(Technically, we can make it more complicated, like allowing to switch the arena until any tiles/particles are added. That could be useful in some usage patterns when specializing a user container that might set a default in its constructor.)
There was a problem hiding this comment.
There was a problem hiding this comment.
There is the a_arena == GetStructOfArrays().GetIdCPUData().arena() check in ParticleTile that should catch this issue, but I guess we could add another check to ParticleContainerBase
Summary
This PR adds a
SetArena(Arena*)function to ParticleContainerBase that allows setting a memory arena that is used for all the particle vectors if the allocator is PolymorphicArenaAllocator. The function has to be called before particle tiles are defined.This functionality is used to fix a bunch of places where a polymorphic vector would previously not have its arena set properly.
Additionally the
RunOnGpulogic inAMReX_WriteBinaryParticleData.His extended to work with a polymorphic allocator.Uses changes extracted from #4404.
Additional background
Previously all components of all particle tiles needed their arena set individually by the user if PolymorphicArenaAllocator was used. In case this was done this PR is a braking change due to the
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(a_arena != nullptrassert inParticleTile::define().Checklist
The proposed changes: