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 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef STOKHOS_BLOCKCRSMATRIX_HPP
43 #define STOKHOS_BLOCKCRSMATRIX_HPP
44 
45 //#include "Kokkos_View.hpp"
46 //#include "Kokkos_Layout.hpp"
47 //#include "Kokkos_Parallel.hpp"
48 #include "Kokkos_Core.hpp"
49 #include "Kokkos_StaticCrsGraph.hpp"
50 
51 #include "Stokhos_Multiply.hpp"
52 
53 namespace Stokhos {
54 
63 template <typename BlockSpec, typename ValueType, class Device>
65 public:
66 
67  typedef Device execution_space;
68  typedef typename execution_space::size_type size_type;
69  typedef ValueType value_type;
70  typedef BlockSpec block_spec;
71  typedef Kokkos::StaticCrsGraph< size_type , execution_space > graph_type;
72  typedef Kokkos::View< value_type**, Kokkos::LayoutLeft, execution_space > block_vector_type ;
73 
77 };
78 
79 template <typename BlockSpec,
80  typename MatrixValue,
81  typename VectorValue,
82  typename Device>
83 class Multiply< BlockCrsMatrix< BlockSpec, MatrixValue, Device >,
84  Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device >,
85  Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device > >
86 {
87 public:
88 
89  typedef Device execution_space ;
90  typedef typename BlockSpec::size_type size_type ;
91  typedef Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device > block_vector_type ;
93 
97 
99  const block_vector_type& x,
100  block_vector_type& y )
101  : m_A( A )
102  , m_x( x )
103  , m_y( y )
104  {}
105 
106  //--------------------------------------------------------------------------
107  // A( storage_size( m_A.block.size() ) , m_A.graph.row_map.size() );
108  // x( m_A.block.dimension() , m_A.graph.row_map.first_count() );
109  // y( m_A.block.dimension() , m_A.graph.row_map.first_count() );
110  //
111 
112  KOKKOS_INLINE_FUNCTION
113  void operator()( const size_type iBlockRow ) const
114  {
115  // Prefer that y[ m_A.block.dimension() ] be scratch space
116  // on the local thread, but cannot dynamically allocate
117  VectorValue * const y = & m_y(0,iBlockRow);
118 
119  const size_type iEntryBegin = m_A.graph.row_map[ iBlockRow ];
120  const size_type iEntryEnd = m_A.graph.row_map[ iBlockRow + 1 ];
121 
122  // Leading dimension guaranteed contiguous for LayoutLeft
123  for ( size_type j = 0 ; j < m_A.block.dimension() ; ++j ) { y[j] = 0 ; }
124 
125  for ( size_type iEntry = iEntryBegin ; iEntry < iEntryEnd ; ++iEntry ) {
126  const VectorValue * const x = & m_x( 0 , m_A.graph.entries(iEntry) );
127  const MatrixValue * const a = & m_A.values( 0 , iEntry );
128 
129  BlockMultiply< BlockSpec >::apply( m_A.block , a , x , y );
130  }
131 
132  }
133 
134  static void apply( const matrix_type& A,
135  const block_vector_type& x,
136  block_vector_type& y )
137  {
138  const size_t row_count = A.graph.row_map.extent(0) - 1;
139  Kokkos::parallel_for( row_count , Multiply(A,x,y) );
140  }
141 };
142 
143 //----------------------------------------------------------------------------
144 //----------------------------------------------------------------------------
145 
146 } // namespace Stokhos
147 
148 #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.