Skip to content

Commit 06ba8bd

Browse files
authored
Add reserve methods to ParticleTile, ArrayOfStructs, and StructOfArrays (#4708)
As with `std::vector`, this allows changing the capacity without changing the size of the underlying containers. The proposed changes: - [ ] fix a bug or incorrect behavior in AMReX - [x] 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 7de101b commit 06ba8bd

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Src/Particle/AMReX_ArrayOfStructs.H

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public:
9393

9494
void resize (size_t count) { m_data.resize(count); }
9595

96+
void reserve (size_t capacity) { m_data.reserve(capacity); }
97+
9698
Iterator erase ( ConstIterator first, ConstIterator second) { return m_data.erase(first, second); }
9799

98100
template< class InputIt >

Src/Particle/AMReX_ParticleTile.H

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,14 @@ struct ParticleTile
973973
m_soa_tile.resize(count);
974974
}
975975

976+
void reserve (std::size_t capacity)
977+
{
978+
if constexpr (!ParticleType::is_soa_particle) {
979+
m_aos_tile.reserve(capacity);
980+
}
981+
m_soa_tile.reserve(capacity);
982+
}
983+
976984
///
977985
/// Add one particle to this tile.
978986
///

Src/Particle/AMReX_StructOfArrays.H

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,21 @@ struct StructOfArrays {
282282
for (int i = 0; i < int(m_runtime_idata.size()); ++i) { m_runtime_idata[i].resize(count); }
283283
}
284284

285+
void reserve (size_t capacity)
286+
{
287+
if constexpr (use64BitIdCpu == true) {
288+
m_idcpu.reserve(capacity);
289+
}
290+
if constexpr (NReal > 0) {
291+
for (int i = 0; i < NReal; ++i) { m_rdata[i].reserve(capacity); }
292+
}
293+
if constexpr (NInt > 0) {
294+
for (int i = 0; i < NInt; ++i) { m_idata[i].reserve(capacity); }
295+
}
296+
for (int i = 0; i < int(m_runtime_rdata.size()); ++i) { m_runtime_rdata[i].reserve(capacity); }
297+
for (int i = 0; i < int(m_runtime_idata.size()); ++i) { m_runtime_idata[i].reserve(capacity); }
298+
}
299+
285300
[[nodiscard]] uint64_t* idcpuarray () {
286301
if constexpr (use64BitIdCpu == true) {
287302
return m_idcpu.dataPtr();

0 commit comments

Comments
 (0)