24 template <
typename T,
class... Properties>
26 size_type required = *(this->localNum_mp) + n;
27 if (this->
size() < required) {
28 int overalloc =
Comm->getDefaultOverallocation();
29 this->
realloc(required * overalloc);
33 template <
typename T,
class... Properties>
39 using policy_type = Kokkos::RangePolicy<execution_space>;
41 "ParticleAttrib::destroy()", policy_type(0, invalidCount),
42 KOKKOS_CLASS_LAMBDA(
const size_t i) {
47 template <
typename T,
class... Properties>
49 auto size = hash.extent(0);
51 int overalloc =
Comm->getDefaultOverallocation();
55 using policy_type = Kokkos::RangePolicy<execution_space>;
57 "ParticleAttrib::pack()", policy_type(0, size),
58 KOKKOS_CLASS_LAMBDA(
const size_t i) { buf_m(i) = dview_m(hash(i)); });
62 template <
typename T,
class... Properties>
66 if (
size < required) {
67 int overalloc =
Comm->getDefaultOverallocation();
68 this->
resize(required * overalloc);
72 using policy_type = Kokkos::RangePolicy<execution_space>;
74 "ParticleAttrib::unpack()", policy_type(0, nrecvs),
75 KOKKOS_CLASS_LAMBDA(
const size_t i) { dview_m(count + i) = buf_m(i); });
79 template <
typename T,
class... Properties>
82 using policy_type = Kokkos::RangePolicy<execution_space>;
84 "ParticleAttrib::operator=()", policy_type(0, *(this->localNum_mp)),
85 KOKKOS_CLASS_LAMBDA(
const size_t i) {
dview_m(i) = x; });
89 template <
typename T,
class... Properties>
90 template <
typename E,
size_t N>
95 capture_type expr_ =
reinterpret_cast<const capture_type&
>(expr);
97 using policy_type = Kokkos::RangePolicy<execution_space>;
99 "ParticleAttrib::operator=()", policy_type(0, *(this->localNum_mp)),
100 KOKKOS_CLASS_LAMBDA(
const size_t i) {
dview_m(i) = expr_(i); });
104 template <
typename T,
class... Properties>
105 template <
typename Field,
class PT,
typename policy_type>
108 policy_type iteration_policy,
hash_type hash_array)
const {
118 const mesh_type& mesh = f.
get_mesh();
120 using vector_type =
typename mesh_type::vector_type;
132 const bool useHashView = hash_array.extent(0) > 0;
133 if (useHashView && (iteration_policy.end() > hash_array.extent(0))) {
135 m <<
"Hash array was passed to scatter, but size does not match iteration policy." <<
endl;
138 Kokkos::parallel_for(
139 "ParticleAttrib::scatter", iteration_policy,
140 KOKKOS_CLASS_LAMBDA(
const size_t idx) {
142 size_t mapped_idx = useHashView ? hash_array(idx) : idx;
145 vector_type l = (pp(mapped_idx) - origin) * invdx + 0.5;
153 const value_type& val = dview_m(mapped_idx);
165 template <
typename T,
class... Properties>
166 template <
typename Field,
typename P2>
169 const bool addToAttribute) {
183 const mesh_type& mesh = f.
get_mesh();
185 using vector_type =
typename mesh_type::vector_type;
195 using policy_type = Kokkos::RangePolicy<execution_space>;
196 Kokkos::parallel_for(
197 "ParticleAttrib::gather", policy_type(0, *(this->localNum_mp)),
198 KOKKOS_CLASS_LAMBDA(
const size_t idx) {
209 view, wlo, whi, args);
210 if (addToAttribute) {
211 dview_m(idx) += gathered;
213 dview_m(idx) = gathered;
219 template <
typename T,
class... Properties>
223 const auto view = this->
getView();
224 const auto size = this->getParticleCount();
228 using policy_type = Kokkos::RangePolicy<execution_space>;
229 Kokkos::parallel_for(
230 "Copy to temp", policy_type(0,
size),
231 KOKKOS_LAMBDA(
const size_type& i) { temp(permutation(i)) = view(i); });
235 Kokkos::deep_copy(Kokkos::subview(view, Kokkos::make_pair<size_type, size_type>(0,
size)), temp);
238 template<
typename T,
class... Properties>
241 auto copySize = indices.size();
245 const auto size = this->getParticleCount();
247 using policy_type = Kokkos::RangePolicy<execution_space>;
248 Kokkos::parallel_for(
249 "Copy to temp", policy_type(0, copySize),
251 view(
size + i) = view(i);
278 template <
typename Attrib1,
typename Field,
typename Attrib2,
279 typename policy_type = Kokkos::RangePolicy<typename Field::execution_space>>
280 inline void scatter(
const Attrib1& attrib,
Field& f,
const Attrib2& pp) {
281 attrib.scatter(f, pp, policy_type(0, attrib.getParticleCount()));
302 template <
typename Attrib1,
typename Field,
typename Attrib2,
303 typename policy_type = Kokkos::RangePolicy<typename Field::execution_space>>
304 inline void scatter(
const Attrib1& attrib,
Field& f,
const Attrib2& pp,
305 policy_type iteration_policy,
typename Attrib1::hash_type hash_array = {}) {
306 attrib.scatter(f, pp, iteration_policy, hash_array);
326 template <
typename Attrib1,
typename Field,
typename Attrib2>
328 const bool addToAttribute =
false) {
329 attrib.gather(f, pp, addToAttribute);
332#define DefineParticleReduction(fun, name, op, MPI_Op) \
333 template <typename T, class... Properties> \
334 T ParticleAttrib<T, Properties...>::name() { \
336 using policy_type = Kokkos::RangePolicy<execution_space>; \
337 Kokkos::parallel_reduce( \
338 "fun", policy_type(0, *(this->localNum_mp)), \
339 KOKKOS_CLASS_LAMBDA(const size_t i, T& valL) { \
340 T myVal = dview_m(i); \
343 Kokkos::fun<T>(temp)); \
344 T globaltemp = 0.0; \
345 Comm->allreduce(temp, globaltemp, 1, MPI_Op<T>()); \
ippl::detail::size_type size_type
ippl::Field< T, Dim, Mesh_t< Dim >, Centering_t< Dim >, ViewArgs... > Field
#define DefineParticleReduction(fun, name, op, MPI_Op)
Inform & endl(Inform &inf)
void gather(Attrib1 &attrib, Field &f, const Attrib2 &pp, const bool addToAttribute=false)
Non-class interface for gathering field data into a particle attribute.
DefineParticleReduction(Sum, sum, valL+=myVal, std::plus) DefineParticleReduction(Max
KOKKOS_INLINE_FUNCTION Vector< T, Dim > min(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
std::unique_ptr< mpi::Communicator > Comm
void scatter(const Attrib1 &attrib, Field &f, const Attrib2 &pp)
Non-class interface for scattering particle attribute data onto a field.
KOKKOS_INLINE_FUNCTION constexpr View::value_type gatherFromField(const std::index_sequence< GatherPoint... > &, const View &view, const Vector< T, View::rank > &wlo, const Vector< T, View::rank > &whi, const Vector< IndexType, View::rank > &args)
KOKKOS_INLINE_FUNCTION constexpr void scatterToField(const std::index_sequence< ScatterPoint... > &, const View &view, const Vector< T, View::rank > &wlo, const Vector< T, View::rank > &whi, const Vector< IndexType, View::rank > &args, T val=1)
Layout_t & getLayout() const
static constexpr unsigned dim
KOKKOS_INLINE_FUNCTION Mesh_t & get_mesh() const
typename BareField_t::view_type view_type
const NDIndex_t & getLocalNDIndex() const
KOKKOS_INLINE_FUNCTION Vector< int, Dim > first() const
KOKKOS_INLINE_FUNCTION vector_type getOrigin() const
virtual KOKKOS_INLINE_FUNCTION const vector_type & getMeshSpacing() const =0
void destroy(const hash_type &deleteIndex, const hash_type &keepIndex, size_type invalidCount) override
void create(size_type) override
ippl::Vector< double, 2 > value_type
void unpack(size_type) override
void internalCopy(const hash_type &indices) override
detail::size_type size_type
void scatter(Field &f, const ParticleAttrib< Vector< P2, Field::dim >, Properties... > &pp, policy_type iteration_policy, hash_type hash_array={}) const
typename detail::ViewType< ippl::Vector< double, 2 >, 1, Properties... >::view_type view_type
void gather(Field &f, const ParticleAttrib< Vector< P2, Field::dim >, Properties... > &pp, const bool addToAttribute=false)
typename Base::hash_type hash_type
void realloc(size_type n)
void pack(const hash_type &) override
void applyPermutation(const hash_type &permutation) override
ParticleAttrib< T, Properties... > & operator=(T x)
size_type size() const override
Timing::TimerRef TimerRef
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)