54 template <
class PLayout,
typename... IP>
59 , nextID_m(
Comm->rank())
60 , numNodes_m(
Comm->size()) {
66 R.set_name(
"position");
69 template <
class PLayout,
typename... IP>
75 template <
class PLayout,
typename... IP>
76 template <
typename MemorySpace>
78 attributes_m.template get<MemorySpace>().push_back(&pa);
82 template <
class PLayout,
typename... IP>
90 template <
class PLayout,
typename... IP>
96 attribute->create(nLocal);
99 if constexpr (EnableIDs) {
102 Kokkos::RangePolicy<size_type, typename particle_index_type::execution_space>;
103 auto pIDs = ID.getView();
104 auto nextID = this->nextID_m;
105 auto numNodes = this->numNodes_m;
107 "ParticleBase<...>::create(size_t)", policy_type(localNum_m, nLocal),
108 KOKKOS_LAMBDA(
const std::int64_t i) { pIDs(i) = nextID + numNodes * i; });
110 nextID_m += numNodes_m * nLocal;
114 localNum_m += nLocal;
117 Comm->allreduce(localNum_m, totalNum_m, 1, std::plus<size_type>());
120 template <
class PLayout,
typename... IP>
133 nextID_m = tmpNextID;
134 numNodes_m =
Comm->size();
137 template <
class PLayout,
typename... IP>
144 const size_t rank =
Comm->rank();
154 template <
class PLayout,
typename... IP>
155 template <
typename... Properties>
158 this->internalDestroy(invalid, destroyNum);
160 Comm->allreduce(localNum_m, totalNum_m, 1, std::plus<size_type>());
163 template <
class PLayout,
typename... IP>
164 template <
typename... Properties>
166 const Kokkos::View<bool*, Properties...>& invalid,
const size_type destroyNum) {
167 PAssert(destroyNum <= localNum_m);
170 if (destroyNum == 0) {
177 if (destroyNum == localNum_m) {
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>;
186 auto& locDeleteIndex = deleteIndex_m.get<memory_space>();
187 auto& locKeepIndex = keepIndex_m.get<memory_space>();
191 if (attributes_m.template get<memory_space>().size() > 0) {
192 int overalloc = Comm->getDefaultOverallocation();
193 auto& del = deleteIndex_m.get<memory_space>();
194 auto& keep = keepIndex_m.get<memory_space>();
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;
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>() {
250 return attributes_m.template get<MemorySpace>().size() > 0;
252 deleteIndex_m.copyToOtherSpaces<memory_space>(filter);
253 keepIndex_m.copyToOtherSpaces<memory_space>(filter);
260 using att_memory_space =
typename Attribute::memory_space;
261 auto& del = deleteIndex_m.get<att_memory_space>();
262 auto& keep = keepIndex_m.get<att_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);
276 return attributes_m.template get<MemorySpace>().size() > 0;
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>
295 size_type bufSize = packedSize<MemorySpace>(nRecvs);
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>
339 auto& att = attributes_m.template get<MemorySpace>();
340 for (
unsigned j = 0; j < att.size(); j++) {
341 att[j]->pack(hash.template get<MemorySpace>());
346 template <
class PLayout,
typename... IP>
349 auto& att = attributes_m.template get<MemorySpace>();
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)
Implementations for FFT constructor/destructor and transforms.
void parallel_for(const std::string &name, const ExecPolicy &policy, const FunctorType &functor)
void parallel_reduce(const std::string &name, const ExecPolicy &policy, const FunctorType &functor, ReducerArgument &&... reducer)
std::unique_ptr< mpi::Communicator > Comm
void runForAllSpaces(Functor &&f)
A representation of an Object attribute.
void set_name(const std::string &name_) override
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
void internalDestroy(const Kokkos::View< bool *, Properties... > &invalid, const size_type destroyNum)
detail::size_type size_type
void globalCreate(size_type nTotal)
void initialize(Layout_t &layout)
void destroy(const Kokkos::View< bool *, Properties... > &invalid, const size_type destroyNum)
static constexpr bool EnableIDs
void createWithID(index_type id)
typename PLayout::index_type index_type
particle_position_type R
view of particle positions
particle_index_type ID
view of particle IDs