Skip to content

Commit

Permalink
cleaning and fixes for PureSoA ParticleTile (#3327)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
AlexanderSinn authored May 24, 2023
1 parent d65dd90 commit b533128
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 202 deletions.
24 changes: 16 additions & 8 deletions Src/Base/AMReX_PODVector.H
Original file line number Diff line number Diff line change
Expand Up @@ -262,32 +262,40 @@ namespace amrex
explicit PODVector (size_type a_size) noexcept
: m_data(nullptr), m_size(a_size)
{
AllocateBuffer(GetNewCapacity(a_size));
if (a_size != 0) {
AllocateBuffer(GetNewCapacity(a_size));
}
}

PODVector (size_type a_size, const value_type& a_value,
const allocator_type& a_allocator = Allocator()) noexcept
: Allocator(a_allocator), m_data(nullptr), m_size(a_size)
{
AllocateBuffer(GetNewCapacity(a_size));
detail::uninitializedFillNImpl<Allocator>(m_data, a_size, a_value, *this);
if (a_size != 0) {
AllocateBuffer(GetNewCapacity(a_size));
detail::uninitializedFillNImpl<Allocator>(m_data, a_size, a_value, *this);
}
}

PODVector (std::initializer_list<T> a_initializer_list,
const allocator_type& a_allocator = Allocator()) noexcept
: Allocator(a_allocator), m_data(nullptr), m_size(a_initializer_list.size())
{
AllocateBuffer(GetNewCapacity(m_size));
detail::initFromListImpl<Allocator>(m_data, a_initializer_list, *this);
if (a_initializer_list.size() != 0) {
AllocateBuffer(GetNewCapacity(m_size));
detail::initFromListImpl<Allocator>(m_data, a_initializer_list, *this);
}
}

PODVector (const PODVector<T, Allocator>& a_vector) noexcept
: Allocator(a_vector), m_data(nullptr), m_size(a_vector.size())
{
using namespace detail;
AllocateBuffer(a_vector.capacity());
auto r = memCopyImpl<Allocator>(m_data, a_vector.m_data, a_vector.size() * sizeof(T), *this);
if (r) { Gpu::streamSynchronize(); }
if (a_vector.size() != 0) {
AllocateBuffer(a_vector.capacity());
auto r = memCopyImpl<Allocator>(m_data, a_vector.m_data, a_vector.size() * sizeof(T), *this);
if (r) { Gpu::streamSynchronize(); }
}
}

PODVector (PODVector<T, Allocator>&& a_vector) noexcept
Expand Down
6 changes: 4 additions & 2 deletions Src/F_Interfaces/Particle/AMReX_particlecontainer_fi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ extern "C" {
}

void amrex_fi_get_particles_mfi(FParticleContainer* particlecontainer,
int lev, MFIter* mfi, ParticleReal*& dp, Long& np)
int lev, MFIter* mfi,
FParticleContainer::ParticleType*& dp, Long& np)
{
const int grid = mfi->index();
const int tile = mfi->LocalTileIndex();
Expand Down Expand Up @@ -116,7 +117,8 @@ extern "C" {
}

void amrex_fi_get_particles_i(FParticleContainer* particlecontainer,
int lev, int grid, int tile, ParticleReal*& dp, Long& np)
int lev, int grid, int tile,
FParticleContainer::ParticleType*& dp, Long& np)
{
auto& particle_level = particlecontainer->GetParticles(lev);
auto search = particle_level.find(std::make_pair(grid, tile));
Expand Down
10 changes: 5 additions & 5 deletions Src/Particle/AMReX_ArrayOfStructs.H
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public:
resize(nrp + num_neighbors);
}

[[nodiscard]] int getNumNeighbors () { return m_num_neighbor_particles; }
[[nodiscard]] int getNumNeighbors () const { return m_num_neighbor_particles; }

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

[[nodiscard]] const RealType* data () const { return &(m_data[0].m_pos[0]); }
[[nodiscard]] RealType* data () { return &(m_data[0].m_pos[0]); }
[[nodiscard]] const ParticleType* data () const { return m_data.data(); }
[[nodiscard]] ParticleType* data () { return m_data.data(); }

[[nodiscard]] const RealType* dataPtr () const { return data(); }
[[nodiscard]] RealType* dataPtr () { return data(); }
[[nodiscard]] const ParticleType* dataPtr () const { return data(); }
[[nodiscard]] ParticleType* dataPtr () { return data(); }

[[nodiscard]] std::pair<int,int> dataShape () const {
return std::make_pair(SizeInReal, static_cast<int>(m_data.size()));
Expand Down
5 changes: 2 additions & 3 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
Expand Up @@ -1090,9 +1090,8 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
::ReorderParticles (int lev, const MFIter& mfi, const index_type* permutations)
{
auto& ptile = ParticlesAt(lev, mfi);
auto& aos = ptile.GetArrayOfStructs();
const size_t np = aos.numParticles();
const size_t np_total = np + aos.numNeighborParticles();
const size_t np = ptile.numParticles();
const size_t np_total = np + ptile.numNeighborParticles();

if (memEfficientSort) {
if constexpr(!ParticleType::is_soa_particle) {
Expand Down
Loading

0 comments on commit b533128

Please sign in to comment.