9#include <Kokkos_Core.hpp>
30template<
typename ValueType>
33 size_t size =
static_cast<size_t>(ssize);
52template<
template<
typename>
class ContType,
typename ValueType,
typename Inner>
53void map(ContType<ValueType>& cont,
const Inner inner, std::pair<localIdx, localIdx> range = {0, 0})
55 auto [start, end] = range;
60 auto contView = cont.view();
64 KOKKOS_LAMBDA(
const localIdx i) { contView[i] = inner(i); },
77template<
template<
typename>
class ContType,
typename ValueType>
79 ContType<ValueType>& cont,
80 const std::type_identity_t<ValueType> value,
81 std::pair<localIdx, localIdx> range = {0, 0}
84 auto [start, end] = range;
85 NF_DEBUG_ASSERT(start <= end,
"Range must be ordered in ascending fashion");
90 auto viewA = cont.view();
92 cont.exec(), {start, end}, KOKKOS_LAMBDA(
const localIdx i) { viewA[i] = value; },
"fill"
104template<
template<
typename>
class ContType,
typename ValueType>
106 ContType<ValueType>& cont,
107 const View<
const std::type_identity_t<ValueType>> view,
108 std::pair<localIdx, localIdx> range = {0, 0}
111 auto [start, end] = range;
116 auto contView = cont.view();
120 KOKKOS_LAMBDA(
const localIdx i) { contView[i] = view[i]; },
125template<
typename... Args>
128 return std::make_tuple(cont.copyToHost()...);
131template<
template<
typename>
class ContType,
typename ValueType>
132bool equal(ContType<ValueType>& cont, ValueType value)
134 auto hostCont = cont.copyToHost();
135 auto hostView = hostCont.view();
136 for (
localIdx i = 0; i < hostView.size(); i++)
138 if (hostView[i] != value)
146template<
template<
typename>
class ContType,
typename ValueType>
147bool equal(
const ContType<ValueType>& cont1,
const ContType<ValueType>& cont2)
149 auto [hostCont1, hostCont2] =
copyToHosts(cont1, cont2);
150 auto [hostView1, hostView2] =
views(hostCont1, hostCont2);
152 if (hostView1.size() != hostView2.size())
157 for (
localIdx i = 0; i < hostView1.size(); i++)
159 if (hostView1[i] != hostView2[i])
168template<
template<
typename>
class ContType,
typename ValueType>
171 auto hostView = cont.copyToHost().view();
173 if (hostView.size() != view2.
size())
178 for (
localIdx i = 0; i < hostView.size(); i++)
180 if (hostView[i] != view2[i])
KOKKOS_INLINE_FUNCTION localIdx size() const
#define NF_DEBUG_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false (only in debu...
auto deepCopyVisitor(localIdx ssize, const ValueType *srcPtr, ValueType *dstPtr)
A helper function to simplify the common pattern of copying between and to executor.
void map(ContType< ValueType > &cont, const Inner inner, std::pair< localIdx, localIdx > range={0, 0})
Map a field using a specific executor.
auto copyToHosts(Args &... cont)
bool equal(ContType< ValueType > &cont, ValueType value)
void setContainer(ContType< ValueType > &cont, const View< const std::type_identity_t< ValueType > > view, std::pair< localIdx, localIdx > range={0, 0})
Set the container with a view of values using a specific executor.
void parallelFor(const ExecutorType &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name)
void fill(ContType< ValueType > &cont, const std::type_identity_t< ValueType > value, std::pair< localIdx, localIdx > range={0, 0})
Fill the field with a vector value using a specific executor.
auto views(Types &... args)
Unpacks all views of the passed classes.