42 #ifndef KOKKOS_CRSMATRIX_MP_VECTOR_HPP
43 #define KOKKOS_CRSMATRIX_MP_VECTOR_HPP
47 #include "KokkosSparse_CrsMatrix.hpp"
48 #include "KokkosSparse_spmv.hpp"
51 #include "Kokkos_Core.hpp"
64 template <
typename Matrix,
typename InputVector,
typename OutputVector,
65 typename Update = MultiplyAssign,
66 typename Enabled =
void>
76 template <
typename MatrixDevice,
77 typename MatrixStorage,
78 typename MatrixOrdinal,
79 typename MatrixMemory,
81 typename InputStorage,
83 typename OutputStorage,
91 Kokkos::View< Sacado::MP::Vector<InputStorage>*,
93 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
96 #ifdef KOKKOS_ENABLE_CUDA
97 , typename std::enable_if<
98 !std::is_same<MatrixDevice,Kokkos::Cuda>::value >::type
139 KOKKOS_INLINE_FUNCTION
143 const size_type iEntryBegin = m_A.graph.row_map[iRow];
144 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
146 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
147 size_type iCol = m_A.graph.entries(iEntry);
148 sum += m_A.values(iEntry) * m_x(iCol);
150 m_update( m_y(iRow), sum );
158 const size_type row_count = A.graph.row_map.extent(0)-1;
159 Kokkos::parallel_for( row_count,
MPMultiply(A,x,y,update) );
170 template <
typename MatrixDevice,
171 typename MatrixStorage,
172 typename MatrixOrdinal,
173 typename MatrixMemory,
175 typename InputStorage,
177 typename OutputStorage,
178 typename ... OutputP,
185 Kokkos::View< Sacado::MP::Vector<InputStorage>**,
187 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
190 #ifdef KOKKOS_ENABLE_CUDA
191 , typename std::enable_if<
192 !std::is_same<MatrixDevice,Kokkos::Cuda>::value >::type
232 KOKKOS_INLINE_FUNCTION
238 for (
size_type col=0; col<num_col; ++col) {
240 const size_type iEntryBegin = m_A.graph.row_map[iRow];
241 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
243 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
244 size_type iCol = m_A.graph.entries(iEntry);
245 sum += m_A.values(iEntry) * m_x(iCol,col);
247 m_update( m_y(iRow,col), sum );
258 const size_type row_count = A.graph.row_map.extent(0)-1;
259 Kokkos::parallel_for( row_count,
MPMultiply(A,x,y,update) );
272 template <
typename MatrixDevice,
273 typename MatrixStorage,
274 typename MatrixOrdinal,
275 typename MatrixMemory,
277 typename InputStorage,
279 typename OutputStorage,
280 typename ... OutputP>
286 Kokkos::View< Sacado::MP::Vector<InputStorage>*,
288 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
329 template <
typename MatrixDevice,
330 typename MatrixStorage,
331 typename MatrixOrdinal,
332 typename MatrixMemory,
334 typename InputStorage,
336 typename OutputStorage,
337 typename ... OutputP>
343 Kokkos::View< Sacado::MP::Vector<InputStorage>**,
345 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
381 namespace KokkosSparse {
383 template <
typename AlphaType,
389 typename ... OutputP>
390 typename std::enable_if<
398 const Kokkos::View< InputType, InputP... >& x,
400 const Kokkos::View< OutputType, OutputP... >& y,
403 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
404 typedef Kokkos::View< InputType, InputP... > InputVectorType;
405 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
409 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
414 "MV_Multiply not implemented for non-constant a or b");
417 value_type aa = Sacado::Value<AlphaType>::eval(a);
418 value_type bb = Sacado::Value<BetaType>::eval(b);
424 InputVectorType,OutputVectorType,UpdateType> multiply_type;
425 multiply_type::apply( A, x, y, UpdateType() );
431 InputVectorType,OutputVectorType,UpdateType> multiply_type;
432 multiply_type::apply( A, x, y, UpdateType(aa) );
440 InputVectorType,OutputVectorType,UpdateType> multiply_type;
441 multiply_type::apply( A, x, y, UpdateType() );
447 InputVectorType,OutputVectorType,UpdateType> multiply_type;
448 multiply_type::apply( A, x, y, UpdateType(aa) );
455 InputVectorType,OutputVectorType,UpdateType> multiply_type;
456 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
460 template <
typename AlphaType,
466 typename ... OutputP>
467 typename std::enable_if<
475 const Kokkos::View< InputType, InputP... >& x,
477 const Kokkos::View< OutputType, OutputP... >& y,
482 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
484 if (y.extent(1) == 1) {
485 auto y_1D = subview(y, Kokkos::ALL(), 0);
486 auto x_1D = subview(x, Kokkos::ALL(), 0);
487 spmv(mode, a, A, x_1D, b, y_1D, RANK_ONE());
490 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
491 typedef Kokkos::View< InputType, InputP... > InputVectorType;
492 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
496 "Stokhos spmv not implemented for non-constant a or b");
499 value_type aa = Sacado::Value<AlphaType>::eval(a);
500 value_type bb = Sacado::Value<BetaType>::eval(b);
506 InputVectorType,OutputVectorType,UpdateType> multiply_type;
507 multiply_type::apply( A, x, y, UpdateType() );
513 InputVectorType,OutputVectorType,UpdateType> multiply_type;
514 multiply_type::apply( A, x, y, UpdateType(aa) );
522 InputVectorType,OutputVectorType,UpdateType> multiply_type;
523 multiply_type::apply( A, x, y, UpdateType() );
529 InputVectorType,OutputVectorType,UpdateType> multiply_type;
530 multiply_type::apply( A, x, y, UpdateType(aa) );
537 InputVectorType,OutputVectorType,UpdateType> multiply_type;
538 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_INLINE_FUNCTION void operator()(const size_type iRow) const
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
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
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
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
Sacado::MP::Vector< InputStorage > InputVectorValue
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)
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
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)
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