99 BareField<T, Dim, ViewArgs...> copy(*layout_m, nghost_m);
100 Kokkos::deep_copy(copy.dview_m, dview_m);
104 template <
typename T,
unsigned Dim,
class... ViewArgs>
112 template <
typename T,
unsigned Dim,
class... ViewArgs>
122 template <
typename T,
unsigned Dim,
class... ViewArgs>
130 template <
typename T,
unsigned Dim,
class... ViewArgs>
131 void BareField<T, Dim, ViewArgs...>::setup() {
132 owned_m = layout_m->getLocalNDIndex();
134 auto resize = [&]<
size_t... Idx>(
const std::index_sequence<Idx...>&) {
135 this->resize((owned_m[Idx].length() + 2 * nghost_m)...);
137 resize(std::make_index_sequence<Dim>{});
140 template <
typename T,
unsigned Dim,
class... ViewArgs>
141 template <
typename... Args>
143 Kokkos::resize(dview_m, args...);
146 template <
typename T,
unsigned Dim,
class... ViewArgs>
148 if (layout_m->comm.size() > 1) {
149 halo_m.fillHalo(dview_m, layout_m);
151 if (layout_m->isAllPeriodic_m) {
152 using Op =
typename detail::HaloCells<T, Dim, ViewArgs...>::assign;
153 halo_m.template applyPeriodicSerialDim<Op>(dview_m, layout_m, nghost_m);
157 template <
typename T,
unsigned Dim,
class... ViewArgs>
158 void BareField<T, Dim, ViewArgs...>::accumulateHalo() {
159 if (layout_m->comm.size() > 1) {
160 halo_m.accumulateHalo(dview_m, layout_m);
162 if (layout_m->isAllPeriodic_m) {
163 using Op =
typename detail::HaloCells<T, Dim, ViewArgs...>::rhs_plus_assign;
164 halo_m.template applyPeriodicSerialDim<Op>(dview_m, layout_m, nghost_m);
168 template <
typename T,
unsigned Dim,
class... ViewArgs>
169 void BareField<T, Dim, ViewArgs...>::accumulateHalo_noghost(
int nghost) {
170 if (layout_m->comm.size() > 1) {
171 halo_m.accumulateHalo_noghost(dview_m, layout_m, nghost);
175 template <
typename T,
unsigned Dim,
class... ViewArgs>
176 BareField<T, Dim, ViewArgs...>& BareField<T, Dim, ViewArgs...>::operator=(T x) {
177 Kokkos::deep_copy(dview_m, x);
181 template <
typename T,
unsigned Dim,
class... ViewArgs>
182 template <
typename E,
size_t N>
183 BareField<T, Dim, ViewArgs...>& BareField<T, Dim, ViewArgs...>::operator=(
184 const detail::Expression<E, N>& expr) {
185 using capture_type = detail::CapturedExpression<E, N>;
186 capture_type expr_ =
reinterpret_cast<const capture_type&
>(expr);
187 using index_array_type =
typename RangePolicy<Dim, execution_space>::index_array_type;
189 "BareField::operator=(const Expression&)",
getRangePolicy(dview_m, nghost_m),
190 KOKKOS_CLASS_LAMBDA(
const index_array_type& args) {
196 template <
typename T,
unsigned Dim,
class... ViewArgs>
199 detail::write<T, Dim, ViewArgs...>(dview_m, out);
202 template <
typename T,
unsigned Dim,
class... ViewArgs>
204 write(inf.getDestination());
207 template <
typename T,
unsigned Dim,
class... ViewArgs>
210 detail::write_as_list<T, Dim, ViewArgs...>(dview_m, out);
213 template <
typename T,
unsigned Dim,
class... ViewArgs>
215 write_as_list(inf.getDestination());
218#define DefineReduction(fun, name, op, MPI_Op) \
219 template <typename T, unsigned Dim, class... ViewArgs> \
220 T BareField<T, Dim, ViewArgs...>::name(int nghost) const { \
221 PAssert_LE(nghost, nghost_m); \
222 T temp = Kokkos::reduction_identity<T>::name(); \
223 using index_array_type = typename RangePolicy<Dim, execution_space>::index_array_type; \
224 ippl::parallel_reduce( \
225 "fun", getRangePolicy(dview_m, nghost_m - nghost), \
226 KOKKOS_CLASS_LAMBDA(const index_array_type& args, T& valL) { \
227 T myVal = apply(dview_m, args); \
230 KokkosCorrection::fun<T>(temp)); \
231 T globaltemp = 0.0; \
232 layout_m->comm.allreduce(temp, globaltemp, 1, MPI_Op<T>()); \
236 DefineReduction(Sum, sum, valL += myVal, std::plus)
237 DefineReduction(Max, max,
using Kokkos::max; valL = max(valL, myVal), std::greater)
238 DefineReduction(Min, min,
using Kokkos::min; valL = min(valL, myVal), std::less)
239 DefineReduction(Prod, prod, valL *= myVal, std::multiplies)