10 #ifndef STOKHOS_FLAT_SPARSE_3_TENSOR_KJI_HPP
11 #define STOKHOS_FLAT_SPARSE_3_TENSOR_KJI_HPP
13 #include "Kokkos_Core.hpp"
28 template<
typename ValueType ,
class ExecutionSpace >
33 typedef typename execution_space::size_type
size_type ;
103 KOKKOS_INLINE_FUNCTION
107 KOKKOS_INLINE_FUNCTION
111 KOKKOS_INLINE_FUNCTION
116 KOKKOS_INLINE_FUNCTION
121 KOKKOS_INLINE_FUNCTION
126 KOKKOS_INLINE_FUNCTION
131 KOKKOS_INLINE_FUNCTION
136 KOKKOS_INLINE_FUNCTION
141 KOKKOS_INLINE_FUNCTION
146 KOKKOS_INLINE_FUNCTION
151 KOKKOS_INLINE_FUNCTION
156 KOKKOS_INLINE_FUNCTION
161 KOKKOS_INLINE_FUNCTION
166 KOKKOS_INLINE_FUNCTION
170 template <
typename OrdinalType>
181 std::vector< size_t > j_coord_work( nk , (
size_t) 0 );
183 for (
typename Cijk_type::k_iterator k_it=Cijk.
k_begin();
184 k_it!=Cijk.
k_end(); ++k_it) {
185 OrdinalType k = index(k_it);
186 for (
typename Cijk_type::kj_iterator j_it = Cijk.
j_begin(k_it);
187 j_it != Cijk.
j_end(k_it); ++j_it) {
188 OrdinalType
j = index(j_it);
197 std::vector< size_t > i_coord_work( j_entry_count , (
size_t) 0 );
200 for (
typename Cijk_type::k_iterator k_it=Cijk.
k_begin();
201 k_it!=Cijk.
k_end(); ++k_it) {
202 OrdinalType k = index(k_it);
203 for (
typename Cijk_type::kj_iterator j_it = Cijk.
j_begin(k_it);
204 j_it != Cijk.
j_end(k_it); ++j_it) {
205 OrdinalType
j = index(j_it);
207 for (
typename Cijk_type::kji_iterator i_it = Cijk.
i_begin(j_it);
208 i_it != Cijk.
i_end(j_it); ++i_it) {
209 ++i_coord_work[j_entry];
240 tensor.
m_flops = 3*j_entry_count + 2*i_entry_count;
243 typename coord_array_type::HostMirror
245 typename coord_array_type::HostMirror
247 typename value_array_type::HostMirror
249 typename entry_array_type::HostMirror
251 typename entry_array_type::HostMirror
253 typename entry_array_type::HostMirror
255 typename entry_array_type::HostMirror
260 host_j_row_map(0) = 0;
262 sum += j_coord_work[k];
263 host_j_row_map(k+1) =
sum;
269 host_i_row_map(0) = 0;
271 sum += i_coord_work[
j];
272 host_i_row_map(
j+1) =
sum;
277 j_coord_work[k] = host_j_row_map[k];
280 i_coord_work[
j] = host_i_row_map[
j];
283 for (
typename Cijk_type::k_iterator k_it=Cijk.
k_begin();
284 k_it!=Cijk.
k_end(); ++k_it) {
285 OrdinalType k = index(k_it);
286 for (
typename Cijk_type::kj_iterator j_it = Cijk.
j_begin(k_it);
287 j_it != Cijk.
j_end(k_it); ++j_it) {
288 OrdinalType
j = index(j_it);
290 const size_type jEntry = j_coord_work[k];
292 host_j_coord(jEntry) =
j ;
294 for (
typename Cijk_type::kji_iterator i_it = Cijk.
i_begin(j_it);
295 i_it != Cijk.
i_end(j_it); ++i_it) {
296 OrdinalType i = index(i_it);
297 ValueType c = Stokhos::value(i_it);
298 const size_type iEntry = i_coord_work[jEntry];
299 ++i_coord_work[jEntry];
300 host_value(iEntry) = (j != k) ? c : 0.5*c;
301 host_i_coord(iEntry) = i ;
302 ++host_num_i(jEntry);
322 template<
class Device ,
typename OrdinalType ,
typename ValueType >
323 FlatSparse3Tensor_kji<ValueType, Device>
330 basis, Cijk, params );
333 template <
typename ValueType,
typename Device >
341 template<
typename MatrixValue ,
typename VectorValue >
342 KOKKOS_INLINE_FUNCTION
344 const MatrixValue *
const a ,
345 const VectorValue *
const x ,
346 VectorValue *
const y )
352 const MatrixValue ak = a[k];
353 const VectorValue xk = x[k];
359 for (
size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
361 VectorValue tmp = a[
j] * xk + ak * x[
j];
367 for (
size_type iEntry = iBeg; iEntry < iEnd; ++iEntry) {
369 y[i] += tensor.
value(iEntry) * tmp;
375 KOKKOS_INLINE_FUNCTION
379 KOKKOS_INLINE_FUNCTION
static KOKKOS_INLINE_FUNCTION size_type matrix_size(const tensor_type &tensor)
execution_space::size_type size_type
KOKKOS_INLINE_FUNCTION const size_type & i_coord(const size_type iEntry) const
i coordinate for i entry 'iEntry'
k_iterator k_begin() const
Iterator pointing to first k entry.
static KOKKOS_INLINE_FUNCTION size_type vector_size(const tensor_type &tensor)
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
KOKKOS_INLINE_FUNCTION size_type i_end(size_type jEntry) const
End i entries with a j entry 'jEntry'.
Kokkos::View< size_type[], execution_space > coord_array_type
ordinal_type num_k() const
Number of k entries in C(i,j,k)
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
Kokkos::View< value_type[], execution_space > value_array_type
FlatSparse3Tensor_kji< ValueType, Device > create_flat_sparse_3_tensor_kji(const Stokhos::ProductBasis< OrdinalType, ValueType > &basis, const Stokhos::Sparse3Tensor< OrdinalType, ValueType > &Cijk, const Teuchos::ParameterList ¶ms=Teuchos::ParameterList())
row_map_array_type m_i_row_map
FlatSparse3Tensor_kji< ValueType, Device > tensor_type
FlatSparse3Tensor_kji(const FlatSparse3Tensor_kji &rhs)
coord_array_type m_j_coord
row_map_array_type m_j_row_map
KOKKOS_INLINE_FUNCTION size_type num_flops() const
Number flop's per multiply-add.
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
Kokkos::View< size_type[], execution_space > row_map_array_type
KOKKOS_INLINE_FUNCTION const size_type & j_coord(const size_type jEntry) const
j coordinate for j entry 'jEntry'
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
KOKKOS_INLINE_FUNCTION size_type num_j(size_type k) const
Number of j entries with a coordinate 'k'.
KOKKOS_INLINE_FUNCTION size_type i_begin(size_type jEntry) const
Begin i entries with a j entry 'jEntry'.
KOKKOS_INLINE_FUNCTION size_type num_k() const
Number of k entries.
KOKKOS_INLINE_FUNCTION size_type num_i(size_type jEntry) const
Number of i entries with a j entry 'jEntry'.
KOKKOS_INLINE_FUNCTION size_type dimension() const
Dimension of the tensor.
Device::size_type size_type
KOKKOS_INLINE_FUNCTION const value_type & value(const size_type iEntry) const
Value for i entry 'iEntry'.
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
coord_array_type m_i_coord
ExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION size_type j_begin(size_type k) const
Begin j entries with a coordinate 'k'.
k_iterator k_end() const
Iterator pointing to last k entry.
static KOKKOS_INLINE_FUNCTION void apply(const tensor_type &tensor, const MatrixValue *const a, const VectorValue *const x, VectorValue *const y)
Stokhos::Sparse3Tensor< int, double > Cijk_type
Kokkos::View< size_type[], execution_space > entry_array_type
static FlatSparse3Tensor_kji create(const Stokhos::ProductBasis< OrdinalType, ValueType > &basis, const Stokhos::Sparse3Tensor< OrdinalType, ValueType > &Cijk, const Teuchos::ParameterList ¶ms=Teuchos::ParameterList())
FlatSparse3Tensor_kji & operator=(const FlatSparse3Tensor_kji &rhs)
kji_iterator i_begin(const kj_iterator &j) const
Iterator pointing to first i entry for given j and k.
kji_iterator i_end(const kj_iterator &j) const
Iterator pointing to last i entry for given j and k.
KOKKOS_INLINE_FUNCTION size_type j_end(size_type k) const
End j entries with a coordinate 'k'.
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< RD, RP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value >::type sum(const Kokkos::View< RD, RP...> &r, const Kokkos::View< XD, XP...> &x)
virtual ordinal_type size() const =0
Return total size of basis.
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
KOKKOS_INLINE_FUNCTION size_type num_non_zeros() const
Number of non-zero's.
KOKKOS_INLINE_FUNCTION size_type entry_count() const
Number of sparse entries.