10 #ifndef STOKHOS_FLAT_SPARSE_3_TENSOR_HPP
11 #define STOKHOS_FLAT_SPARSE_3_TENSOR_HPP
13 #include "Kokkos_Core.hpp"
29 template<
typename ValueType ,
class ExecutionSpace >
34 typedef typename execution_space::size_type
size_type ;
99 KOKKOS_INLINE_FUNCTION
103 KOKKOS_INLINE_FUNCTION
108 KOKKOS_INLINE_FUNCTION
113 KOKKOS_INLINE_FUNCTION
118 KOKKOS_INLINE_FUNCTION
123 KOKKOS_INLINE_FUNCTION
128 KOKKOS_INLINE_FUNCTION
133 KOKKOS_INLINE_FUNCTION
138 KOKKOS_INLINE_FUNCTION
143 KOKKOS_INLINE_FUNCTION
148 KOKKOS_INLINE_FUNCTION
153 KOKKOS_INLINE_FUNCTION
158 KOKKOS_INLINE_FUNCTION
162 template <
typename OrdinalType>
172 std::vector< size_t > k_coord_work( dimension , (
size_t) 0 );
174 for (
typename Cijk_type::i_iterator i_it=Cijk.
i_begin();
175 i_it!=Cijk.
i_end(); ++i_it) {
176 OrdinalType i = index(i_it);
177 k_coord_work[i] = Cijk.
num_k(i_it);
178 k_entry_count += Cijk.
num_k(i_it);
182 std::vector< size_t > j_coord_work( k_entry_count , (
size_t) 0 );
185 for (
typename Cijk_type::i_iterator i_it=Cijk.
i_begin();
186 i_it!=Cijk.
i_end(); ++i_it) {
187 for (
typename Cijk_type::ik_iterator k_it = Cijk.
k_begin(i_it);
188 k_it != Cijk.
k_end(i_it); ++k_it, ++k_entry) {
189 OrdinalType k = index(k_it);
190 for (
typename Cijk_type::ikj_iterator j_it = Cijk.
j_begin(k_it);
191 j_it != Cijk.
j_end(k_it); ++j_it) {
192 OrdinalType
j = index(j_it);
194 ++j_coord_work[k_entry];
225 typename coord_array_type::HostMirror
227 typename coord_array_type::HostMirror
229 typename value_array_type::HostMirror
231 typename entry_array_type::HostMirror
233 typename entry_array_type::HostMirror
235 typename entry_array_type::HostMirror
237 typename entry_array_type::HostMirror
242 host_k_row_map(0) = 0;
244 sum += k_coord_work[i];
245 host_k_row_map(i+1) =
sum;
251 host_j_row_map(0) = 0;
252 for (
size_type i = 0 ; i < k_entry_count ; ++i ) {
253 sum += j_coord_work[i];
254 host_j_row_map(i+1) =
sum;
259 k_coord_work[i] = host_k_row_map[i];
261 for (
size_type i = 0 ; i < k_entry_count ; ++i ) {
262 j_coord_work[i] = host_j_row_map[i];
265 for (
typename Cijk_type::i_iterator i_it=Cijk.
i_begin();
266 i_it!=Cijk.
i_end(); ++i_it) {
267 OrdinalType i = index(i_it);
268 for (
typename Cijk_type::ik_iterator k_it = Cijk.
k_begin(i_it);
269 k_it != Cijk.
k_end(i_it); ++k_it) {
270 OrdinalType k = index(k_it);
271 const size_type kEntry = k_coord_work[i];
273 host_k_coord(kEntry) = k ;
275 for (
typename Cijk_type::ikj_iterator j_it = Cijk.
j_begin(k_it);
276 j_it != Cijk.
j_end(k_it); ++j_it) {
277 OrdinalType
j = index(j_it);
278 ValueType c = Stokhos::value(j_it);
280 const size_type jEntry = j_coord_work[kEntry];
281 ++j_coord_work[kEntry];
282 host_value(jEntry) = (j != k) ? c : 0.5*c;
283 host_j_coord(jEntry) =
j ;
284 ++host_num_j(kEntry);
306 template<
class Device ,
typename OrdinalType ,
typename ValueType >
307 FlatSparse3Tensor<ValueType, Device>
316 template <
typename ValueType,
typename Device>
324 template<
typename MatrixValue ,
typename VectorValue >
325 KOKKOS_INLINE_FUNCTION
327 const MatrixValue *
const a ,
328 const VectorValue *
const x ,
329 VectorValue *
const y )
336 VectorValue ytmp = 0;
342 for (
size_type kEntry = kBeg; kEntry < kEnd; ++kEntry) {
344 const MatrixValue ak = a[k];
345 const VectorValue xk = x[k];
351 for (
size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
353 ytmp += tensor.
value(jEntry) * ( a[
j] * xk + ak * x[
j] );
361 KOKKOS_INLINE_FUNCTION
365 KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION size_type k_end(size_type i) const
End k entries with a coordinate 'i'.
coord_array_type m_j_coord
KOKKOS_INLINE_FUNCTION size_type j_end(size_type kEntry) const
End j entries with a k entry 'kEntry'.
row_map_array_type m_j_row_map
KOKKOS_INLINE_FUNCTION const size_type & j_coord(const size_type jEntry) const
j coordinate for j entry 'jEntry'
coord_array_type m_k_coord
k_iterator k_begin() const
Iterator pointing to first k entry.
FlatSparse3Tensor< ValueType, Device > tensor_type
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
KOKKOS_INLINE_FUNCTION size_type entry_count() const
Number of sparse entries.
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_INLINE_FUNCTION size_type num_non_zeros() const
Number of non-zero's.
static KOKKOS_INLINE_FUNCTION size_type matrix_size(const tensor_type &tensor)
FlatSparse3Tensor< ValueType, Device > create_flat_sparse_3_tensor(const Stokhos::ProductBasis< OrdinalType, ValueType > &basis, const Stokhos::Sparse3Tensor< OrdinalType, ValueType > &Cijk, const Teuchos::ParameterList ¶ms=Teuchos::ParameterList())
KOKKOS_INLINE_FUNCTION size_type k_begin(size_type i) const
Begin k entries with a coordinate 'i'.
static KOKKOS_INLINE_FUNCTION void apply(const tensor_type &tensor, const MatrixValue *const a, const VectorValue *const x, VectorValue *const y)
Device::size_type size_type
KOKKOS_INLINE_FUNCTION size_type num_j(size_type kEntry) const
Number of j entries with a k entry 'kEntry'.
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
row_map_array_type m_k_row_map
execution_space::size_type size_type
Kokkos::View< value_type[], execution_space > value_array_type
KOKKOS_INLINE_FUNCTION const size_type & k_coord(const size_type kEntry) const
k coordinate for k entry 'kEntry'
FlatSparse3Tensor & operator=(const FlatSparse3Tensor &rhs)
KOKKOS_INLINE_FUNCTION size_type num_flops() const
Number flop's per multiply-add.
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
static FlatSparse3Tensor create(const Stokhos::ProductBasis< OrdinalType, ValueType > &basis, const Stokhos::Sparse3Tensor< OrdinalType, ValueType > &Cijk, const Teuchos::ParameterList ¶ms=Teuchos::ParameterList())
k_iterator k_end() const
Iterator pointing to last k entry.
static KOKKOS_INLINE_FUNCTION size_type vector_size(const tensor_type &tensor)
Stokhos::Sparse3Tensor< int, double > Cijk_type
KOKKOS_INLINE_FUNCTION size_type num_k(size_type i) const
Number of k entries with a coordinate 'i'.
Kokkos::View< size_type[], execution_space > entry_array_type
KOKKOS_INLINE_FUNCTION const value_type & value(const size_type jEntry) const
Value for j entry 'jEntry'.
KOKKOS_INLINE_FUNCTION size_type dimension() const
Dimension of the tensor.
Kokkos::View< size_type[], execution_space > coord_array_type
ExecutionSpace execution_space
kji_iterator i_begin(const kj_iterator &j) const
Iterator pointing to first i entry for given j and k.
FlatSparse3Tensor(const FlatSparse3Tensor &rhs)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
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_begin(size_type kEntry) const
Begin j entries with a k entry 'kEntry'.
Kokkos::View< size_type[], execution_space > row_map_array_type
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)