diff --git a/Src/Particle/AMReX_ParticleTileRT.H b/Src/Particle/AMReX_ParticleTileRT.H index 8c4dff93770..2ab6dc9d8fa 100644 --- a/Src/Particle/AMReX_ParticleTileRT.H +++ b/Src/Particle/AMReX_ParticleTileRT.H @@ -639,6 +639,7 @@ struct ParticleTileRT if (m_capacity < new_size) { size_type new_grown_capacity = grow_podvector_capacity(strategy, new_size, m_capacity, sizeof(RType)); + new_grown_capacity = align_capacity(new_grown_capacity); realloc_and_move(new_size, new_grown_capacity, m_n_real, m_n_int); } else { m_size = new_size; @@ -652,6 +653,7 @@ struct ParticleTileRT if (m_capacity < new_capacity) { size_type new_grown_capacity = grow_podvector_capacity(strategy, new_capacity, m_capacity, sizeof(RType)); + new_grown_capacity = align_capacity(new_grown_capacity); realloc_and_move(m_size, new_grown_capacity, m_n_real, m_n_int); } } @@ -737,8 +739,9 @@ struct ParticleTileRT { AMREX_ALWAYS_ASSERT(m_defined); - if (m_size != m_capacity) { - realloc_and_move(m_size, m_size, m_n_real, m_n_int); + size_type aligned_size = align_capacity(m_size); + if (aligned_size < m_capacity) { + realloc_and_move(m_size, aligned_size, m_n_real, m_n_int); } } @@ -805,6 +808,15 @@ private: return static_cast(std::distance(name_list->begin(), pos)); } + static size_type align_capacity (size_type capacity) { + const auto aligment_in_bytes = Arena::align_size; + const auto aligment_in_elements = aligment_in_bytes / std::gcd( + std::gcd(aligment_in_bytes, sizeof(uint64_t)), + std::gcd(sizeof(RType), sizeof(IType)) + ); + return (capacity + aligment_in_elements - 1) / aligment_in_elements * aligment_in_elements; + } + bool m_defined = false; Arena* m_arena = nullptr;