Skip to content

Commit b533128

Browse files
cleaning and fixes for PureSoA ParticleTile (#3327)
## Summary * fix return by value/reference mismatch of `id()` and `cpu()` with `decltype(auto)` * update `packParticleData` and `unpackParticleData` for PureSoA * change `getSuperParticle` and add `setSuperParticle` for PureSoA. Remaining issue: super particle has redundant/unused fields for positions, id and cpu * update `ConstParticleTileData` for PureSoA * don’t call `getParticleTileData` in `ParticleTile::id()` etc. as this could be very slow if used in a for loop * use if constexpr instead if SFINAE in a number of places * change PODVector constructor so that `getParticleTileData()` won't allocate memory if no runtime components are used ## Additional background Follow-up to #2878. ## 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 d65dd90 commit b533128

File tree

6 files changed

+187
-202
lines changed

6 files changed

+187
-202
lines changed

Src/Base/AMReX_PODVector.H

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,32 +262,40 @@ namespace amrex
262262
explicit PODVector (size_type a_size) noexcept
263263
: m_data(nullptr), m_size(a_size)
264264
{
265-
AllocateBuffer(GetNewCapacity(a_size));
265+
if (a_size != 0) {
266+
AllocateBuffer(GetNewCapacity(a_size));
267+
}
266268
}
267269

268270
PODVector (size_type a_size, const value_type& a_value,
269271
const allocator_type& a_allocator = Allocator()) noexcept
270272
: Allocator(a_allocator), m_data(nullptr), m_size(a_size)
271273
{
272-
AllocateBuffer(GetNewCapacity(a_size));
273-
detail::uninitializedFillNImpl<Allocator>(m_data, a_size, a_value, *this);
274+
if (a_size != 0) {
275+
AllocateBuffer(GetNewCapacity(a_size));
276+
detail::uninitializedFillNImpl<Allocator>(m_data, a_size, a_value, *this);
277+
}
274278
}
275279

276280
PODVector (std::initializer_list<T> a_initializer_list,
277281
const allocator_type& a_allocator = Allocator()) noexcept
278282
: Allocator(a_allocator), m_data(nullptr), m_size(a_initializer_list.size())
279283
{
280-
AllocateBuffer(GetNewCapacity(m_size));
281-
detail::initFromListImpl<Allocator>(m_data, a_initializer_list, *this);
284+
if (a_initializer_list.size() != 0) {
285+
AllocateBuffer(GetNewCapacity(m_size));
286+
detail::initFromListImpl<Allocator>(m_data, a_initializer_list, *this);
287+
}
282288
}
283289

284290
PODVector (const PODVector<T, Allocator>& a_vector) noexcept
285291
: Allocator(a_vector), m_data(nullptr), m_size(a_vector.size())
286292
{
287293
using namespace detail;
288-
AllocateBuffer(a_vector.capacity());
289-
auto r = memCopyImpl<Allocator>(m_data, a_vector.m_data, a_vector.size() * sizeof(T), *this);
290-
if (r) { Gpu::streamSynchronize(); }
294+
if (a_vector.size() != 0) {
295+
AllocateBuffer(a_vector.capacity());
296+
auto r = memCopyImpl<Allocator>(m_data, a_vector.m_data, a_vector.size() * sizeof(T), *this);
297+
if (r) { Gpu::streamSynchronize(); }
298+
}
291299
}
292300

293301
PODVector (PODVector<T, Allocator>&& a_vector) noexcept

Src/F_Interfaces/Particle/AMReX_particlecontainer_fi.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ extern "C" {
6969
}
7070

7171
void amrex_fi_get_particles_mfi(FParticleContainer* particlecontainer,
72-
int lev, MFIter* mfi, ParticleReal*& dp, Long& np)
72+
int lev, MFIter* mfi,
73+
FParticleContainer::ParticleType*& dp, Long& np)
7374
{
7475
const int grid = mfi->index();
7576
const int tile = mfi->LocalTileIndex();
@@ -116,7 +117,8 @@ extern "C" {
116117
}
117118

118119
void amrex_fi_get_particles_i(FParticleContainer* particlecontainer,
119-
int lev, int grid, int tile, ParticleReal*& dp, Long& np)
120+
int lev, int grid, int tile,
121+
FParticleContainer::ParticleType*& dp, Long& np)
120122
{
121123
auto& particle_level = particlecontainer->GetParticles(lev);
122124
auto search = particle_level.find(std::make_pair(grid, tile));

Src/Particle/AMReX_ArrayOfStructs.H

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public:
6262
resize(nrp + num_neighbors);
6363
}
6464

65-
[[nodiscard]] int getNumNeighbors () { return m_num_neighbor_particles; }
65+
[[nodiscard]] int getNumNeighbors () const { return m_num_neighbor_particles; }
6666

6767
[[nodiscard]] bool empty () const { return m_data.empty(); }
6868

69-
[[nodiscard]] const RealType* data () const { return &(m_data[0].m_pos[0]); }
70-
[[nodiscard]] RealType* data () { return &(m_data[0].m_pos[0]); }
69+
[[nodiscard]] const ParticleType* data () const { return m_data.data(); }
70+
[[nodiscard]] ParticleType* data () { return m_data.data(); }
7171

72-
[[nodiscard]] const RealType* dataPtr () const { return data(); }
73-
[[nodiscard]] RealType* dataPtr () { return data(); }
72+
[[nodiscard]] const ParticleType* dataPtr () const { return data(); }
73+
[[nodiscard]] ParticleType* dataPtr () { return data(); }
7474

7575
[[nodiscard]] std::pair<int,int> dataShape () const {
7676
return std::make_pair(SizeInReal, static_cast<int>(m_data.size()));

Src/Particle/AMReX_ParticleContainerI.H

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,9 +1090,8 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
10901090
::ReorderParticles (int lev, const MFIter& mfi, const index_type* permutations)
10911091
{
10921092
auto& ptile = ParticlesAt(lev, mfi);
1093-
auto& aos = ptile.GetArrayOfStructs();
1094-
const size_t np = aos.numParticles();
1095-
const size_t np_total = np + aos.numNeighborParticles();
1093+
const size_t np = ptile.numParticles();
1094+
const size_t np_total = np + ptile.numNeighborParticles();
10961095

10971096
if (memEfficientSort) {
10981097
if constexpr(!ParticleType::is_soa_particle) {

0 commit comments

Comments
 (0)