Skip to content

Commit 554b1ca

Browse files
PureSoA IdCpu fixes (#3671)
## Summary I noticed a few issues in AMReX while trying to update HiPACE++ for #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
1 parent 0c6f2b4 commit 554b1ca

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

Src/Particle/AMReX_Particle.H

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ namespace
2424
constexpr Long NoSplitParticleID = GhostParticleID - 4;
2525
}
2626

27-
/** Used for 32bit int particle Ids, as in pure SoA layout */
28-
namespace IntParticleIds {
29-
constexpr int GhostParticleID = 2147483647; // 2**31-1
30-
constexpr int VirtualParticleID = GhostParticleID - 1;
31-
constexpr int LastParticleID = GhostParticleID - 2;
32-
constexpr int DoSplitParticleID = GhostParticleID - 3;
33-
constexpr int NoSplitParticleID = GhostParticleID - 4;
34-
}
35-
3627
using namespace LongParticleIds;
3728
}
3829

Src/Particle/AMReX_ParticleTile.H

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ SoAParticle<NArrayReal, NArrayInt>::NextID ()
458458
#endif
459459
next = the_next_id++;
460460

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

@@ -470,7 +470,7 @@ int
470470
SoAParticle<NArrayReal, NArrayInt>::UnprotectedNextID ()
471471
{
472472
int next = the_next_id++;
473-
if (next > IntParticleIds::LastParticleID) {
473+
if (next > LongParticleIds::LastParticleID) {
474474
amrex::Abort("SoAParticle<NArrayReal, NArrayInt>::NextID() -- too many particles");
475475
}
476476
return next;
@@ -1039,7 +1039,9 @@ struct ParticleTile
10391039

10401040
void shrink_to_fit ()
10411041
{
1042-
if constexpr (!ParticleType::is_soa_particle) {
1042+
if constexpr (ParticleType::is_soa_particle) {
1043+
GetStructOfArrays().GetIdCPUData().shrink_to_fit();
1044+
} else {
10431045
m_aos_tile().shrink_to_fit();
10441046
}
10451047
for (int j = 0; j < NumRealComps(); ++j)
@@ -1058,7 +1060,9 @@ struct ParticleTile
10581060
Long capacity () const
10591061
{
10601062
Long nbytes = 0;
1061-
if constexpr (!ParticleType::is_soa_particle) {
1063+
if constexpr (ParticleType::is_soa_particle) {
1064+
nbytes += GetStructOfArrays().GetIdCPUData().capacity() * sizeof(uint64_t);
1065+
} else {
10621066
nbytes += m_aos_tile().capacity() * sizeof(ParticleType);
10631067
}
10641068
for (int j = 0; j < NumRealComps(); ++j)
@@ -1077,7 +1081,9 @@ struct ParticleTile
10771081

10781082
void swap (ParticleTile<ParticleType, NArrayReal, NArrayInt, Allocator>& other)
10791083
{
1080-
if constexpr (!ParticleType::is_soa_particle) {
1084+
if constexpr (ParticleType::is_soa_particle) {
1085+
GetStructOfArrays().GetIdCPUData().swap(other.GetStructOfArrays().GetIdCPUData());
1086+
} else {
10811087
m_aos_tile().swap(other.GetArrayOfStructs()());
10821088
}
10831089
for (int j = 0; j < NumRealComps(); ++j)

Src/Particle/AMReX_StructOfArrays.H

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,12 @@ struct StructOfArrays {
195195
for (int i = 0; i < int(m_runtime_idata.size()); ++i) { m_runtime_idata[i].resize(count); }
196196
}
197197

198-
[[nodiscard]] IdCPU* idcpuarray () {
198+
[[nodiscard]] uint64_t* idcpuarray () {
199199
if constexpr (use64BitIdCpu == true) {
200200
return m_idcpu.dataPtr();
201201
} else {
202202
return nullptr;
203203
}
204-
205204
}
206205

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

0 commit comments

Comments
 (0)