Skip to content

Commit d448c17

Browse files
ax3lAlexanderSinn
andauthored
ParticleTile: More SoA Updates (#3305)
## Summary More updates to `ParticleTile` and simplifications for pure SoA support. ## Additional background Isolated from #3290 and author credited to @AlexanderSinn. ## Checklist The proposed changes: - [ ] 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 Co-authored-by: Alexander Sinn <[email protected]>
1 parent 1a96800 commit d448c17

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

Src/Particle/AMReX_ParticleTile.H

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,13 @@ struct ParticleTileData
109109
}
110110

111111
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
112-
auto* rdata (const int attribute_index)
112+
auto * rdata (const int attribute_index) const
113113
{
114114
return this->m_rdata[attribute_index];
115115
}
116116

117117
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
118-
auto const * rdata (const int attribute_index) const
119-
{
120-
return this->m_rdata[attribute_index];
121-
}
122-
123-
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
124-
auto* idata (const int attribute_index)
125-
{
126-
return this->m_idata[attribute_index];
127-
}
128-
129-
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
130-
auto const * idata (const int attribute_index) const
118+
auto * idata (const int attribute_index) const
131119
{
132120
return this->m_idata[attribute_index];
133121
}
@@ -746,11 +734,7 @@ struct ParticleTile
746734
SoA& GetStructOfArrays () { return m_soa_tile; }
747735
const SoA& GetStructOfArrays () const { return m_soa_tile; }
748736

749-
template <typename T = ParticleType, typename std::enable_if<!T::is_soa_particle, int>::type = 0>
750-
bool empty () const { return m_aos_tile.empty(); }
751-
752-
template <typename T = ParticleType, typename std::enable_if<T::is_soa_particle, int>::type = 0>
753-
bool empty () const { return m_soa_tile.empty(); }
737+
bool empty () const { return size() == 0; }
754738

755739
/**
756740
* \brief Returns the total number of particles (real and neighbor)
@@ -817,7 +801,9 @@ struct ParticleTile
817801

818802
void resize (std::size_t count)
819803
{
820-
m_aos_tile.resize(count);
804+
if constexpr (!ParticleType::is_soa_particle) {
805+
m_aos_tile.resize(count);
806+
}
821807
m_soa_tile.resize(count);
822808
}
823809

@@ -969,7 +955,9 @@ struct ParticleTile
969955

970956
void shrink_to_fit ()
971957
{
972-
m_aos_tile().shrink_to_fit();
958+
if constexpr (!ParticleType::is_soa_particle) {
959+
m_aos_tile().shrink_to_fit();
960+
}
973961
for (int j = 0; j < NumRealComps(); ++j)
974962
{
975963
auto& rdata = GetStructOfArrays().GetRealData(j);
@@ -986,7 +974,9 @@ struct ParticleTile
986974
Long capacity () const
987975
{
988976
Long nbytes = 0;
989-
nbytes += m_aos_tile().capacity() * sizeof(ParticleType);
977+
if constexpr (!ParticleType::is_soa_particle) {
978+
nbytes += m_aos_tile().capacity() * sizeof(ParticleType);
979+
}
990980
for (int j = 0; j < NumRealComps(); ++j)
991981
{
992982
auto& rdata = GetStructOfArrays().GetRealData(j);
@@ -1003,7 +993,9 @@ struct ParticleTile
1003993

1004994
void swap (ParticleTile<ParticleType, NArrayReal, NArrayInt, Allocator>& other)
1005995
{
1006-
m_aos_tile().swap(other.GetArrayOfStructs()());
996+
if constexpr (!ParticleType::is_soa_particle) {
997+
m_aos_tile().swap(other.GetArrayOfStructs()());
998+
}
1007999
for (int j = 0; j < NumRealComps(); ++j)
10081000
{
10091001
auto& rdata = GetStructOfArrays().GetRealData(j);
@@ -1052,7 +1044,11 @@ struct ParticleTile
10521044
#endif
10531045

10541046
ParticleTileDataType ptd;
1055-
ptd.m_aos = m_aos_tile().dataPtr();
1047+
if constexpr (!ParticleType::is_soa_particle) {
1048+
ptd.m_aos = m_aos_tile().dataPtr();
1049+
} else {
1050+
ptd.m_aos = nullptr;
1051+
}
10561052
if constexpr(NArrayReal > 0)
10571053
for (int i = 0; i < NArrayReal; ++i)
10581054
ptd.m_rdata[i] = m_soa_tile.GetRealData(i).dataPtr();
@@ -1109,7 +1105,11 @@ struct ParticleTile
11091105
#endif
11101106

11111107
ConstParticleTileDataType ptd;
1112-
ptd.m_aos = m_aos_tile().dataPtr();
1108+
if constexpr (!ParticleType::is_soa_particle) {
1109+
ptd.m_aos = m_aos_tile().dataPtr();
1110+
} else {
1111+
ptd.m_aos = nullptr;
1112+
}
11131113
if constexpr(NArrayReal > 0)
11141114
for (int i = 0; i < NArrayReal; ++i)
11151115
ptd.m_rdata[i] = m_soa_tile.GetRealData(i).dataPtr();

0 commit comments

Comments
 (0)