Skip to content

Commit

Permalink
Add helper function for setting id and cpu simultaneously. (#3733)
Browse files Browse the repository at this point in the history
Also sneaking in a small ignore_unused fix.

Close #3731.

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
  • Loading branch information
atmyers and ax3l authored Jan 31, 2024
1 parent 33dea1f commit 09fc44a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Src/Particle/AMReX_Particle.H
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ struct ConstParticleCPUWrapper
operator int () const noexcept { return static_cast<int>(m_idata & 0x00FFFFFF); }
};

/** Set the idcpu value at once, based on a particle id and cpuid
*
* This can be used in initialization and assignments,
* to avoid writing twice into the same memory bank.
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
std::uint64_t SetParticleIDandCPU (Long id, int cpu) noexcept{
std::uint64_t idcpu = 0;
ParticleIDWrapper{idcpu} = id;
ParticleCPUWrapper{idcpu} = cpu;
return idcpu;
}

template <typename T, int NReal, int NInt>
struct ParticleBase
Expand Down
1 change: 1 addition & 0 deletions Src/Particle/AMReX_ParticleIO.H
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
{
new_size += src_tile.size();
} else {
amrex::ignore_unused(src_tile);
new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].size();
}
dst_tile.resize(new_size);
Expand Down

0 comments on commit 09fc44a

Please sign in to comment.