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;
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;
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>**,
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) );