42 #ifndef STOKHOS_FLAT_SPARSE_3_TENSOR_HPP
43 #define STOKHOS_FLAT_SPARSE_3_TENSOR_HPP
45 #include "Kokkos_Core.hpp"
61 template<
typename ValueType ,
class ExecutionSpace >
66 typedef typename execution_space::size_type
size_type ;
131 KOKKOS_INLINE_FUNCTION
135 KOKKOS_INLINE_FUNCTION
140 KOKKOS_INLINE_FUNCTION
145 KOKKOS_INLINE_FUNCTION
150 KOKKOS_INLINE_FUNCTION
155 KOKKOS_INLINE_FUNCTION
160 KOKKOS_INLINE_FUNCTION
165 KOKKOS_INLINE_FUNCTION
170 KOKKOS_INLINE_FUNCTION
175 KOKKOS_INLINE_FUNCTION
180 KOKKOS_INLINE_FUNCTION
185 KOKKOS_INLINE_FUNCTION
190 KOKKOS_INLINE_FUNCTION
194 template <
typename OrdinalType>
204 std::vector< size_t > k_coord_work( dimension , (
size_t) 0 );
206 for (
typename Cijk_type::i_iterator i_it=Cijk.
i_begin();
207 i_it!=Cijk.
i_end(); ++i_it) {
208 OrdinalType i = index(i_it);
209 k_coord_work[i] = Cijk.
num_k(i_it);
210 k_entry_count += Cijk.
num_k(i_it);
214 std::vector< size_t > j_coord_work( k_entry_count , (
size_t) 0 );
217 for (
typename Cijk_type::i_iterator i_it=Cijk.
i_begin();
218 i_it!=Cijk.
i_end(); ++i_it) {
219 for (
typename Cijk_type::ik_iterator k_it = Cijk.
k_begin(i_it);
220 k_it != Cijk.
k_end(i_it); ++k_it, ++k_entry) {
221 OrdinalType k = index(k_it);
222 for (
typename Cijk_type::ikj_iterator j_it = Cijk.
j_begin(k_it);
223 j_it != Cijk.
j_end(k_it); ++j_it) {
224 OrdinalType
j = index(j_it);
226 ++j_coord_work[k_entry];
257 typename coord_array_type::HostMirror
259 typename coord_array_type::HostMirror
261 typename value_array_type::HostMirror
263 typename entry_array_type::HostMirror
265 typename entry_array_type::HostMirror
267 typename entry_array_type::HostMirror
269 typename entry_array_type::HostMirror
274 host_k_row_map(0) = 0;
276 sum += k_coord_work[i];
277 host_k_row_map(i+1) =
sum;
283 host_j_row_map(0) = 0;
284 for (
size_type i = 0 ; i < k_entry_count ; ++i ) {
285 sum += j_coord_work[i];
286 host_j_row_map(i+1) =
sum;
291 k_coord_work[i] = host_k_row_map[i];
293 for (
size_type i = 0 ; i < k_entry_count ; ++i ) {
294 j_coord_work[i] = host_j_row_map[i];
297 for (
typename Cijk_type::i_iterator i_it=Cijk.
i_begin();
298 i_it!=Cijk.
i_end(); ++i_it) {
299 OrdinalType i = index(i_it);
300 for (
typename Cijk_type::ik_iterator k_it = Cijk.
k_begin(i_it);
301 k_it != Cijk.
k_end(i_it); ++k_it) {
302 OrdinalType k = index(k_it);
303 const size_type kEntry = k_coord_work[i];
305 host_k_coord(kEntry) = k ;
307 for (
typename Cijk_type::ikj_iterator j_it = Cijk.
j_begin(k_it);
308 j_it != Cijk.
j_end(k_it); ++j_it) {
309 OrdinalType
j = index(j_it);
310 ValueType c = Stokhos::value(j_it);
312 const size_type jEntry = j_coord_work[kEntry];
313 ++j_coord_work[kEntry];
314 host_value(jEntry) = (j != k) ? c : 0.5*c;
315 host_j_coord(jEntry) =
j ;
316 ++host_num_j(kEntry);
338 template<
class Device ,
typename OrdinalType ,
typename ValueType >
339 FlatSparse3Tensor<ValueType, Device>
348 template <
typename ValueType,
typename Device>
356 template<
typename MatrixValue ,
typename VectorValue >
357 KOKKOS_INLINE_FUNCTION
359 const MatrixValue *
const a ,
360 const VectorValue *
const x ,
361 VectorValue *
const y )
368 VectorValue ytmp = 0;
374 for (
size_type kEntry = kBeg; kEntry < kEnd; ++kEntry) {
376 const MatrixValue ak = a[k];
377 const VectorValue xk = x[k];
383 for (
size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
385 ytmp += tensor.
value(jEntry) * ( a[
j] * xk + ak * x[
j] );
393 KOKKOS_INLINE_FUNCTION
397 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)