42 #ifndef STOKHOS_FLAT_SPARSE_3_TENSOR_KJI_HPP
43 #define STOKHOS_FLAT_SPARSE_3_TENSOR_KJI_HPP
45 #include "Kokkos_Core.hpp"
60 template<
typename ValueType ,
class ExecutionSpace >
65 typedef typename execution_space::size_type
size_type ;
135 KOKKOS_INLINE_FUNCTION
139 KOKKOS_INLINE_FUNCTION
143 KOKKOS_INLINE_FUNCTION
148 KOKKOS_INLINE_FUNCTION
153 KOKKOS_INLINE_FUNCTION
158 KOKKOS_INLINE_FUNCTION
163 KOKKOS_INLINE_FUNCTION
168 KOKKOS_INLINE_FUNCTION
173 KOKKOS_INLINE_FUNCTION
178 KOKKOS_INLINE_FUNCTION
183 KOKKOS_INLINE_FUNCTION
188 KOKKOS_INLINE_FUNCTION
193 KOKKOS_INLINE_FUNCTION
198 KOKKOS_INLINE_FUNCTION
202 template <
typename OrdinalType>
213 std::vector< size_t > j_coord_work( nk , (
size_t) 0 );
215 for (
typename Cijk_type::k_iterator k_it=Cijk.
k_begin();
216 k_it!=Cijk.
k_end(); ++k_it) {
217 OrdinalType k = index(k_it);
218 for (
typename Cijk_type::kj_iterator j_it = Cijk.
j_begin(k_it);
219 j_it != Cijk.
j_end(k_it); ++j_it) {
220 OrdinalType
j = index(j_it);
229 std::vector< size_t > i_coord_work( j_entry_count , (
size_t) 0 );
232 for (
typename Cijk_type::k_iterator k_it=Cijk.
k_begin();
233 k_it!=Cijk.
k_end(); ++k_it) {
234 OrdinalType k = index(k_it);
235 for (
typename Cijk_type::kj_iterator j_it = Cijk.
j_begin(k_it);
236 j_it != Cijk.
j_end(k_it); ++j_it) {
237 OrdinalType
j = index(j_it);
239 for (
typename Cijk_type::kji_iterator i_it = Cijk.
i_begin(j_it);
240 i_it != Cijk.
i_end(j_it); ++i_it) {
241 ++i_coord_work[j_entry];
272 tensor.
m_flops = 3*j_entry_count + 2*i_entry_count;
275 typename coord_array_type::HostMirror
277 typename coord_array_type::HostMirror
279 typename value_array_type::HostMirror
281 typename entry_array_type::HostMirror
283 typename entry_array_type::HostMirror
285 typename entry_array_type::HostMirror
287 typename entry_array_type::HostMirror
292 host_j_row_map(0) = 0;
294 sum += j_coord_work[k];
295 host_j_row_map(k+1) =
sum;
301 host_i_row_map(0) = 0;
303 sum += i_coord_work[
j];
304 host_i_row_map(
j+1) =
sum;
309 j_coord_work[k] = host_j_row_map[k];
312 i_coord_work[
j] = host_i_row_map[
j];
315 for (
typename Cijk_type::k_iterator k_it=Cijk.
k_begin();
316 k_it!=Cijk.
k_end(); ++k_it) {
317 OrdinalType k = index(k_it);
318 for (
typename Cijk_type::kj_iterator j_it = Cijk.
j_begin(k_it);
319 j_it != Cijk.
j_end(k_it); ++j_it) {
320 OrdinalType
j = index(j_it);
322 const size_type jEntry = j_coord_work[k];
324 host_j_coord(jEntry) =
j ;
326 for (
typename Cijk_type::kji_iterator i_it = Cijk.
i_begin(j_it);
327 i_it != Cijk.
i_end(j_it); ++i_it) {
328 OrdinalType i = index(i_it);
329 ValueType c = Stokhos::value(i_it);
330 const size_type iEntry = i_coord_work[jEntry];
331 ++i_coord_work[jEntry];
332 host_value(iEntry) = (j != k) ? c : 0.5*c;
333 host_i_coord(iEntry) = i ;
334 ++host_num_i(jEntry);
354 template<
class Device ,
typename OrdinalType ,
typename ValueType >
355 FlatSparse3Tensor_kji<ValueType, Device>
362 basis, Cijk, params );
365 template <
typename ValueType,
typename Device >
373 template<
typename MatrixValue ,
typename VectorValue >
374 KOKKOS_INLINE_FUNCTION
376 const MatrixValue *
const a ,
377 const VectorValue *
const x ,
378 VectorValue *
const y )
384 const MatrixValue ak = a[k];
385 const VectorValue xk = x[k];
391 for (
size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
393 VectorValue tmp = a[
j] * xk + ak * x[
j];
399 for (
size_type iEntry = iBeg; iEntry < iEnd; ++iEntry) {
401 y[i] += tensor.
value(iEntry) * tmp;
407 KOKKOS_INLINE_FUNCTION
411 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.