7#include <Kokkos_ReductionIdentity.hpp>
18 template <
typename T,
unsigned Dim>
36 template <
typename Scalar,
class Space = Kokkos::HostSpace>
38 using Super = Kokkos::Max<Scalar, Space>;
45 dest =
max(dest, src);
48 template <
typename Scalar,
class Space = Kokkos::HostSpace>
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>
91 , layout_m(nullptr) {}
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>
128 owned_m = layout_m->getLocalNDIndex();
130 auto resize = [&]<
size_t... Idx>(
const std::index_sequence<Idx...>&) {
131 this->resize((owned_m[Idx].length() + 2 * nghost_m)...);
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>
144 if (layout_m->comm.size() > 1) {
147 if (layout_m->isAllPeriodic_m) {
149 halo_m.template applyPeriodicSerialDim<Op>(dview_m, layout_m, nghost_m);
153 template <
typename T,
unsigned Dim,
class... ViewArgs>
155 if (layout_m->comm.size() > 1) {
158 if (layout_m->isAllPeriodic_m) {
160 halo_m.template applyPeriodicSerialDim<Op>(dview_m, layout_m, nghost_m);
164 template <
typename T,
unsigned Dim,
class... ViewArgs>
166 if (layout_m->comm.size() > 1) {
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);
188 "BareField::operator=(const Expression&)",
getRangePolicy(dview_m, nghost_m),
189 KOKKOS_CLASS_LAMBDA(
const index_array_type& args) {
195 template <
typename T,
unsigned Dim,
class... ViewArgs>
198 detail::write<T, Dim>(dview_m, out);
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>()); \
#define DefineReduction(fun, name, op, MPI_Op)
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.
void initialize(int &argc, char *argv[], MPI_Comm comm)
KOKKOS_INLINE_FUNCTION constexpr decltype(auto) apply(const View &view, const Coords &coords)
KOKKOS_INLINE_FUNCTION Vector< T, Dim > max(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
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 deepCopy() const
void accumulateHalo_noghost(int nghost=1)
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()