From 58b4323959ef06b52c0778764484a42b11b14ca4 Mon Sep 17 00:00:00 2001 From: Ryan Ammann Date: Thu, 15 Oct 2026 13:10:38 +0200 Subject: [PATCH] Move localNum_m increment up --- src/Particle/ParticleBase.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Particle/ParticleBase.hpp b/src/Particle/ParticleBase.hpp index fbbe72638d..ff6af493b9 100644 --- a/src/Particle/ParticleBase.hpp +++ b/src/Particle/ParticleBase.hpp @@ -94,27 +94,27 @@ namespace ippl { attribute->create(nLocal, non_destructive); }); + // remember that we're creating these new particles. This must happen before + // ID.getView() below, which only covers the first localNum_m entries. + const size_type offset = localNum_m; + localNum_m += nLocal; + if constexpr (EnableIDs) { // Set the unique ID value for these new particles. The new entries - // live at indices [localNum_m, localNum_m + nLocal); the k-th new + // live at indices [offset, offset + nLocal); the k-th new // particle on this rank gets ID nextID + numNodes * k. using policy_type = Kokkos::RangePolicy; auto pIDs = ID.getView(); auto nextID = this->nextID_m; auto numNodes = this->numNodes_m; - auto offset = localNum_m; Kokkos::parallel_for( - "ParticleBase<...>::create(size_t,bool)", - policy_type(localNum_m, localNum_m + nLocal), + "ParticleBase<...>::create(size_t,bool)", policy_type(offset, offset + nLocal), KOKKOS_LAMBDA(const std::int64_t i) { pIDs(i) = nextID + numNodes * (i - offset); }); nextID_m += numNodes_m * nLocal; } - - // remember that we're creating these new particles - localNum_m += nLocal; } Comm->allreduce(localNum_m, totalNum_m, 1, std::plus());