Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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_Core.hpp"
46#include "Kokkos_StaticCrsGraph.hpp"
47
48#include "Stokhos_Multiply.hpp"
49
50namespace Stokhos {
51
60template <typename BlockSpec, typename ValueType, class Device>
62public:
63
64 typedef Device execution_space;
65 typedef typename execution_space::size_type size_type;
66 typedef ValueType value_type;
67 typedef BlockSpec block_spec;
68 typedef Kokkos::StaticCrsGraph< size_type , execution_space > graph_type;
69 typedef Kokkos::View< value_type**, Kokkos::LayoutLeft, execution_space > block_vector_type ;
70
74};
75
76template <typename BlockSpec,
77 typename MatrixValue,
78 typename VectorValue,
79 typename Device>
80class Multiply< BlockCrsMatrix< BlockSpec, MatrixValue, Device >,
81 Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device >,
82 Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device > >
83{
84public:
85
86 typedef Device execution_space ;
87 typedef typename BlockSpec::size_type size_type ;
88 typedef Kokkos::View< VectorValue**, Kokkos::LayoutLeft, Device > block_vector_type ;
89 typedef BlockCrsMatrix< BlockSpec, MatrixValue, Device > matrix_type ;
90
94
96 const block_vector_type& x,
98 : m_A( A )
99 , m_x( x )
100 , m_y( y )
101 {}
102
103 //--------------------------------------------------------------------------
104 // A( storage_size( m_A.block.size() ) , m_A.graph.row_map.size() );
105 // x( m_A.block.dimension() , m_A.graph.row_map.first_count() );
106 // y( m_A.block.dimension() , m_A.graph.row_map.first_count() );
107 //
108
109 KOKKOS_INLINE_FUNCTION
110 void operator()( const size_type iBlockRow ) const
111 {
112 // Prefer that y[ m_A.block.dimension() ] be scratch space
113 // on the local thread, but cannot dynamically allocate
114 VectorValue * const y = & m_y(0,iBlockRow);
115
116 const size_type iEntryBegin = m_A.graph.row_map[ iBlockRow ];
117 const size_type iEntryEnd = m_A.graph.row_map[ iBlockRow + 1 ];
118
119 // Leading dimension guaranteed contiguous for LayoutLeft
120 for ( size_type j = 0 ; j < m_A.block.dimension() ; ++j ) { y[j] = 0 ; }
121
122 for ( size_type iEntry = iEntryBegin ; iEntry < iEntryEnd ; ++iEntry ) {
123 const VectorValue * const x = & m_x( 0 , m_A.graph.entries(iEntry) );
124 const MatrixValue * const a = & m_A.values( 0 , iEntry );
125
126 BlockMultiply< BlockSpec >::apply( m_A.block , a , x , y );
127 }
128
129 }
130
131 static void apply( const matrix_type& A,
132 const block_vector_type& x,
134 {
135 const size_t row_count = A.graph.row_map.extent(0) - 1;
136 Kokkos::parallel_for( row_count , Multiply(A,x,y) );
137 }
138};
139
140//----------------------------------------------------------------------------
141//----------------------------------------------------------------------------
142
143} // namespace Stokhos
144
145#endif /* #ifndef STOKHOS_BLOCKCRSMATRIX_HPP */
CRS matrix of dense blocks.
Kokkos::View< value_type **, Kokkos::LayoutLeft, execution_space > block_vector_type
Kokkos::StaticCrsGraph< size_type, execution_space > graph_type
execution_space::size_type size_type
Top-level namespace for Stokhos classes and functions.