Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_BlockCrsMatrix.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef STOKHOS_BLOCKCRSMATRIX_HPP
11 #define STOKHOS_BLOCKCRSMATRIX_HPP
12 
13 #include "Kokkos_Core.hpp"
14 #include "Kokkos_StaticCrsGraph.hpp"
15 
16 #include "Stokhos_Multiply.hpp"
17 
18 namespace Stokhos {
19 
28 template <typename BlockSpec, typename ValueType, class Device>
30 public:
31 
32  typedef Device execution_space;
33  typedef typename execution_space::size_type size_type;
34  typedef ValueType value_type;
35  typedef BlockSpec block_spec;
36  typedef Kokkos::StaticCrsGraph< size_type , execution_space > graph_type;
37  typedef Kokkos::View< value_type**, Kokkos::LayoutLeft, execution_space > block_vector_type ;
38 
42 };
43 
44 template <typename BlockSpec,
45  typename MatrixValue,
46  typename VectorValue,
47  typename Device>
48 class Multiply< BlockCrsMatrix< BlockSpec, MatrixValue, Device >,
49  Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device >,
50  Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device > >
51 {
52 public:
53 
54  typedef Device execution_space ;
55  typedef typename BlockSpec::size_type size_type ;
56  typedef Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device > block_vector_type ;
58 
62 
64  const block_vector_type& x,
66  : m_A( A )
67  , m_x( x )
68  , m_y( y )
69  {}
70 
71  //--------------------------------------------------------------------------
72  // A( storage_size( m_A.block.size() ) , m_A.graph.row_map.size() );
73  // x( m_A.block.dimension() , m_A.graph.row_map.first_count() );
74  // y( m_A.block.dimension() , m_A.graph.row_map.first_count() );
75  //
76 
77  KOKKOS_INLINE_FUNCTION
78  void operator()( const size_type iBlockRow ) const
79  {
80  // Prefer that y[ m_A.block.dimension() ] be scratch space
81  // on the local thread, but cannot dynamically allocate
82  VectorValue * const y = & m_y(0,iBlockRow);
83 
84  const size_type iEntryBegin = m_A.graph.row_map[ iBlockRow ];
85  const size_type iEntryEnd = m_A.graph.row_map[ iBlockRow + 1 ];
86 
87  // Leading dimension guaranteed contiguous for LayoutLeft
88  for ( size_type j = 0 ; j < m_A.block.dimension() ; ++j ) { y[j] = 0 ; }
89 
90  for ( size_type iEntry = iEntryBegin ; iEntry < iEntryEnd ; ++iEntry ) {
91  const VectorValue * const x = & m_x( 0 , m_A.graph.entries(iEntry) );
92  const MatrixValue * const a = & m_A.values( 0 , iEntry );
93 
94  BlockMultiply< BlockSpec >::apply( m_A.block , a , x , y );
95  }
96 
97  }
98 
99  static void apply( const matrix_type& A,
100  const block_vector_type& x,
101  block_vector_type& y )
102  {
103  const size_t row_count = A.graph.row_map.extent(0) - 1;
104  Kokkos::parallel_for( row_count , Multiply(A,x,y) );
105  }
106 };
107 
108 //----------------------------------------------------------------------------
109 //----------------------------------------------------------------------------
110 
111 } // namespace Stokhos
112 
113 #endif /* #ifndef STOKHOS_BLOCKCRSMATRIX_HPP */
execution_space::size_type size_type
Kokkos::View< value_type **, Kokkos::LayoutLeft, execution_space > block_vector_type
Kokkos::StaticCrsGraph< size_type, execution_space > graph_type
CRS matrix of dense blocks.