7#include <Kokkos_ReductionIdentity.hpp>
18 template <
typename T,
unsigned Dim>
36 template <
typename Scalar,
class Space = Kokkos::HostSpace>
37 struct Max : Kokkos::Max<Scalar, Space> {
38 using Super = Kokkos::Max<Scalar, Space>;
45 dest = max(dest, src);
48 template <
typename Scalar,
class Space = Kokkos::HostSpace>
49 struct Min : Kokkos::Min<Scalar, Space> {
50 using Super = Kokkos::Min<Scalar, Space>;
57 dest = min(dest, src);
60 template <
typename Scalar,
class Space = Kokkos::HostSpace>
61 struct Sum : Kokkos::Sum<Scalar, Space> {
62 using Super = Kokkos::Sum<Scalar, Space>;
70 template <
typename Scalar,
class Space = Kokkos::HostSpace>
71 struct Prod : Kokkos::Prod<Scalar, Space> {
72 using Super = Kokkos::Prod<Scalar, Space>;
84 template <
typename T,
unsigned Dim,
class... ViewArgs>
88 template <
typename T,
unsigned Dim,
class... ViewArgs>
93 template <
typename T,
unsigned Dim,
class... ViewArgs>
96 Kokkos::deep_copy(copy.dview_m,
dview_m);
100 template <
typename T,
unsigned Dim,
class... ViewArgs>
108 template <
typename T,
unsigned Dim,
class... ViewArgs>
118 template <
typename T,
unsigned Dim,
class... ViewArgs>
126 template <
typename T,
unsigned Dim,
class... ViewArgs>
130 auto resize = [&]<
size_t... Idx>(
const std::index_sequence<Idx...>&) {
133 resize(std::make_index_sequence<Dim>{});
136 template <
typename T,
unsigned Dim,
class... ViewArgs>
137 template <
typename... Args>
139 Kokkos::resize(
dview_m, args...);
142 template <
typename T,
unsigned Dim,
class... ViewArgs>
153 template <
typename T,
unsigned Dim,
class... ViewArgs>
164 template <
typename T,
unsigned Dim,
class... ViewArgs>
171 template <
typename T,
unsigned Dim,
class... ViewArgs>
176 KOKKOS_CLASS_LAMBDA(
const index_array_type& args) {
apply(
dview_m, args) = x; });
180 template <
typename T,
unsigned Dim,
class... ViewArgs>
181 template <
typename E,
size_t N>
185 capture_type expr_ =
reinterpret_cast<const capture_type&
>(expr);
189 KOKKOS_CLASS_LAMBDA(
const index_array_type& args) {
195 template <
typename T,
unsigned Dim,
class... ViewArgs>
201 template <
typename T,
unsigned Dim,
class... ViewArgs>
206#define DefineReduction(fun, name, op, MPI_Op) \
207 template <typename T, unsigned Dim, class... ViewArgs> \
208 T BareField<T, Dim, ViewArgs...>::name(int nghost) const { \
209 PAssert_LE(nghost, nghost_m); \
210 T temp = Kokkos::reduction_identity<T>::name(); \
211 using index_array_type = typename RangePolicy<Dim, execution_space>::index_array_type; \
212 ippl::parallel_reduce( \
213 "fun", getRangePolicy(dview_m, nghost_m - nghost), \
214 KOKKOS_CLASS_LAMBDA(const index_array_type& args, T& valL) { \
215 T myVal = apply(dview_m, args); \
218 KokkosCorrection::fun<T>(temp)); \
219 T globaltemp = 0.0; \
220 layout_m->comm.allreduce(temp, globaltemp, 1, MPI_Op<T>()); \
ippl::Vector< T, Dim > Vector
#define DefineReduction(fun, name, op, MPI_Op)
DefineReduction(Sum, sum, valL+=myVal, std::plus) DefineReduction(Max
KOKKOS_INLINE_FUNCTION constexpr decltype(auto) apply(const View &view, const Coords &coords)
RangePolicy< View::rank, typenameView::execution_space, PolicyArgs... >::policy_type getRangePolicy(const View &view, int shift=0)
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)
void write(const typename ViewType< T, Dim, Properties... >::view_type &view, std::ostream &out=std::cout)
BareField & operator=(T x)
Layout_t * layout_m
How the arrays are laid out.
FieldLayout< Dim > Layout_t
void initialize(Layout_t &l, int nghost=1)
void write(std::ostream &out=std::cout) const
BareField deepCopy() const
void updateLayout(Layout_t &, int nghost=1)
Domain_t owned_m
Domain of the data.
view_type dview_m
Actual field data.
void accumulateHalo_noghost(int nghost=1)
int nghost_m
Number of ghost layers on each field boundary.
void resize(Args... args)
static KOKKOS_FORCEINLINE_FUNCTION ippl::Vector< T, Dim > min()
static KOKKOS_FORCEINLINE_FUNCTION ippl::Vector< T, Dim > max()
static KOKKOS_FORCEINLINE_FUNCTION ippl::Vector< T, Dim > prod()
static KOKKOS_FORCEINLINE_FUNCTION ippl::Vector< T, Dim > sum()
KOKKOS_INLINE_FUNCTION Max(value_type &vref)
typename Super::value_type value_type
KOKKOS_INLINE_FUNCTION void join(value_type &dest, const value_type &src) const
Kokkos::Max< Scalar, Space > Super
KOKKOS_INLINE_FUNCTION Min(value_type &vref)
KOKKOS_INLINE_FUNCTION void join(value_type &dest, const value_type &src) const
Kokkos::Min< Scalar, Space > Super
typename Super::value_type value_type
Kokkos::Sum< Scalar, Space > Super
KOKKOS_INLINE_FUNCTION void join(value_type &dest, const value_type &src) const
typename Super::value_type value_type
KOKKOS_INLINE_FUNCTION Sum(value_type &vref)
typename Super::value_type value_type
KOKKOS_INLINE_FUNCTION Prod(value_type &vref)
KOKKOS_INLINE_FUNCTION void join(value_type &dest, const value_type &src) const
Kokkos::Prod< Scalar, Space > Super
std::ostream & getDestination()
::ippl::Vector< index_type, Dim > index_array_type