54 template <
class PLayout,
typename... IP>
66 R.set_name(
"position");
69 template <
class PLayout,
typename... IP>
75 template <
class PLayout,
typename... IP>
76 template <
typename MemorySpace>
82 template <
class PLayout,
typename... IP>
90 template <
class PLayout,
typename... IP>
96 attribute->create(nLocal);
102 Kokkos::RangePolicy<size_type, typename particle_index_type::execution_space>;
103 auto pIDs =
ID.getView();
106 Kokkos::parallel_for(
107 "ParticleBase<...>::create(size_t)", policy_type(
localNum_m, nLocal),
108 KOKKOS_LAMBDA(
const std::int64_t i) { pIDs(i) = nextID + numNodes * i; });
120 template <
class PLayout,
typename... IP>
137 template <
class PLayout,
typename... IP>
144 const size_t rank =
Comm->rank();
154 template <
class PLayout,
typename... IP>
155 template <
typename... Properties>
163 template <
class PLayout,
typename... IP>
164 template <
typename... Properties>
166 const Kokkos::View<bool*, Properties...>& invalid,
const size_type destroyNum) {
170 if (destroyNum == 0) {
182 using view_type = Kokkos::View<
bool*, Properties...>;
183 using memory_space =
typename view_type::memory_space;
184 using execution_space =
typename view_type::execution_space;
185 using policy_type = Kokkos::RangePolicy<execution_space>;
187 auto& locKeepIndex =
keepIndex_m.get<memory_space>();
192 int overalloc =
Comm->getDefaultOverallocation();
195 if (del.size() < destroyNum) {
196 Kokkos::realloc(del, destroyNum * overalloc);
197 Kokkos::realloc(keep, destroyNum * overalloc);
203 Kokkos::deep_copy(locDeleteIndex, -1);
206 Kokkos::parallel_scan(
207 "Scan in ParticleBase::destroy()", policy_type(0, localNum_m - destroyNum),
208 KOKKOS_LAMBDA(
const size_t i,
int& idx,
const bool final) {
209 if (
final && invalid(i)) {
210 locDeleteIndex(idx) = i;
220 Kokkos::parallel_reduce(
221 "Reduce in ParticleBase::destroy()", policy_type(0, destroyNum),
222 KOKKOS_LAMBDA(
const size_t i,
size_t& maxIdx) {
223 if (locDeleteIndex(i) >= 0 && i > maxIdx) {
227 Kokkos::Max<size_type>(maxDeleteIndex));
230 Kokkos::parallel_scan(
231 "Second scan in ParticleBase::destroy()",
232 Kokkos::RangePolicy<size_type, execution_space>(localNum_m - destroyNum, localNum_m),
233 KOKKOS_LAMBDA(
const size_t i,
int& idx,
const bool final) {
234 if (
final && !invalid(i)) {
235 locKeepIndex(idx) = i;
244 localNum_m -= destroyNum;
249 auto filter = [&]<
typename MemorySpace>() {
252 deleteIndex_m.copyToOtherSpaces<memory_space>(filter);
260 using att_memory_space =
typename Attribute::memory_space;
263 attribute->destroy(del, keep, maxDeleteIndex + 1);
267 template <
class PLayout,
typename... IP>
268 template <
typename HashType>
270 std::vector<MPI_Request>& requests,
271 const HashType& hash) {
273 requests.resize(requests.size() + 1);
280 size_type bufSize = packedSize<MemorySpace>(nSends);
285 auto buf =
Comm->getBuffer<MemorySpace>(bufSize);
287 Comm->isend(rank, tag++, *
this, *buf, requests.back(), nSends);
288 buf->resetWritePos();
292 template <
class PLayout,
typename... IP>
300 auto buf =
Comm->getBuffer<MemorySpace>(bufSize);
302 Comm->recv(rank, tag++, *
this, *buf, bufSize, nRecvs);
308 template <
class PLayout,
typename... IP>
309 template <
typename Archive>
311 using memory_space =
typename Archive::buffer_type::memory_space;
313 att->serialize(ar, nsends);
317 template <
class PLayout,
typename... IP>
318 template <
typename Archive>
320 using memory_space =
typename Archive::buffer_type::memory_space;
322 att->deserialize(ar, nrecvs);
326 template <
class PLayout,
typename... IP>
327 template <
typename MemorySpace>
331 total += att->packedSize(count);
336 template <
class PLayout,
typename... IP>
340 for (
unsigned j = 0; j < att.size(); j++) {
346 template <
class PLayout,
typename... IP>
350 for (
unsigned j = 0; j < att.size(); j++) {
351 att[j]->unpack(nrecvs);
354 localNum_m += nrecvs;
typename ippl::detail::ViewType< ippl::Vector< double, Dim >, 1 >::view_type view_type
ippl::detail::size_type size_type
void unpack(const ippl::NDIndex< 3 > intersect, const Kokkos::View< Tf *** > &view, ippl::detail::FieldBufferData< Tb > &fd, int nghost, const ippl::NDIndex< 3 > ldom, bool x=false, bool y=false, bool z=false)
void pack(const ippl::NDIndex< 3 > intersect, Kokkos::View< Tf *** > &view, ippl::detail::FieldBufferData< Tb > &fd, int nghost, const ippl::NDIndex< 3 > ldom, ippl::mpi::Communicator::size_type &nsends)
std::unique_ptr< mpi::Communicator > Comm
KOKKOS_INLINE_FUNCTION auto & get(Tuple< Ts... > &t)
Accessor function to get an element mutable reference at a specific index from a Tuple.
void runForAllSpaces(Functor &&f)
void setParticleCount(size_type &num)
void create(size_type nLocal)
void addAttribute(detail::ParticleAttribBase< MemorySpace > &pa)
typename detail::ContainerForAllSpaces< detail::hash_type >::type hash_container_type
index_type nextID_m
next unique particle ID
void pack(const hash_container_type &hash)
size_type localNum_m
processor local number of particles
void serialize(Archive &ar, size_type nsends)
attribute_container_type attributes_m
all attributes
void internalDestroy(const Kokkos::View< bool *, Properties... > &invalid, const size_type destroyNum)
detail::size_type size_type
void globalCreate(size_type nTotal)
void forAllAttributes(Functor &&f) const
Layout_t * layout_m
particle layout
void initialize(Layout_t &layout)
void unpack(size_type nrecvs)
void destroy(const Kokkos::View< bool *, Properties... > &invalid, const size_type destroyNum)
size_type packedSize(const size_type count) const
static constexpr bool EnableIDs
void recvFromRank(int rank, int tag, size_type nRecvs)
void createWithID(index_type id)
typename PLayout::index_type index_type
index_type numNodes_m
number of MPI ranks
hash_container_type keepIndex_m
void sendToRank(int rank, int tag, std::vector< MPI_Request > &requests, const HashType &hash)
size_type totalNum_m
total number of particles (across all processes)
hash_container_type deleteIndex_m
buffers for particle partitioning
particle_position_type R
view of particle positions
particle_index_type ID
view of particle IDs
void deserialize(Archive &ar, size_type nrecvs)