7#include <Kokkos_Core.hpp>
28template<
typename ValueType>
31 size_t size =
static_cast<size_t>(ssize);
50template<
template<
typename>
class ContType,
typename ValueType,
typename Inner>
51void map(ContType<ValueType>& cont,
const Inner inner, std::pair<localIdx, localIdx> range = {0, 0})
53 auto [start, end] = range;
58 auto contView = cont.view();
60 cont.exec(), {start, end}, KOKKOS_LAMBDA(
const localIdx i) { contView[i] = inner(i); }
72template<
template<
typename>
class ContType,
typename ValueType>
74 ContType<ValueType>& cont,
75 const std::type_identity_t<ValueType> value,
76 std::pair<localIdx, localIdx> range = {0, 0}
79 auto [start, end] = range;
80 NF_DEBUG_ASSERT(start <= end,
"Range must be ordered in ascending fashion");
85 auto viewA = cont.view();
87 cont.exec(), {start, end}, KOKKOS_LAMBDA(
const localIdx i) { viewA[i] = value; }
99template<
template<
typename>
class ContType,
typename ValueType>
101 ContType<ValueType>& cont,
102 const View<
const std::type_identity_t<ValueType>> view,
103 std::pair<localIdx, localIdx> range = {0, 0}
106 auto [start, end] = range;
111 auto contView = cont.view();
113 cont.exec(), {start, end}, KOKKOS_LAMBDA(
const localIdx i) { contView[i] = view[i]; }
117template<
typename... Args>
120 return std::make_tuple(cont.copyToHost()...);
123template<
template<
typename>
class ContType,
typename ValueType>
124bool equal(ContType<ValueType>& cont, ValueType value)
126 auto hostCont = cont.copyToHost();
127 auto hostView = hostCont.view();
128 for (
localIdx i = 0; i < hostView.size(); i++)
130 if (hostView[i] != value)
138template<
template<
typename>
class ContType,
typename ValueType>
139bool equal(
const ContType<ValueType>& cont1,
const ContType<ValueType>& cont2)
141 auto [hostCont1, hostCont2] =
copyToHosts(cont1, cont2);
142 auto [hostView1, hostView2] =
views(hostCont1, hostCont2);
144 if (hostView1.size() != hostView2.size())
149 for (
localIdx i = 0; i < hostView1.size(); i++)
151 if (hostView1[i] != hostView2[i])
160template<
template<
typename>
class ContType,
typename ValueType>
163 auto hostView = cont.copyToHost().view();
165 if (hostView.size() != view2.
size())
170 for (
localIdx i = 0; i < hostView.size(); i++)
172 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 parallelFor(const Executor &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name="parallelFor")
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 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.