Skip to content

Commit 9d2b749

Browse files
authored
fix atomicSetID wrapper access (#4625)
## Summary - added dereference needed for using ParticleIDWrapper object - added assertions to a test for checking ## Additional background - Originally seen as the following error while debugging Artemis CI: ``` error: invalid conversion from ‘long unsigned int*’ to ‘uint64_t’ {aka ‘long unsigned int’} [-fpermissive] 436 | this->m_idcpu = wrapper.m_idata; | ~~~~~~~~^~~~~~~ | | | long unsigned int* ``` ## Checklist The proposed changes: - [X] fix a bug or incorrect behavior in AMReX - [ ] 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 cc67e4b commit 9d2b749

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Src/Particle/AMReX_Particle.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,10 @@ struct alignas(sizeof(double)) Particle
435435
wrapper = id;
436436
#if defined(AMREX_USE_OMP)
437437
#pragma omp atomic write
438-
this->m_idcpu = wrapper.m_idata;
438+
this->m_idcpu = *(wrapper.m_idata);
439439
#else
440440
auto *old_ptr = reinterpret_cast<unsigned long long*>(&(this->m_idcpu));
441-
amrex::Gpu::Atomic::Exch(old_ptr, (unsigned long long) wrapper.m_idata);
441+
amrex::Gpu::Atomic::Exch(old_ptr, (unsigned long long) (*wrapper.m_idata));
442442
#endif
443443
}
444444

Tests/Particles/ParallelContext/main.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,32 @@ class TestParticleContainer
222222
#endif
223223
});
224224
}
225+
226+
amrex::ParallelFor(np,
227+
[=] AMREX_GPU_DEVICE (size_t i) noexcept
228+
{
229+
ParticleType& p = pstruct[i];
230+
auto old_id = p.id();
231+
auto new_id = 5000 + p.id();
232+
p.atomicSetID(new_id);
233+
#ifndef AMREX_USE_GPU
234+
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(p.id() == new_id,
235+
"atomicSetID failed: expected " +
236+
std::to_string(new_id) + " but got " +
237+
std::to_string(p.id()));
238+
#else
239+
AMREX_ALWAYS_ASSERT(p.id() == new_id);
240+
#endif
241+
p.atomicSetID(new_id - 5000);
242+
#ifndef AMREX_USE_GPU
243+
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(p.id() == old_id,
244+
"atomicSetID failed: expected " +
245+
std::to_string(old_id) + " but got " +
246+
std::to_string(p.id()));
247+
#else
248+
AMREX_ALWAYS_ASSERT(p.id() == old_id);
249+
#endif
250+
});
225251
}
226252
}
227253
}

0 commit comments

Comments
 (0)