10 #ifndef STOKHOS_LEXICOGRAPHIC_BLOCK_SPARSE_3_TENSOR_HPP
11 #define STOKHOS_LEXICOGRAPHIC_BLOCK_SPARSE_3_TENSOR_HPP
13 #include "Kokkos_Core.hpp"
31 template<
typename ValueType ,
class ExecutionSpace >
36 typedef typename execution_space::size_type
size_type;
41 typedef Kokkos::View< int[][7] , Kokkos::LayoutRight, execution_space >
coord_array_type;
85 KOKKOS_INLINE_FUNCTION
89 KOKKOS_INLINE_FUNCTION
93 KOKKOS_INLINE_FUNCTION
97 KOKKOS_INLINE_FUNCTION
103 KOKKOS_INLINE_FUNCTION
109 KOKKOS_INLINE_FUNCTION
115 KOKKOS_INLINE_FUNCTION
121 KOKKOS_INLINE_FUNCTION
127 KOKKOS_INLINE_FUNCTION
133 KOKKOS_INLINE_FUNCTION
139 KOKKOS_INLINE_FUNCTION
144 KOKKOS_INLINE_FUNCTION
148 KOKKOS_INLINE_FUNCTION
152 KOKKOS_INLINE_FUNCTION
155 template <
typename OrdinalType>
172 typename coord_array_type::HostMirror host_coord =
174 typename value_array_type::HostMirror host_value =
179 typedef typename Cijk_type::CijkNode
node_type;
185 OrdinalType child_index;
186 OrdinalType coord_index = 0;
187 OrdinalType value_index = 0;
189 while (node_stack.
size() > 0) {
190 node = node_stack.
back();
191 child_index = index_stack.
back();
195 host_coord(coord_index, 0) = node->i_begin;
196 host_coord(coord_index, 1) = node->j_begin;
197 host_coord(coord_index, 2) = node->k_begin;
198 host_coord(coord_index, 3) = node->p_i;
199 host_coord(coord_index, 4) = node->p_j;
200 host_coord(coord_index, 5) = node->p_k;
201 host_coord(coord_index, 6) = node->parent_j_equals_k;
203 for (OrdinalType i=0; i<node->my_num_entries; ++i)
204 host_value(value_index++) = node->values[i];
205 tensor.
m_flops += 5*node->my_num_entries + node->i_size;
211 else if (child_index < node->children.size()) {
212 ++index_stack.
back();
213 node = node->children[child_index];
250 template<
class Device ,
typename OrdinalType ,
typename ValueType >
251 LexicographicBlockSparse3Tensor<ValueType, Device>
258 basis, Cijk, params);
261 template <
typename ValueType,
typename Device >
269 template<
typename MatrixValue ,
typename VectorValue >
270 KOKKOS_INLINE_FUNCTION
272 const MatrixValue *
const a ,
273 const VectorValue *
const x ,
274 VectorValue *
const y )
282 for (
size_type block = 0; block < nBlock; ++block) {
286 const int p_i = tensor.
get_p_i(block);
287 const int p_j = tensor.
get_p_j(block);
288 const int p_k = tensor.
get_p_k(block);
289 VectorValue *
const y_block = y + i_begin;
290 const MatrixValue *
const a_j_block = a + j_begin;
291 const VectorValue *
const x_k_block = x + k_begin;
292 const MatrixValue *
const a_k_block = a + k_begin;
293 const VectorValue *
const x_j_block = x + j_begin;
309 for (
int i=0; i<=p_i; ++i) {
310 VectorValue ytmp = 0;
311 for (
int j=0;
j<=p_j; ++
j) {
312 int k0 =
j%2 != (i+
j)%2 ?
j+1 :
j;
313 for (
int k=k0; k<=p_k; k+=2) {
314 ytmp += tensor.
value(value_entry++) *
315 ( a_j_block[
j] * x_k_block[k] + a_k_block[k] * x_j_block[
j] );
322 for (
int i=0; i<=p_i; ++i) {
323 VectorValue ytmp = 0;
324 for (
int j=0;
j<=p_j; ++
j) {
325 for (
int k=(i+
j)%2; k<=p_k; k+=2) {
326 ytmp += tensor.
value(value_entry++) *
327 ( a_j_block[
j] * x_k_block[k] + a_k_block[k] * x_j_block[
j] );
341 for (
size_type block = 0; block < nBlock; ++block) {
345 const int p_i = tensor.
get_p_i(block);
346 const int p_j = tensor.
get_p_j(block);
347 const int p_k = tensor.
get_p_k(block);
348 VectorValue *
const y_block = y + i_begin;
349 const MatrixValue *
const a_j_block = a + j_begin;
350 const VectorValue *
const x_k_block = x + k_begin;
351 const MatrixValue *
const a_k_block = a + k_begin;
352 const VectorValue *
const x_j_block = x + j_begin;
368 for (
int i=0; i<=p_i; ++i) {
369 VectorValue ytmp = 0;
370 for (
int j=0;
j<=p_j; ++
j) {
371 for (
int k=
j; k<=p_k; ++k) {
372 ytmp += tensor.
value(value_entry++) *
373 ( a_j_block[
j] * x_k_block[k] + a_k_block[k] * x_j_block[
j] );
380 for (
int i=0; i<=p_i; ++i) {
381 VectorValue ytmp = 0;
382 for (
int j=0;
j<=p_j; ++
j) {
383 for (
int k=0; k<=p_k; ++k) {
384 ytmp += tensor.
value(value_entry++) *
385 ( a_j_block[
j] * x_k_block[k] + a_k_block[k] * x_j_block[
j] );
396 KOKKOS_INLINE_FUNCTION
400 KOKKOS_INLINE_FUNCTION
Teuchos::RCP< const CijkNode > getHeadNode() const
Get the head node.
KOKKOS_INLINE_FUNCTION int get_j_begin(const size_type entry) const
LexicographicBlockSparse3Tensor< ValueType, Device > create_lexicographic_block_sparse_3_tensor(const Stokhos::ProductBasis< OrdinalType, ValueType > &basis, const Stokhos::LTBSparse3Tensor< OrdinalType, ValueType > &Cijk, const Teuchos::ParameterList ¶ms=Teuchos::ParameterList())
LexicographicBlockSparse3Tensor(const LexicographicBlockSparse3Tensor &rhs)
KOKKOS_INLINE_FUNCTION int get_p_k(const size_type entry) const
static KOKKOS_INLINE_FUNCTION void apply(const tensor_type &tensor, const MatrixValue *const a, const VectorValue *const x, VectorValue *const y)
KOKKOS_INLINE_FUNCTION int get_j_eq_k(const size_type entry) const
Kokkos::View< value_type[], execution_space > value_array_type
ordinal_type num_entries() const
Return number of non-zero entries.
ordinal_type num_leafs() const
Return number of nodes.
KOKKOS_INLINE_FUNCTION size_type num_value() const
Number of values.
LexicographicBlockSparse3Tensor & operator=(const LexicographicBlockSparse3Tensor &rhs)
Data structure storing a sparse 3-tensor C(i,j,k) in a a tree-based format for lexicographically orde...
ExecutionSpace execution_space
Device::size_type size_type
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
static KOKKOS_INLINE_FUNCTION size_type vector_size(const tensor_type &tensor)
execution_space::size_type size_type
static KOKKOS_INLINE_FUNCTION size_type matrix_size(const tensor_type &tensor)
KOKKOS_INLINE_FUNCTION int get_k_begin(const size_type entry) const
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
KOKKOS_INLINE_FUNCTION size_type num_coord() const
Number of coordinates.
KOKKOS_INLINE_FUNCTION size_type num_flops() const
Number flop's per multiply-add.
Kokkos::View< int[][7], Kokkos::LayoutRight, execution_space > coord_array_type
Stokhos::Sparse3Tensor< int, double > Cijk_type
KOKKOS_INLINE_FUNCTION int get_p_i(const size_type entry) const
void push_back(const value_type &x)
bool symmetric() const
Return if symmetric.
LexicographicBlockSparse3Tensor< ValueType, Device > tensor_type
KOKKOS_INLINE_FUNCTION bool symmetric() const
Is PDF symmetric.
LexicographicBlockSparse3Tensor()
KOKKOS_INLINE_FUNCTION const value_type & value(const size_type entry) const
Cijk for entry 'entry'.
~LexicographicBlockSparse3Tensor()
KOKKOS_INLINE_FUNCTION size_type dimension() const
Dimension of the tensor.
static LexicographicBlockSparse3Tensor create(const Stokhos::ProductBasis< OrdinalType, ValueType > &basis, const Stokhos::LTBSparse3Tensor< OrdinalType, ValueType > &Cijk, const Teuchos::ParameterList ¶ms=Teuchos::ParameterList())
KOKKOS_INLINE_FUNCTION int get_p_j(const size_type entry) const
KOKKOS_INLINE_FUNCTION int get_i_begin(const size_type entry) const
#define TEUCHOS_ASSERT(assertion_test)
virtual ordinal_type size() const =0
Return total size of basis.
KOKKOS_INLINE_FUNCTION size_type num_non_zeros() const
Number of non-zero's.
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)