Stokhos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
kokkos
Stokhos_SymmetricDiagonalSpec.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_SYMMETRIC_DIAGONAL_SPEC_HPP
43
#define STOKHOS_SYMMETRIC_DIAGONAL_SPEC_HPP
44
45
#include "Kokkos_StaticCrsGraph.hpp"
46
47
namespace
Stokhos
{
48
62
template
<
class
ExecutionSpace >
63
class
SymmetricDiagonalSpec
{
64
public
:
65
66
typedef
unsigned
size_type
;
67
69
KOKKOS_INLINE_FUNCTION
70
unsigned
dimension
()
const
{
return
m_dimension
; }
71
73
KOKKOS_INLINE_FUNCTION
74
unsigned
matrix_offset
(
const
unsigned
row ,
const
unsigned
column )
const
75
{
76
const
int
diag_count = 1 + (
m_dimension
>> 1 );
77
const
int
diag
= (int) column - (
int
) row ;
78
79
unsigned
offset = 0 ;
80
81
if
( ( 0 <=
diag
&&
diag
< diag_count ) || (
diag
<= - diag_count ) ) {
82
offset = row +
m_dimension
* ( (
m_dimension
+
diag
) %
m_dimension
);
83
}
84
else
{
85
offset = column +
m_dimension
* ( (
m_dimension
-
diag
) %
m_dimension
);
86
}
87
88
return
offset ;
89
}
90
92
KOKKOS_INLINE_FUNCTION
93
unsigned
matrix_size
()
const
94
{
return
(
m_dimension
* (
m_dimension
+ 1 ) ) >> 1 ; }
95
96
SymmetricDiagonalSpec
()
97
:
m_dimension
( 0 ) {}
98
99
SymmetricDiagonalSpec
(
const
SymmetricDiagonalSpec
& rhs )
100
:
m_dimension
( rhs.
m_dimension
) {}
101
102
SymmetricDiagonalSpec
&
operator
=
103
(
const
SymmetricDiagonalSpec
& rhs )
104
{
m_dimension
= rhs.m_dimension ;
return
*this ; }
105
106
explicit
107
SymmetricDiagonalSpec
(
const
unsigned
dim )
108
:
m_dimension
( dim ) {}
109
110
private
:
111
unsigned
m_dimension
;
112
};
113
114
template
<
typename
Device >
115
class
BlockMultiply
<
SymmetricDiagonalSpec
< Device > > {
116
public
:
117
typedef
Device
execution_space
;
118
typedef
typename
execution_space::size_type
size_type
;
119
typedef
SymmetricDiagonalSpec< execution_space >
block_type
;
120
121
template
<
typename
MatrixValue ,
typename
VectorValue >
122
KOKKOS_INLINE_FUNCTION
123
static
void
apply
(
const
block_type
& block ,
124
const
MatrixValue * a ,
125
const
VectorValue *
const
x ,
126
VectorValue *
const
y )
127
{
128
const
size_type
dimension = block.
dimension
();
129
const
size_type
dim_half = ( dimension + 1 ) >> 1 ;
130
131
// Multiply the main diagonal (first diagonal)
132
for
(
size_type
j
= 0 ;
j
< dimension ; ++
j
) {
133
y[
j
] += a[
j
] * x[
j
] ;
// Contiguous access
134
}
135
136
// Multiply remaining full diagionals, each diagonal is accessed twice
137
for
(
size_type
d = 1 ; d < dim_half ; ++d ) {
138
size_type
kx = d ;
139
size_type
kxr = dimension - d ;
140
141
a += dimension ;
// next diagonal
142
143
for
(
size_type
j
= 0 ;
j
< dimension ; ++
j
) {
144
y[
j
] += a[
j
] * x[kx] + a[kxr] * x[kxr];
// Contiguous access
145
if
( dimension == ++kx ) kx = 0 ;
146
if
( dimension == ++kxr ) kxr = 0 ;
147
}
148
}
149
150
// If even number of diagonals then the last diagonal is half-length
151
if
( ! ( dimension & 01 ) ) {
152
size_type
kx = dim_half ;
153
154
a += dimension ;
// next diagonal
155
156
for
(
size_type
j
= 0 ;
j
< dim_half ; ++
j
, ++kx ) {
157
y[
j
] += a[
j
] * x[kx] ;
// Contiguous access
158
y[kx] += a[
j
] * x[
j
] ;
// Contiguous access
159
}
160
}
161
}
162
163
KOKKOS_INLINE_FUNCTION
164
static
size_type
matrix_size
(
const
block_type
& block )
165
{
return
block.
matrix_size
(); }
166
};
167
168
}
// namespace Stokhos
169
170
#endif
/* #ifndef STOKHOS_SYMMETRIC_DIAGONAL_SPEC_HPP */
j
j
Definition
Sacado_Fad_Exp_MP_Vector.hpp:527
Stokhos::BlockMultiply< SymmetricDiagonalSpec< Device > >::matrix_size
static KOKKOS_INLINE_FUNCTION size_type matrix_size(const block_type &block)
Definition
Stokhos_SymmetricDiagonalSpec.hpp:164
Stokhos::BlockMultiply< SymmetricDiagonalSpec< Device > >::apply
static KOKKOS_INLINE_FUNCTION void apply(const block_type &block, const MatrixValue *a, const VectorValue *const x, VectorValue *const y)
Definition
Stokhos_SymmetricDiagonalSpec.hpp:123
Stokhos::BlockMultiply< SymmetricDiagonalSpec< Device > >::size_type
execution_space::size_type size_type
Definition
Stokhos_SymmetricDiagonalSpec.hpp:118
Stokhos::BlockMultiply< SymmetricDiagonalSpec< Device > >::block_type
SymmetricDiagonalSpec< execution_space > block_type
Definition
Stokhos_SymmetricDiagonalSpec.hpp:119
Stokhos::BlockMultiply< SymmetricDiagonalSpec< Device > >::execution_space
Device execution_space
Definition
Stokhos_SymmetricDiagonalSpec.hpp:117
Stokhos::BlockMultiply
Definition
Stokhos_Multiply.hpp:174
Stokhos::SymmetricDiagonalSpec
Symmetric diagonal storage for a dense matrix.
Definition
Stokhos_SymmetricDiagonalSpec.hpp:63
Stokhos::SymmetricDiagonalSpec::matrix_offset
KOKKOS_INLINE_FUNCTION unsigned matrix_offset(const unsigned row, const unsigned column) const
Storage location for the (row,column) entry.
Definition
Stokhos_SymmetricDiagonalSpec.hpp:74
Stokhos::SymmetricDiagonalSpec< Kokkos::Cuda >::size_type
unsigned size_type
Definition
Stokhos_SymmetricDiagonalSpec.hpp:66
Stokhos::SymmetricDiagonalSpec::dimension
KOKKOS_INLINE_FUNCTION unsigned dimension() const
Dimension of vector block.
Definition
Stokhos_SymmetricDiagonalSpec.hpp:70
Stokhos::SymmetricDiagonalSpec< Kokkos::Cuda >::m_dimension
unsigned m_dimension
Definition
Stokhos_SymmetricDiagonalSpec.hpp:111
Stokhos::SymmetricDiagonalSpec::matrix_size
KOKKOS_INLINE_FUNCTION unsigned matrix_size() const
Storage size for block coefficients.
Definition
Stokhos_SymmetricDiagonalSpec.hpp:93
Stokhos::SymmetricDiagonalSpec::SymmetricDiagonalSpec
SymmetricDiagonalSpec()
Definition
Stokhos_SymmetricDiagonalSpec.hpp:96
Stokhos::SymmetricDiagonalSpec::SymmetricDiagonalSpec
SymmetricDiagonalSpec(const unsigned dim)
Definition
Stokhos_SymmetricDiagonalSpec.hpp:107
Stokhos::SymmetricDiagonalSpec::SymmetricDiagonalSpec
SymmetricDiagonalSpec(const SymmetricDiagonalSpec &rhs)
Definition
Stokhos_SymmetricDiagonalSpec.hpp:99
diag
@ diag
Definition
experimental/linear2d_diffusion_pce.cpp:140
Stokhos
Top-level namespace for Stokhos classes and functions.
Definition
Stokhos_AbstractPreconditionerFactory.hpp:48
Generated by
1.17.0