Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Src/Particle/AMReX_ParticleTileRT.H
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -805,6 +808,15 @@ private:
return static_cast<int>(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;
Expand Down
Loading