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) {
43 dview_m(deleteIndex(i)) = dview_m(keepIndex(i));
47 template <
typename T,
class... Properties>
49 auto size = hash.extent(0);
50 if (buf_m.extent(0) < size) {
51 int overalloc =
Comm->getDefaultOverallocation();
52 Kokkos::realloc(buf_m, size * overalloc);
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>
64 auto size = dview_m.extent(0);
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;
123 const vector_type& dx = mesh.getMeshSpacing();
124 const vector_type& origin = mesh.getOrigin();
125 const vector_type invdx = 1.0 / dx;
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;
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;
188 const vector_type& origin = mesh.getOrigin();
189 const vector_type invdx = 1.0 / dx;
195 using policy_type = Kokkos::RangePolicy<execution_space>;
197 "ParticleAttrib::gather", policy_type(0, *(this->localNum_mp)),
198 KOKKOS_CLASS_LAMBDA(
const size_t idx) {
200 vector_type l = (pp(idx) - origin) * invdx + 0.5;
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>;
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();
244 auto view = this->getView();
245 const auto size = this->getParticleCount();
247 using policy_type = Kokkos::RangePolicy<execution_space>;
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,
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::Field< T, Dim, Mesh_t< Dim >, Centering_t< Dim >, ViewArgs... > Field
ippl::detail::size_type size_type
#define DefineParticleReduction(fun, name, op, MPI_Op)
Inform & endl(Inform &inf)
double Min(double a, double b)
static const TFunction2< double, double > plus
double Max(double a, double b)
static const TFunction2< bool, double > greater
static const TFunction2< bool, double > less
Implementations for FFT constructor/destructor and transforms.
KOKKOS_INLINE_FUNCTION Vector< T, Dim > max(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
void gather(Attrib1 &attrib, Field &f, const Attrib2 &pp, const bool addToAttribute=false)
Non-class interface for gathering field data into a particle attribute.
KOKKOS_INLINE_FUNCTION Vector< T, Dim > min(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
void parallel_for(const std::string &name, const ExecPolicy &policy, const FunctorType &functor)
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.
typename detail::ViewType< int, 1, MemorySpace >::view_type hash_type
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
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
void unpack(size_type) override
void internalCopy(const hash_type &indices) override
Copy and create values of given indices.
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
Scatter particle attribute data onto a field.
typename detail::ViewType< index_type, 1, Properties... >::view_type view_type
void gather(Field &f, const ParticleAttrib< Vector< P2, Field::dim >, Properties... > &pp, const bool addToAttribute=false)
Gather field data into the particle attribute.
typename Base::hash_type hash_type
void pack(const hash_type &) override
void applyPermutation(const hash_type &permutation) override
Sort the attribute according to a permutation.
ParticleAttrib< T, Properties... > & operator=(T x)
Timing::TimerRef TimerRef
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)