Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Src/Particle/AMReX_Particle.H
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,10 @@ struct alignas(sizeof(double)) Particle
wrapper = id;
#if defined(AMREX_USE_OMP)
#pragma omp atomic write
this->m_idcpu = wrapper.m_idata;
this->m_idcpu = *(wrapper.m_idata);
#else
auto *old_ptr = reinterpret_cast<unsigned long long*>(&(this->m_idcpu));
amrex::Gpu::Atomic::Exch(old_ptr, (unsigned long long) wrapper.m_idata);
amrex::Gpu::Atomic::Exch(old_ptr, (unsigned long long) (*wrapper.m_idata));
#endif
}

Expand Down
26 changes: 26 additions & 0 deletions Tests/Particles/ParallelContext/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,32 @@ class TestParticleContainer
#endif
});
}

amrex::ParallelFor(np,
[=] AMREX_GPU_DEVICE (size_t i) noexcept
{
ParticleType& p = pstruct[i];
auto old_id = p.id();
auto new_id = 5000 + p.id();
p.atomicSetID(new_id);
#ifndef AMREX_USE_GPU
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(p.id() == new_id,
"atomicSetID failed: expected " +
std::to_string(new_id) + " but got " +
std::to_string(p.id()));
#else
AMREX_ALWAYS_ASSERT(p.id() == new_id);
#endif
p.atomicSetID(new_id - 5000);
#ifndef AMREX_USE_GPU
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(p.id() == old_id,
"atomicSetID failed: expected " +
std::to_string(old_id) + " but got " +
std::to_string(p.id()));
#else
AMREX_ALWAYS_ASSERT(p.id() == old_id);
#endif
});
}
}
}
Expand Down
Loading