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<
class... Ts>
struct make_void {
typedef void type; };
66 using replace_me_with_void_t_in_cxx17 =
67 typename make_void<Ts...>::type;
69 template<
class T,
class = replace_me_with_
void_t_in_cxx17<> >
70 struct const_type_impl {
75 struct const_type_impl<T,
76 replace_me_with_void_t_in_cxx17<typename T::const_type> > {
77 using type =
typename T::const_type;
81 using const_type_t =
typename const_type_impl<T>::type;
89 template <
typename Matrix,
typename InputVector,
typename OutputVector,
90 typename Update = MultiplyAssign,
91 typename Enabled =
void>
101 template <
typename MatrixDevice,
102 typename MatrixStorage,
103 typename MatrixOrdinal,
104 typename MatrixMemory,
106 typename InputStorage,
108 typename OutputStorage,
109 typename ... OutputP,
116 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
118 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
121 #ifdef KOKKOS_ENABLE_CUDA
122 , typename std::enable_if<
123 !std::is_same<MatrixDevice,Kokkos::Cuda>::value >::type
164 KOKKOS_INLINE_FUNCTION
168 const size_type iEntryBegin = m_A.graph.row_map[iRow];
169 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
171 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
172 size_type iCol = m_A.graph.entries(iEntry);
173 sum += m_A.values(iEntry) * m_x(iCol);
175 m_update( m_y(iRow), sum );
183 const size_type row_count = A.graph.row_map.extent(0)-1;
184 Kokkos::parallel_for( row_count,
MPMultiply(A,x,y,update) );
195 template <
typename MatrixDevice,
196 typename MatrixStorage,
197 typename MatrixOrdinal,
198 typename MatrixMemory,
200 typename InputStorage,
202 typename OutputStorage,
203 typename ... OutputP,
210 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
212 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
215 #ifdef KOKKOS_ENABLE_CUDA
216 , typename std::enable_if<
217 !std::is_same<MatrixDevice,Kokkos::Cuda>::value >::type
257 KOKKOS_INLINE_FUNCTION
263 for (
size_type col=0; col<num_col; ++col) {
265 const size_type iEntryBegin = m_A.graph.row_map[iRow];
266 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
268 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
269 size_type iCol = m_A.graph.entries(iEntry);
270 sum += m_A.values(iEntry) * m_x(iCol,col);
272 m_update( m_y(iRow,col), sum );
283 const size_type row_count = A.graph.row_map.extent(0)-1;
284 Kokkos::parallel_for( row_count,
MPMultiply(A,x,y,update) );
297 template <
typename MatrixDevice,
298 typename MatrixStorage,
299 typename MatrixOrdinal,
300 typename MatrixMemory,
302 typename InputStorage,
304 typename OutputStorage,
305 typename ... OutputP>
311 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
313 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
354 template <
typename MatrixDevice,
355 typename MatrixStorage,
356 typename MatrixOrdinal,
357 typename MatrixMemory,
359 typename InputStorage,
361 typename OutputStorage,
362 typename ... OutputP>
368 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
370 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
406 namespace KokkosSparse {
408 template <
typename AlphaType,
414 typename ... OutputP>
415 typename std::enable_if<
423 const Kokkos::View< InputType, InputP... >& x,
425 const Kokkos::View< OutputType, OutputP... >& y,
428 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
429 typedef Kokkos::View< InputType, InputP... > InputVectorType;
430 using input_vector_type = const_type_t<InputVectorType>;
431 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
435 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
440 "MV_Multiply not implemented for non-constant a or b");
443 value_type aa = Sacado::Value<AlphaType>::eval(a);
444 value_type bb = Sacado::Value<BetaType>::eval(b);
450 input_vector_type, OutputVectorType,
451 UpdateType> multiply_type;
452 multiply_type::apply( A, x, y, UpdateType() );
458 input_vector_type, OutputVectorType,
459 UpdateType> multiply_type;
460 multiply_type::apply( A, x, y, UpdateType(aa) );
468 input_vector_type, OutputVectorType,
469 UpdateType> multiply_type;
470 multiply_type::apply( A, x, y, UpdateType() );
476 input_vector_type, OutputVectorType,
477 UpdateType> multiply_type;
478 multiply_type::apply( A, x, y, UpdateType(aa) );
485 input_vector_type, OutputVectorType,
486 UpdateType> multiply_type;
487 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
491 template <
typename AlphaType,
497 typename ... OutputP>
498 typename std::enable_if<
506 const Kokkos::View< InputType, InputP... >& x,
508 const Kokkos::View< OutputType, OutputP... >& y,
513 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
515 if (y.extent(1) == 1) {
516 auto y_1D = subview(y, Kokkos::ALL(), 0);
517 auto x_1D = subview(x, Kokkos::ALL(), 0);
518 spmv(mode, a, A, x_1D, b, y_1D, RANK_ONE());
521 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
522 typedef Kokkos::View< InputType, InputP... > InputVectorType;
523 using input_vector_type = const_type_t<InputVectorType>;
524 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
528 "Stokhos spmv not implemented for non-constant a or b");
531 value_type aa = Sacado::Value<AlphaType>::eval(a);
532 value_type bb = Sacado::Value<BetaType>::eval(b);
538 input_vector_type, OutputVectorType,
539 UpdateType> multiply_type;
540 multiply_type::apply( A, x, y, UpdateType() );
546 input_vector_type, OutputVectorType,
547 UpdateType> multiply_type;
548 multiply_type::apply( A, x, y, UpdateType(aa) );
556 input_vector_type, OutputVectorType,
557 UpdateType> multiply_type;
558 multiply_type::apply( A, x, y, UpdateType() );
564 input_vector_type, OutputVectorType,
565 UpdateType> multiply_type;
566 multiply_type::apply( A, x, y, UpdateType(aa) );
573 input_vector_type, OutputVectorType,
574 UpdateType> multiply_type;
575 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
execution_space::size_type size_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Sacado::MP::Vector< OutputStorage > OutputVectorValue
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
MatrixDevice execution_space
Sacado::MP::Vector< InputStorage > InputVectorValue
const output_vector_type m_y
Sacado::MP::Vector< OutputStorage > OutputVectorValue
MatrixDevice execution_space
MatrixDevice execution_space
Sacado::MP::Vector< MatrixStorage > MatrixValue
Sacado::MP::Vector< MatrixStorage > MatrixValue
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
MPMultiply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
matrix_type::values_type matrix_values_type
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
const input_vector_type m_x
Sacado::MP::Vector< MatrixStorage > MatrixValue
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
MPMultiply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
matrix_type::values_type matrix_values_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
Sacado::MP::Vector< InputStorage > InputVectorValue
Sacado::MP::Vector< InputStorage > InputVectorValue
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
const input_vector_type m_x
execution_space::size_type size_type
Sacado::MP::Vector< InputStorage > InputVectorValue
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
MatrixDevice execution_space
OutputVectorValue scalar_type
execution_space::size_type size_type
Sacado::MP::Vector< MatrixStorage > MatrixValue
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
const update_type m_update
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
OutputVectorValue scalar_type
matrix_type::values_type matrix_values_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
const output_vector_type m_y
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
execution_space::size_type size_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)
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)
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)