Skip to content

Commit

Permalink
PureSoA IdCpu fixes (AMReX-Codes#3671)
Browse files Browse the repository at this point in the history
## Summary

I noticed a few issues in AMReX while trying to update HiPACE++ for
AMReX-Codes#3585.

Additionally, I would like to point out that `ParticleTile` has
`push_back_real` and `push_back_int` functions but for PureSoA there is
no `push_back_idcpu`, however this is not added in this PR.

## Additional background

## Checklist

The proposed changes:
- [x] fix a bug or incorrect behavior in AMReX
- [ ] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate
  • Loading branch information
AlexanderSinn authored Dec 15, 2023
1 parent 0c6f2b4 commit 554b1ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
9 changes: 0 additions & 9 deletions Src/Particle/AMReX_Particle.H
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ namespace
constexpr Long NoSplitParticleID = GhostParticleID - 4;
}

/** Used for 32bit int particle Ids, as in pure SoA layout */
namespace IntParticleIds {
constexpr int GhostParticleID = 2147483647; // 2**31-1
constexpr int VirtualParticleID = GhostParticleID - 1;
constexpr int LastParticleID = GhostParticleID - 2;
constexpr int DoSplitParticleID = GhostParticleID - 3;
constexpr int NoSplitParticleID = GhostParticleID - 4;
}

using namespace LongParticleIds;
}

Expand Down
16 changes: 11 additions & 5 deletions Src/Particle/AMReX_ParticleTile.H
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ SoAParticle<NArrayReal, NArrayInt>::NextID ()
#endif
next = the_next_id++;

if (next > IntParticleIds::LastParticleID) {
if (next > LongParticleIds::LastParticleID) {
amrex::Abort("SoAParticle<NArrayReal, NArrayInt>::NextID() -- too many particles");
}

Expand All @@ -470,7 +470,7 @@ int
SoAParticle<NArrayReal, NArrayInt>::UnprotectedNextID ()
{
int next = the_next_id++;
if (next > IntParticleIds::LastParticleID) {
if (next > LongParticleIds::LastParticleID) {
amrex::Abort("SoAParticle<NArrayReal, NArrayInt>::NextID() -- too many particles");
}
return next;
Expand Down Expand Up @@ -1039,7 +1039,9 @@ struct ParticleTile

void shrink_to_fit ()
{
if constexpr (!ParticleType::is_soa_particle) {
if constexpr (ParticleType::is_soa_particle) {
GetStructOfArrays().GetIdCPUData().shrink_to_fit();
} else {
m_aos_tile().shrink_to_fit();
}
for (int j = 0; j < NumRealComps(); ++j)
Expand All @@ -1058,7 +1060,9 @@ struct ParticleTile
Long capacity () const
{
Long nbytes = 0;
if constexpr (!ParticleType::is_soa_particle) {
if constexpr (ParticleType::is_soa_particle) {
nbytes += GetStructOfArrays().GetIdCPUData().capacity() * sizeof(uint64_t);
} else {
nbytes += m_aos_tile().capacity() * sizeof(ParticleType);
}
for (int j = 0; j < NumRealComps(); ++j)
Expand All @@ -1077,7 +1081,9 @@ struct ParticleTile

void swap (ParticleTile<ParticleType, NArrayReal, NArrayInt, Allocator>& other)
{
if constexpr (!ParticleType::is_soa_particle) {
if constexpr (ParticleType::is_soa_particle) {
GetStructOfArrays().GetIdCPUData().swap(other.GetStructOfArrays().GetIdCPUData());
} else {
m_aos_tile().swap(other.GetArrayOfStructs()());
}
for (int j = 0; j < NumRealComps(); ++j)
Expand Down
3 changes: 1 addition & 2 deletions Src/Particle/AMReX_StructOfArrays.H
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,12 @@ struct StructOfArrays {
for (int i = 0; i < int(m_runtime_idata.size()); ++i) { m_runtime_idata[i].resize(count); }
}

[[nodiscard]] IdCPU* idcpuarray () {
[[nodiscard]] uint64_t* idcpuarray () {
if constexpr (use64BitIdCpu == true) {
return m_idcpu.dataPtr();
} else {
return nullptr;
}

}

[[nodiscard]] GpuArray<ParticleReal*, NReal> realarray ()
Expand Down

0 comments on commit 554b1ca

Please sign in to comment.