Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_SymmetricDiagonalSpec.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_SYMMETRIC_DIAGONAL_SPEC_HPP
11 #define STOKHOS_SYMMETRIC_DIAGONAL_SPEC_HPP
12 
13 
14 namespace Stokhos {
15 
29 template< class ExecutionSpace >
31 public:
32 
33  typedef unsigned size_type;
34 
36  KOKKOS_INLINE_FUNCTION
37  unsigned dimension() const { return m_dimension ; }
38 
40  KOKKOS_INLINE_FUNCTION
41  unsigned matrix_offset( const unsigned row , const unsigned column ) const
42  {
43  const int diag_count = 1 + ( m_dimension >> 1 );
44  const int diag = (int) column - (int) row ;
45 
46  unsigned offset = 0 ;
47 
48  if ( ( 0 <= diag && diag < diag_count ) || ( diag <= - diag_count ) ) {
49  offset = row + m_dimension * ( ( m_dimension + diag ) % m_dimension );
50  }
51  else {
52  offset = column + m_dimension * ( ( m_dimension - diag ) % m_dimension );
53  }
54 
55  return offset ;
56  }
57 
59  KOKKOS_INLINE_FUNCTION
60  unsigned matrix_size() const
61  { return ( m_dimension * ( m_dimension + 1 ) ) >> 1 ; }
62 
64  : m_dimension( 0 ) {}
65 
67  : m_dimension( rhs.m_dimension ) {}
68 
69  SymmetricDiagonalSpec & operator =
70  ( const SymmetricDiagonalSpec & rhs )
71  { m_dimension = rhs.m_dimension ; return *this ; }
72 
73  explicit
74  SymmetricDiagonalSpec( const unsigned dim )
75  : m_dimension( dim ) {}
76 
77 private:
78  unsigned m_dimension ;
79 };
80 
81 template < typename Device >
83 public:
84  typedef Device execution_space ;
85  typedef typename execution_space::size_type size_type ;
87 
88  template< typename MatrixValue , typename VectorValue >
89  KOKKOS_INLINE_FUNCTION
90  static void apply( const block_type & block ,
91  const MatrixValue * a ,
92  const VectorValue * const x ,
93  VectorValue * const y )
94  {
95  const size_type dimension = block.dimension();
96  const size_type dim_half = ( dimension + 1 ) >> 1 ;
97 
98  // Multiply the main diagonal (first diagonal)
99  for ( size_type j = 0 ; j < dimension ; ++j ) {
100  y[j] += a[j] * x[j] ; // Contiguous access
101  }
102 
103  // Multiply remaining full diagionals, each diagonal is accessed twice
104  for ( size_type d = 1 ; d < dim_half ; ++d ) {
105  size_type kx = d ;
106  size_type kxr = dimension - d ;
107 
108  a += dimension ; // next diagonal
109 
110  for ( size_type j = 0 ; j < dimension ; ++j ) {
111  y[j] += a[j] * x[kx] + a[kxr] * x[kxr]; // Contiguous access
112  if ( dimension == ++kx ) kx = 0 ;
113  if ( dimension == ++kxr ) kxr = 0 ;
114  }
115  }
116 
117  // If even number of diagonals then the last diagonal is half-length
118  if ( ! ( dimension & 01 ) ) {
119  size_type kx = dim_half ;
120 
121  a += dimension ; // next diagonal
122 
123  for ( size_type j = 0 ; j < dim_half ; ++j , ++kx ) {
124  y[j] += a[j] * x[kx] ; // Contiguous access
125  y[kx] += a[j] * x[j] ; // Contiguous access
126  }
127  }
128  }
129 
130  KOKKOS_INLINE_FUNCTION
131  static size_type matrix_size( const block_type & block )
132  { return block.matrix_size(); }
133 };
134 
135 } // namespace Stokhos
136 
137 #endif /* #ifndef STOKHOS_SYMMETRIC_DIAGONAL_SPEC_HPP */
static KOKKOS_INLINE_FUNCTION size_type matrix_size(const block_type &block)
static KOKKOS_INLINE_FUNCTION void apply(const block_type &block, const MatrixValue *a, const VectorValue *const x, VectorValue *const y)
KOKKOS_INLINE_FUNCTION unsigned matrix_size() const
Storage size for block coefficients.
KOKKOS_INLINE_FUNCTION unsigned matrix_offset(const unsigned row, const unsigned column) const
Storage location for the (row,column) entry.
SymmetricDiagonalSpec(const SymmetricDiagonalSpec &rhs)
Symmetric diagonal storage for a dense matrix.
KOKKOS_INLINE_FUNCTION unsigned dimension() const
Dimension of vector block.