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

Fix optional component communication for pure SoA particles #4333

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 5 additions & 15 deletions Src/Particle/AMReX_ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ public:
//! of a level hierarchy. Must be properly initialized later.
ParticleContainer_impl ()
:
ParticleContainerBase(),
h_redistribute_real_comp(AMREX_SPACEDIM + NStructReal + NArrayReal, true),
h_redistribute_int_comp(2 + NStructInt + NArrayInt, true)
ParticleContainerBase()
{
Initialize ();
}
Expand All @@ -215,9 +213,7 @@ public:
//!
ParticleContainer_impl (ParGDBBase* gdb)
:
ParticleContainerBase(gdb),
h_redistribute_real_comp(AMREX_SPACEDIM + NStructReal + NArrayReal, true),
h_redistribute_int_comp(2 + NStructInt + NArrayInt, true)
ParticleContainerBase(gdb)
{
Initialize ();
ParticleContainer_impl::reserveData();
Expand All @@ -235,9 +231,7 @@ public:
const DistributionMapping & dmap,
const BoxArray & ba)
:
ParticleContainerBase(geom, dmap, ba),
h_redistribute_real_comp(AMREX_SPACEDIM + NStructReal + NArrayReal, true),
h_redistribute_int_comp(2 + NStructInt + NArrayInt, true)
ParticleContainerBase(geom, dmap, ba)
{
Initialize ();
ParticleContainer_impl::reserveData();
Expand All @@ -258,9 +252,7 @@ public:
const Vector<BoxArray> & ba,
const Vector<int> & rr)
:
ParticleContainerBase(geom, dmap, ba, rr),
h_redistribute_real_comp(AMREX_SPACEDIM + NStructReal + NArrayReal, true),
h_redistribute_int_comp(2 + NStructInt + NArrayInt, true)
ParticleContainerBase(geom, dmap, ba, rr)
{
Initialize ();
ParticleContainer_impl::reserveData();
Expand All @@ -280,9 +272,7 @@ public:
const Vector<BoxArray> & ba,
const Vector<IntVect> & rr)
:
ParticleContainerBase(geom, dmap, ba, rr),
h_redistribute_real_comp(AMREX_SPACEDIM + NStructReal + NArrayReal, true),
h_redistribute_int_comp(2 + NStructInt + NArrayInt, true)
ParticleContainerBase(geom, dmap, ba, rr)
{
Initialize ();
ParticleContainer_impl::reserveData();
Expand Down
34 changes: 29 additions & 5 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::SetParticleSize ()
{
num_real_comm_comps = 0;
int comm_comps_start = AMREX_SPACEDIM + NStructReal;
int comm_comps_start = 0;
if constexpr (!ParticleType::is_soa_particle) {
comm_comps_start += AMREX_SPACEDIM + NStructReal;
}
for (int i = comm_comps_start; i < comm_comps_start + NumRealComps(); ++i) {
if (h_redistribute_real_comp[i]) {++num_real_comm_comps;}
}
Expand Down Expand Up @@ -45,6 +48,15 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
usePrePost = false;
doUnlink = true;

// by default communicate all components
if constexpr (ParticleType::is_soa_particle)
{
h_redistribute_real_comp.resize(NArrayReal, true);
} else {
h_redistribute_real_comp.resize(AMREX_SPACEDIM + NStructReal + NArrayReal, true);
}
h_redistribute_int_comp.resize(2 + NStructInt + NArrayInt, true);

SetParticleSize();

// add default names for SoA Real and Int compile-time arguments
Expand Down Expand Up @@ -1742,7 +1754,10 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
particles_to_send.resize(new_size);
std::memcpy(&particles_to_send[old_size], &p, particle_size);
char* dst = &particles_to_send[old_size] + particle_size;
int array_comp_start = AMREX_SPACEDIM + NStructReal;
int array_comp_start = 0;
if constexpr (!ParticleType::is_soa_particle) {
array_comp_start = AMREX_SPACEDIM + NStructReal;
}
for (int comp = 0; comp < NumRealComps(); comp++) {
if (h_redistribute_real_comp[array_comp_start + comp]) {
std::memcpy(dst, &soa.GetRealData(comp)[pindex], sizeof(ParticleReal));
Expand Down Expand Up @@ -1866,7 +1881,10 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
std::memcpy(dst, &soa.GetIdCPUData()[pindex], sizeof(uint64_t));
dst += sizeof(uint64_t);
}
int array_comp_start = AMREX_SPACEDIM + NStructReal;
int array_comp_start = 0;
if constexpr (!ParticleType::is_soa_particle) {
array_comp_start = AMREX_SPACEDIM + NStructReal;
}
for (int comp = 0; comp < NumRealComps(); comp++) {
if (h_redistribute_real_comp[array_comp_start + comp]) {
std::memcpy(dst, &soa.GetRealData(comp)[pindex], sizeof(ParticleReal));
Expand Down Expand Up @@ -2267,7 +2285,10 @@ RedistributeMPI (std::map<int, Vector<char> >& not_ours,
ptile.push_back(p);
}

int array_comp_start = AMREX_SPACEDIM + NStructReal;
int array_comp_start = 0;
if constexpr (!ParticleType::is_soa_particle) {
array_comp_start = AMREX_SPACEDIM + NStructReal;
}
for (int comp = 0; comp < NumRealComps(); ++comp) {
if (h_redistribute_real_comp[array_comp_start + comp]) {
ParticleReal rdata;
Expand Down Expand Up @@ -2345,7 +2366,10 @@ RedistributeMPI (std::map<int, Vector<char> >& not_ours,
host_int_attribs[lev][ind].resize(NumIntComps());

// add the real...
int array_comp_start = AMREX_SPACEDIM + NStructReal;
int array_comp_start = 0;
if constexpr (!ParticleType::is_soa_particle) {
array_comp_start = AMREX_SPACEDIM + NStructReal;
}
for (int comp = 0; comp < NumRealComps(); ++comp) {
if (h_redistribute_real_comp[array_comp_start + comp]) {
Real rdata;
Expand Down
Loading