23 template <
unsigned int inner>
35 #ifdef MOOSE_KOKKOS_SCOPE 45 #ifdef MOOSE_KOKKOS_SCOPE 52 template <
typename T,
unsigned int inner>
83 KOKKOS_ASSERT(i <
_dim.stride[inner - 1]);
99 #define usingKokkosJaggedArrayInnerDataBaseMembers(T, inner) \ 101 using JaggedArrayInnerDataBase<T, inner>::_data; \ 102 using JaggedArrayInnerDataBase<T, inner>::_dim 107 template <
typename T,
unsigned int inner>
111 template <
typename T>
114 usingKokkosJaggedArrayInnerDataBaseMembers(T, 1);
133 KOKKOS_ASSERT(i0 < _dim[0]);
139 template <
typename T>
142 usingKokkosJaggedArrayInnerDataBaseMembers(T, 2);
162 KOKKOS_ASSERT(i0 < _dim[0]);
163 KOKKOS_ASSERT(i1 < _dim[1]);
165 return _data[i0 + _dim.stride[0] * i1];
169 template <
typename T>
172 usingKokkosJaggedArrayInnerDataBaseMembers(T, 3);
193 KOKKOS_ASSERT(i0 < _dim[0]);
194 KOKKOS_ASSERT(i1 < _dim[1]);
195 KOKKOS_ASSERT(i2 < _dim[2]);
197 return _data[i0 + _dim.stride[0] * i1 + _dim.stride[1] * i2];
220 template <
typename T,
unsigned int inner,
unsigned int outer>
223 #ifdef MOOSE_KOKKOS_SCOPE 229 void create(
const std::vector<dof_id_type> &
n);
235 void reserve(
const std::array<dof_id_type, outer> & index,
236 const std::array<dof_id_type, inner> & dimension);
246 mooseAssert(
_finalized,
"KokkosJaggedArray not finalized.");
248 _data.copyToDevice();
255 mooseAssert(
_finalized,
"KokkosJaggedArray not finalized.");
319 #define usingKokkosJaggedArrayBaseMembers(T, inner, outer) \ 321 using JaggedArrayBase<T, inner, outer>::_data; \ 322 using JaggedArrayBase<T, inner, outer>::_dims; \ 323 using JaggedArrayBase<T, inner, outer>::_offsets 325 #ifdef MOOSE_KOKKOS_SCOPE 326 template <
typename T,
unsigned int inner,
unsigned int outer>
337 template <
typename T,
unsigned int inner,
unsigned int outer>
340 const std::array<dof_id_type, inner> & dimension)
342 mooseAssert(!_finalized,
"KokkosJaggedArray already finalized.");
347 for (
unsigned int o = 0; o < outer; ++o)
349 idx += index[o] * stride;
350 stride *= _offsets.n(o);
355 for (
unsigned int i = 0; i < inner; ++i)
357 stride *= dimension[i];
359 _dims[
idx].dim[i] = dimension[i];
360 _dims[
idx].stride[i] = stride;
364 template <
typename T,
unsigned int inner,
unsigned int outer>
368 mooseAssert(!_finalized,
"KokkosJaggedArray already finalized.");
376 for (
unsigned int i = 0; i < inner; ++i)
377 stride *= _dims[o][i];
379 _offsets[o] = stride;
382 std::exclusive_scan(_offsets.begin(), _offsets.end(), _offsets.begin(), 0);
384 _dims.copyToDevice();
385 _offsets.copyToDevice();
386 _data.create(_offsets.last() + stride);
395 template <
typename T,
unsigned int inner,
unsigned int outer>
399 template <
typename T,
unsigned int inner>
402 usingKokkosJaggedArrayBaseMembers(T, inner, 1);
410 #ifdef MOOSE_KOKKOS_SCOPE 430 auto data = &_data[_offsets(i0)];
431 const auto &
dim = _dims(i0);
438 template <
typename T,
unsigned int inner>
441 usingKokkosJaggedArrayBaseMembers(T, inner, 2);
449 #ifdef MOOSE_KOKKOS_SCOPE 472 auto data = &_data[_offsets(i0, i1)];
473 const auto &
dim = _dims(i0, i1);
480 template <
typename T,
unsigned int inner>
483 usingKokkosJaggedArrayBaseMembers(T, inner, 3);
491 #ifdef MOOSE_KOKKOS_SCOPE 520 auto data = &_data[_offsets(i0, i1, i2)];
521 const auto &
dim = _dims(i0, i1, i2);
JaggedArray(dof_id_type n0, dof_id_type n1, dof_id_type n2)
Constructor Allocate outer array with given dimensions.
void create(const std::vector< dof_id_type > &n)
Allocate outer array.
The base class for Kokkos jagged arrays.
KOKKOS_FUNCTION dof_id_type size() const
Get the total data array size.
void finalize()
Setup array structure.
JaggedArrayInnerDim< inner > _dim
Inner array dimension information.
KOKKOS_FUNCTION JaggedArrayInnerData(T *data, JaggedArrayInnerDim< 2 > dim)
Constructor.
void create(dof_id_type n0, dof_id_type n1, dof_id_type n2)
Allocate outer array with given dimensions.
void copyToDevice()
Copy data from host to device.
KOKKOS_FUNCTION dof_id_type operator[](unsigned int i) const
Get the size of a dimension.
JaggedArray(dof_id_type n0)
Constructor Allocate outer array with given dimensions.
dof_id_type stride[inner]
Stride of each dimension.
Array< JaggedArrayInnerDim< inner >, outer > _dims
Dimension information of each inner array.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Array< T > _data
Sequential data array.
auto & array()
Get the underlying data array.
void create(dof_id_type n0)
Allocate outer array with given dimensions.
bool _finalized
Whether the array was finalized.
KOKKOS_FUNCTION T & operator[](dof_id_type i) const
Get an array entry.
KOKKOS_FUNCTION auto operator()(dof_id_type i0, dof_id_type i1, dof_id_type i2) const
Get an inner array.
KOKKOS_FUNCTION dof_id_type n() const
Get the total outer array size.
A simple object holding the dimension information of an inner array.
KOKKOS_FUNCTION T & operator()(dof_id_type i0, dof_id_type i1, dof_id_type i2) const
Get an array entry.
void reserve(const std::array< dof_id_type, outer > &index, const std::array< dof_id_type, inner > &dimension)
Reserve inner array for an outer array entry.
KOKKOS_FUNCTION T & operator()(dof_id_type i0, dof_id_type i1) const
Get an array entry.
KOKKOS_FUNCTION dof_id_type n(unsigned int dim) const
Get the size of a dimension of the outer array.
void copyToHost()
Copy data from device to host.
KOKKOS_FUNCTION auto operator()(dof_id_type i0, dof_id_type i1) const
Get an inner array.
KOKKOS_FUNCTION auto operator()(dof_id_type i0) const
Get an inner array.
KOKKOS_FUNCTION JaggedArrayInnerData(T *data, JaggedArrayInnerDim< 3 > dim)
Constructor.
The specialization of the inner array wrapper class for each dimension.
KOKKOS_FUNCTION dof_id_type n(unsigned int dim) const
Get the size of a dimension of the inner array.
T * _data
Pointer to the inner array data.
KOKKOS_FUNCTION bool isFinalized() const
Get whether the array is finalized.
Array< dof_id_type, outer > _offsets
Starting offset of each inner array into the sequential data array.
KOKKOS_FUNCTION T & operator()(dof_id_type i0) const
Get an array entry.
KOKKOS_FUNCTION dof_id_type size() const
Get the total inner array size.
KOKKOS_FUNCTION auto operator[](dof_id_type i) const
Get an inner array.
void create(dof_id_type n0, dof_id_type n1)
Allocate outer array with given dimensions.
JaggedArray(dof_id_type n0, dof_id_type n1)
Constructor Allocate outer array with given dimensions.
The specialization of the Kokkos jagged array class for each dimension.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
dof_id_type dim[inner]
Size of each dimension.
KOKKOS_FUNCTION JaggedArrayInnerDataBase(T *data, JaggedArrayInnerDim< inner > dim)
Constructor.
KOKKOS_FUNCTION JaggedArrayInnerData(T *data, JaggedArrayInnerDim< 1 > dim)
Constructor.
The base class of the inner array wrapper.