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<typename MatrixDevice::execution_space,Kokkos::Cuda>::value >::type
138 typedef KokkosSparse::CrsMatrix<
const MatrixValue,
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<typename MatrixDevice::execution_space,Kokkos::Cuda>::value >::type
230 typedef KokkosSparse::CrsMatrix<
const MatrixValue,
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) );
295 template <
typename MatrixDevice,
296 typename MatrixStorage,
297 typename MatrixOrdinal,
298 typename MatrixMemory,
300 typename InputStorage,
302 typename OutputStorage,
303 typename ... OutputP,
310 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
312 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
359 template <
typename MatrixDevice,
360 typename MatrixStorage,
361 typename MatrixOrdinal,
362 typename MatrixMemory,
364 typename InputStorage,
366 typename OutputStorage,
367 typename ... OutputP,
374 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
376 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
425 template <
typename MatrixDevice,
426 typename MatrixStorage,
427 typename MatrixOrdinal,
428 typename MatrixMemory,
430 typename InputStorage,
432 typename OutputStorage,
433 typename ... OutputP>
439 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
441 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
482 template <
typename MatrixDevice,
483 typename MatrixStorage,
484 typename MatrixOrdinal,
485 typename MatrixMemory,
487 typename InputStorage,
489 typename OutputStorage,
490 typename ... OutputP>
496 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
498 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
534 namespace KokkosSparse {
536 template <
typename AlphaType,
542 typename ... OutputP>
543 typename std::enable_if<
551 const Kokkos::View< InputType, InputP... >& x,
553 const Kokkos::View< OutputType, OutputP... >& y,
556 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
557 typedef Kokkos::View< InputType, InputP... > InputVectorType;
558 using input_vector_type = const_type_t<InputVectorType>;
559 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
563 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
568 "MV_Multiply not implemented for non-constant a or b");
571 value_type aa = Sacado::Value<AlphaType>::eval(a);
572 value_type bb = Sacado::Value<BetaType>::eval(b);
578 input_vector_type, OutputVectorType,
579 UpdateType> multiply_type;
580 multiply_type::apply( A, x, y, UpdateType() );
586 input_vector_type, OutputVectorType,
587 UpdateType> multiply_type;
588 multiply_type::apply( A, x, y, UpdateType(aa) );
596 input_vector_type, OutputVectorType,
597 UpdateType> multiply_type;
598 multiply_type::apply( A, x, y, UpdateType() );
604 input_vector_type, OutputVectorType,
605 UpdateType> multiply_type;
606 multiply_type::apply( A, x, y, UpdateType(aa) );
613 input_vector_type, OutputVectorType,
614 UpdateType> multiply_type;
615 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
619 template <
typename AlphaType,
625 typename ... OutputP>
626 typename std::enable_if<
631 KokkosKernels::Experimental::Controls,
635 const Kokkos::View< InputType, InputP... >& x,
637 const Kokkos::View< OutputType, OutputP... >& y,
640 spmv(mode, a, A, x, b, y, RANK_ONE());
643 template <
typename AlphaType,
649 typename ... OutputP>
650 typename std::enable_if<
658 const Kokkos::View< InputType, InputP... >& x,
660 const Kokkos::View< OutputType, OutputP... >& y,
665 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
667 if (y.extent(1) == 1) {
668 auto y_1D = subview(y, Kokkos::ALL(), 0);
669 auto x_1D = subview(x, Kokkos::ALL(), 0);
670 spmv(mode, a, A, x_1D, b, y_1D, RANK_ONE());
673 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
674 typedef Kokkos::View< InputType, InputP... > InputVectorType;
675 using input_vector_type = const_type_t<InputVectorType>;
676 typedef typename InputVectorType::array_type::non_const_value_type
value_type;
680 "Stokhos spmv not implemented for non-constant a or b");
683 value_type aa = Sacado::Value<AlphaType>::eval(a);
684 value_type bb = Sacado::Value<BetaType>::eval(b);
690 input_vector_type, OutputVectorType,
691 UpdateType> multiply_type;
692 multiply_type::apply( A, x, y, UpdateType() );
698 input_vector_type, OutputVectorType,
699 UpdateType> multiply_type;
700 multiply_type::apply( A, x, y, UpdateType(aa) );
708 input_vector_type, OutputVectorType,
709 UpdateType> multiply_type;
710 multiply_type::apply( A, x, y, UpdateType() );
716 input_vector_type, OutputVectorType,
717 UpdateType> multiply_type;
718 multiply_type::apply( A, x, y, UpdateType(aa) );
725 input_vector_type, OutputVectorType,
726 UpdateType> multiply_type;
727 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
732 template <
typename AlphaType,
738 typename ... OutputP>
739 typename std::enable_if<
744 KokkosKernels::Experimental::Controls,
748 const Kokkos::View< InputType, InputP... >& x,
750 const Kokkos::View< OutputType, OutputP... >& y,
753 spmv(mode, a, A, x, b, y, RANK_TWO());
execution_space::size_type size_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Sacado::MP::Vector< InputStorage > InputVectorValue
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
const output_vector_type m_y
MPMultiply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
OutputVectorValue scalar_type
Sacado::MP::Vector< InputStorage > InputVectorValue
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
Sacado::MP::Vector< OutputStorage > OutputVectorValue
MatrixDevice::execution_space execution_space
Sacado::MP::Vector< MatrixStorage > MatrixValue
matrix_type::const_type const_matrix_type
Kokkos::DefaultExecutionSpace execution_space
Sacado::MP::Vector< MatrixStorage > MatrixValue
matrix_type::const_type const_matrix_type
execution_space::size_type size_type
MatrixDevice::execution_space execution_space
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
matrix_type::values_type matrix_values_type
Sacado::MP::Vector< MatrixStorage > MatrixValue
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
Sacado::MP::Vector< MatrixStorage > MatrixValue
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
MatrixDevice::execution_space execution_space
Sacado::MP::Vector< OutputStorage > OutputVectorValue
matrix_type::values_type matrix_values_type
matrix_type::values_type matrix_values_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
Sacado::MP::Vector< InputStorage > InputVectorValue
Sacado::MP::Vector< InputStorage > InputVectorValue
MatrixDevice::execution_space execution_space
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
execution_space::size_type size_type
Sacado::MP::Vector< InputStorage > InputVectorValue
const update_type m_update
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
Sacado::MP::Vector< InputStorage > InputVectorValue
KokkosSparse::CrsMatrix< const MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
OutputVectorValue scalar_type
OutputVectorValue scalar_type
KokkosSparse::CrsMatrix< const MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
execution_space::size_type size_type
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
Sacado::MP::Vector< MatrixStorage > MatrixValue
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
const input_vector_type m_x
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
const input_vector_type m_x
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
OutputVectorValue scalar_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
MatrixDevice::execution_space execution_space
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
const update_type m_update
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
Kokkos::View< const InputVectorValue *, InputP... > input_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)
Sacado::MP::Vector< MatrixStorage > MatrixValue
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
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)
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)
MatrixDevice::execution_space execution_space
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
Sacado::MP::Vector< OutputStorage > OutputVectorValue