42#ifndef KOKKOS_CRSMATRIX_MP_VECTOR_HPP
43#define KOKKOS_CRSMATRIX_MP_VECTOR_HPP
49#include "KokkosSparse_CrsMatrix.hpp"
51#include "KokkosSparse_spmv.hpp"
54#include "Kokkos_Core.hpp"
57#include "Teuchos_TestForException.hpp"
65template<
class T,
class = std::
void_t<> >
66struct const_type_impl {
71struct const_type_impl<T,
72 std::void_t<typename T::const_type> > {
73 using type =
typename T::const_type;
77using const_type_t =
typename const_type_impl<T>::type;
85template <
typename Matrix,
typename InputVector,
typename OutputVector,
87 typename Enabled =
void>
97template <
typename MatrixDevice,
98 typename MatrixStorage,
99 typename MatrixOrdinal,
100 typename MatrixMemory,
102 typename InputStorage,
104 typename OutputStorage,
105 typename ... OutputP,
112 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
114 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
117#ifdef KOKKOS_ENABLE_CUDA
118 , typename std::enable_if<
119 !std::is_same<typename MatrixDevice::execution_space,Kokkos::Cuda>::value >::type
134 typedef KokkosSparse::CrsMatrix<
const MatrixValue,
160 KOKKOS_INLINE_FUNCTION
167 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
169 sum +=
m_A.values(iEntry) *
m_x(iCol);
179 const size_type row_count = A.graph.row_map.extent(0)-1;
191template <
typename MatrixDevice,
192 typename MatrixStorage,
193 typename MatrixOrdinal,
194 typename MatrixMemory,
196 typename InputStorage,
198 typename OutputStorage,
199 typename ... OutputP,
206 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
208 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
211#ifdef KOKKOS_ENABLE_CUDA
212 , typename std::enable_if<
213 !std::is_same<typename MatrixDevice::execution_space,Kokkos::Cuda>::value >::type
226 typedef KokkosSparse::CrsMatrix<
const MatrixValue,
253 KOKKOS_INLINE_FUNCTION
259 for (
size_type col=0; col<num_col; ++col) {
264 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
266 sum +=
m_A.values(iEntry) *
m_x(iCol,col);
279 const size_type row_count = A.graph.row_map.extent(0)-1;
291template <
typename MatrixDevice,
292 typename MatrixStorage,
293 typename MatrixOrdinal,
294 typename MatrixMemory,
296 typename InputStorage,
298 typename OutputStorage,
299 typename ... OutputP,
306 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
308 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
355template <
typename MatrixDevice,
356 typename MatrixStorage,
357 typename MatrixOrdinal,
358 typename MatrixMemory,
360 typename InputStorage,
362 typename OutputStorage,
363 typename ... OutputP,
370 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
372 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
421template <
typename MatrixDevice,
422 typename MatrixStorage,
423 typename MatrixOrdinal,
424 typename MatrixMemory,
426 typename InputStorage,
428 typename OutputStorage,
429 typename ... OutputP>
435 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
437 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
478template <
typename MatrixDevice,
479 typename MatrixStorage,
480 typename MatrixOrdinal,
481 typename MatrixMemory,
483 typename InputStorage,
485 typename OutputStorage,
486 typename ... OutputP>
492 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
494 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
532template <
typename AlphaType,
538 typename ... OutputP>
539typename std::enable_if<
540 Kokkos::is_view_mp_vector< Kokkos::View< InputType, InputP... > >::value &&
541 Kokkos::is_view_mp_vector< Kokkos::View< OutputType, OutputP... > >::value
547 const Kokkos::View< InputType, InputP... >& x,
549 const Kokkos::View< OutputType, OutputP... >& y,
552 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
553 typedef Kokkos::View< InputType, InputP... > InputVectorType;
554 using input_vector_type = const_type_t<InputVectorType>;
555 typedef typename InputVectorType::array_type::non_const_value_type value_type;
559 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
564 "MV_Multiply not implemented for non-constant a or b");
567 value_type aa = Sacado::Value<AlphaType>::eval(a);
568 value_type bb = Sacado::Value<BetaType>::eval(b);
569 if (bb == value_type(0)) {
570 if (aa == value_type(1)) {
574 input_vector_type, OutputVectorType,
575 UpdateType> multiply_type;
576 multiply_type::apply( A, x, y, UpdateType() );
582 input_vector_type, OutputVectorType,
583 UpdateType> multiply_type;
584 multiply_type::apply( A, x, y, UpdateType(aa) );
587 else if (bb == value_type(1)) {
588 if (aa == value_type(1)) {
592 input_vector_type, OutputVectorType,
593 UpdateType> multiply_type;
594 multiply_type::apply( A, x, y, UpdateType() );
600 input_vector_type, OutputVectorType,
601 UpdateType> multiply_type;
602 multiply_type::apply( A, x, y, UpdateType(aa) );
609 input_vector_type, OutputVectorType,
610 UpdateType> multiply_type;
611 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
615template <
typename AlphaType,
621 typename ... OutputP>
622typename std::enable_if<
627 KokkosKernels::Experimental::Controls,
631 const Kokkos::View< InputType, InputP... >& x,
633 const Kokkos::View< OutputType, OutputP... >& y,
636 spmv(mode, a, A, x, b, y, RANK_ONE());
639template <
typename AlphaType,
645 typename ... OutputP>
646typename std::enable_if<
654 const Kokkos::View< InputType, InputP... >& x,
656 const Kokkos::View< OutputType, OutputP... >& y,
661 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
663 if (y.extent(1) == 1) {
664 auto y_1D = subview(y, Kokkos::ALL(), 0);
665 auto x_1D = subview(x, Kokkos::ALL(), 0);
666 spmv(mode, a, A, x_1D, b, y_1D, RANK_ONE());
669 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
670 typedef Kokkos::View< InputType, InputP... > InputVectorType;
671 using input_vector_type = const_type_t<InputVectorType>;
672 typedef typename InputVectorType::array_type::non_const_value_type value_type;
676 "Stokhos spmv not implemented for non-constant a or b");
679 value_type aa = Sacado::Value<AlphaType>::eval(a);
680 value_type bb = Sacado::Value<BetaType>::eval(b);
681 if (bb == value_type(0)) {
682 if (aa == value_type(1)) {
686 input_vector_type, OutputVectorType,
687 UpdateType> multiply_type;
688 multiply_type::apply( A, x, y, UpdateType() );
694 input_vector_type, OutputVectorType,
695 UpdateType> multiply_type;
696 multiply_type::apply( A, x, y, UpdateType(aa) );
699 else if (bb == value_type(1)) {
700 if (aa == value_type(1)) {
704 input_vector_type, OutputVectorType,
705 UpdateType> multiply_type;
706 multiply_type::apply( A, x, y, UpdateType() );
712 input_vector_type, OutputVectorType,
713 UpdateType> multiply_type;
714 multiply_type::apply( A, x, y, UpdateType(aa) );
721 input_vector_type, OutputVectorType,
722 UpdateType> multiply_type;
723 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
728template <
typename AlphaType,
734 typename ... OutputP>
735typename std::enable_if<
740 KokkosKernels::Experimental::Controls,
744 const Kokkos::View< InputType, InputP... >& x,
746 const Kokkos::View< OutputType, OutputP... >& y,
749 spmv(mode, a, A, x, b, y, RANK_TWO());
execution_space::size_type size_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
matrix_type::values_type matrix_values_type
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y)
Sacado::MP::Vector< OutputStorage > OutputVectorValue
MatrixDevice::execution_space execution_space
Sacado::MP::Vector< InputStorage > InputVectorValue
Sacado::MP::Vector< MatrixStorage > MatrixValue
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
matrix_type::values_type matrix_values_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)
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
Sacado::MP::Vector< MatrixStorage > MatrixValue
execution_space::size_type size_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Sacado::MP::Vector< InputStorage > InputVectorValue
MatrixDevice::execution_space execution_space
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Sacado::MP::Vector< InputStorage > InputVectorValue
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
execution_space::size_type size_type
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
matrix_type::const_type const_matrix_type
OutputVectorValue scalar_type
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)
Sacado::MP::Vector< MatrixStorage > MatrixValue
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
OutputVectorValue scalar_type
Sacado::MP::Vector< InputStorage > InputVectorValue
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
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
Sacado::MP::Vector< MatrixStorage > MatrixValue
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
execution_space::size_type size_type
matrix_type::const_type const_matrix_type
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
execution_space::size_type size_type
MatrixDevice::execution_space execution_space
const input_vector_type m_x
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
const output_vector_type m_y
const update_type m_update
Sacado::MP::Vector< InputStorage > InputVectorValue
Sacado::MP::Vector< MatrixStorage > MatrixValue
OutputVectorValue scalar_type
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)
KokkosSparse::CrsMatrix< const MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
Sacado::MP::Vector< OutputStorage > OutputVectorValue
Kokkos::View< OutputVectorValue *, OutputP... > output_vector_type
OutputVectorValue scalar_type
Sacado::MP::Vector< InputStorage > InputVectorValue
KokkosSparse::CrsMatrix< const MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
MPMultiply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
Kokkos::View< const InputVectorValue **, InputP... > input_vector_type
Kokkos::View< OutputVectorValue **, OutputP... > output_vector_type
MatrixDevice::execution_space execution_space
const output_vector_type m_y
static void apply(const matrix_type &A, const input_vector_type &x, const output_vector_type &y, const update_type &update)
Sacado::MP::Vector< OutputStorage > OutputVectorValue
execution_space::size_type size_type
const input_vector_type m_x
const update_type m_update
matrix_type::values_type matrix_values_type
Sacado::MP::Vector< MatrixStorage > MatrixValue
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)
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
Top-level namespace for Stokhos classes and functions.
void update(const ValueType &alpha, VectorType &x, const ValueType &beta, const VectorType &y)