42 #ifndef KOKKOS_CRSMATRIX_MP_VECTOR_HPP 43 #define KOKKOS_CRSMATRIX_MP_VECTOR_HPP 47 #include "Kokkos_Sparse.hpp" 50 #include "Kokkos_Core.hpp" 53 #include "Teuchos_TestForException.hpp" 63 template <
typename Matrix,
typename InputVector,
typename OutputVector,
64 typename Update = MultiplyAssign,
65 typename Enabled =
void>
75 template <
typename MatrixDevice,
76 typename MatrixStorage,
77 typename MatrixOrdinal,
78 typename MatrixMemory,
80 typename InputStorage,
82 typename OutputStorage,
90 Kokkos::View< Sacado::MP::Vector<InputStorage>*,
92 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
95 #ifdef KOKKOS_HAVE_CUDA 96 , typename std::enable_if<
97 !std::is_same<MatrixDevice,Kokkos::Cuda>::value >::type
138 KOKKOS_INLINE_FUNCTION
142 const size_type iEntryBegin = m_A.graph.row_map[iRow];
143 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
145 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
146 size_type iCol = m_A.graph.entries(iEntry);
147 sum += m_A.values(iEntry) * m_x(iCol);
149 m_update( m_y(iRow),
sum );
157 const size_type row_count = A.graph.row_map.dimension_0()-1;
169 template <
typename MatrixDevice,
170 typename MatrixStorage,
171 typename MatrixOrdinal,
172 typename MatrixMemory,
174 typename InputStorage,
176 typename OutputStorage,
177 typename ... OutputP,
184 Kokkos::View< Sacado::MP::Vector<InputStorage>**,
186 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
189 #ifdef KOKKOS_HAVE_CUDA 190 , typename std::enable_if<
191 !std::is_same<MatrixDevice,Kokkos::Cuda>::value >::type
231 KOKKOS_INLINE_FUNCTION
236 const size_type num_col = m_y.dimension_1();
237 for (
size_type col=0; col<num_col; ++col) {
239 const size_type iEntryBegin = m_A.graph.row_map[iRow];
240 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
242 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
243 size_type iCol = m_A.graph.entries(iEntry);
244 sum += m_A.values(iEntry) * m_x(iCol,col);
246 m_update( m_y(iRow,col),
sum );
257 const size_type row_count = A.graph.row_map.dimension_0()-1;
271 template <
typename MatrixDevice,
272 typename MatrixStorage,
273 typename MatrixOrdinal,
274 typename MatrixMemory,
276 typename InputStorage,
278 typename OutputStorage,
279 typename ... OutputP>
285 Kokkos::View< Sacado::MP::Vector<InputStorage>*,
287 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
328 template <
typename MatrixDevice,
329 typename MatrixStorage,
330 typename MatrixOrdinal,
331 typename MatrixMemory,
333 typename InputStorage,
335 typename OutputStorage,
336 typename ... OutputP>
342 Kokkos::View< Sacado::MP::Vector<InputStorage>**,
344 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
382 template <
typename AlphaType,
388 typename ... OutputP>
389 typename std::enable_if<
397 const Kokkos::View< InputType, InputP... >&
x,
399 const Kokkos::View< OutputType, OutputP... >&
y,
402 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
403 typedef Kokkos::View< InputType, InputP... > InputVectorType;
404 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
408 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
413 "MV_Multiply not implemented for non-constant a or b");
416 value_type aa = Sacado::Value<AlphaType>::eval(a);
417 value_type bb = Sacado::Value<BetaType>::eval(b);
423 InputVectorType,OutputVectorType,UpdateType> multiply_type;
424 multiply_type::apply( A,
x,
y, UpdateType() );
430 InputVectorType,OutputVectorType,UpdateType> multiply_type;
431 multiply_type::apply( A,
x,
y, UpdateType(aa) );
439 InputVectorType,OutputVectorType,UpdateType> multiply_type;
440 multiply_type::apply( A,
x,
y, UpdateType() );
446 InputVectorType,OutputVectorType,UpdateType> multiply_type;
447 multiply_type::apply( A,
x,
y, UpdateType(aa) );
454 InputVectorType,OutputVectorType,UpdateType> multiply_type;
455 multiply_type::apply( A,
x,
y, UpdateType(aa,bb) );
459 template <
typename AlphaType,
465 typename ... OutputP>
466 typename std::enable_if<
474 const Kokkos::View< InputType, InputP... >&
x,
476 const Kokkos::View< OutputType, OutputP... >&
y,
481 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
483 if (
y.dimension_1() == 1) {
484 auto y_1D = subview(
y, Kokkos::ALL(), 0);
485 auto x_1D = subview(
x, Kokkos::ALL(), 0);
486 spmv(mode, a, A, x_1D, b, y_1D, RANK_ONE());
489 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
490 typedef Kokkos::View< InputType, InputP... > InputVectorType;
491 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
495 "Stokhos spmv not implemented for non-constant a or b");
498 value_type aa = Sacado::Value<AlphaType>::eval(a);
499 value_type bb = Sacado::Value<BetaType>::eval(b);
505 InputVectorType,OutputVectorType,UpdateType> multiply_type;
506 multiply_type::apply( A,
x,
y, UpdateType() );
512 InputVectorType,OutputVectorType,UpdateType> multiply_type;
513 multiply_type::apply( A,
x,
y, UpdateType(aa) );
521 InputVectorType,OutputVectorType,UpdateType> multiply_type;
522 multiply_type::apply( A,
x,
y, UpdateType() );
528 InputVectorType,OutputVectorType,UpdateType> multiply_type;
529 multiply_type::apply( A,
x,
y, UpdateType(aa) );
536 InputVectorType,OutputVectorType,UpdateType> multiply_type;
537 multiply_type::apply( A,
x,
y, UpdateType(aa,bb) );
const input_vector_type m_x
Sacado::MP::Vector< OutputStorage > OutputVectorValue
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
Sacado::MP::Vector< MatrixStorage > MatrixValue
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
const update_type m_update
Kokkos::View< InputVectorValue *, InputP... > input_vector_type
const output_vector_type m_y
OutputVectorValue scalar_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Sacado::MP::Vector< InputStorage > InputVectorValue
Sacado::MP::Vector< OutputStorage > OutputVectorValue
MatrixDevice execution_space
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
Sacado::MP::Vector< InputStorage > InputVectorValue
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
MPMultiply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
MatrixDevice execution_space
execution_space::size_type size_type
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
matrix_type::values_type matrix_values_type
const update_type m_update
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< RD, RP... > >::value &&Kokkos::is_view_uq_pce< Kokkos::View< XD, XP... > >::value >::type sum(const Kokkos::View< RD, RP... > &r, const Kokkos::View< XD, XP... > &x)
execution_space::size_type size_type
Sacado::MP::Vector< MatrixStorage > MatrixValue
matrix_type::values_type matrix_values_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
Kokkos::View< InputVectorValue **, InputP... > input_vector_type
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
Sacado::MP::Vector< InputStorage > InputVectorValue
Top-level namespace for Stokhos classes and functions.
Kokkos::View< InputVectorValue *, InputP... > input_vector_type
const input_vector_type m_x
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
Kokkos::View< InputVectorValue **, InputP... > input_vector_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
MatrixDevice execution_space
Sacado::MP::Vector< MatrixStorage > MatrixValue
matrix_type::values_type matrix_values_type
execution_space::size_type size_type
MatrixDevice execution_space
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
OutputVectorValue scalar_type
MPMultiply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
execution_space::size_type size_type
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType ValueType * y
Sacado::MP::Vector< MatrixStorage > MatrixValue
void update(const ValueType &alpha, VectorType &x, const ValueType &beta, const VectorType &y)
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< InputType, InputP... > >::value &&Kokkos::is_view_uq_pce< Kokkos::View< OutputType, OutputP... > >::value >::type spmv(const char mode[], const AlphaType &a, const MatrixType &A, const Kokkos::View< InputType, InputP... > &x, const BetaType &b, const Kokkos::View< OutputType, OutputP... > &y, const RANK_ONE)
const output_vector_type m_y
Sacado::MP::Vector< InputStorage > InputVectorValue
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type