42#ifndef KOKKOS_CRSMATRIX_MP_VECTOR_HPP
43#define KOKKOS_CRSMATRIX_MP_VECTOR_HPP
47#include "KokkosSparse_CrsMatrix.hpp"
49#include "KokkosSparse_spmv.hpp"
52#include "Kokkos_Core.hpp"
55#include "Teuchos_TestForException.hpp"
65template<
class... Ts>
struct make_void {
typedef void type; };
67using replace_me_with_void_t_in_cxx17 =
68 typename make_void<Ts...>::type;
70template<
class T,
class = replace_me_with_
void_t_in_cxx17<> >
71struct const_type_impl {
76struct const_type_impl<T,
77 replace_me_with_void_t_in_cxx17<typename T::const_type> > {
78 using type =
typename T::const_type;
82using const_type_t =
typename const_type_impl<T>::type;
90template <
typename Matrix,
typename InputVector,
typename OutputVector,
91 typename Update = MultiplyAssign,
92 typename Enabled =
void>
102template <
typename MatrixDevice,
103 typename MatrixStorage,
104 typename MatrixOrdinal,
105 typename MatrixMemory,
107 typename InputStorage,
109 typename OutputStorage,
110 typename ... OutputP,
117 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
119 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
122#ifdef KOKKOS_ENABLE_CUDA
123 , typename std::enable_if<
124 !std::is_same<typename MatrixDevice::execution_space,Kokkos::Cuda>::value >::type
139 typedef KokkosSparse::CrsMatrix<
const MatrixValue,
165 KOKKOS_INLINE_FUNCTION
169 const size_type iEntryBegin = m_A.graph.row_map[iRow];
170 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
172 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
173 size_type iCol = m_A.graph.entries(iEntry);
174 sum += m_A.values(iEntry) * m_x(iCol);
176 m_update( m_y(iRow), sum );
184 const size_type row_count = A.graph.row_map.extent(0)-1;
196template <
typename MatrixDevice,
197 typename MatrixStorage,
198 typename MatrixOrdinal,
199 typename MatrixMemory,
201 typename InputStorage,
203 typename OutputStorage,
204 typename ... OutputP,
211 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
213 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
216#ifdef KOKKOS_ENABLE_CUDA
217 , typename std::enable_if<
218 !std::is_same<typename MatrixDevice::execution_space,Kokkos::Cuda>::value >::type
231 typedef KokkosSparse::CrsMatrix<
const MatrixValue,
258 KOKKOS_INLINE_FUNCTION
264 for (
size_type col=0; col<num_col; ++col) {
266 const size_type iEntryBegin = m_A.graph.row_map[iRow];
267 const size_type iEntryEnd = m_A.graph.row_map[iRow+1];
269 for (
size_type iEntry = iEntryBegin; iEntry < iEntryEnd; ++iEntry) {
270 size_type iCol = m_A.graph.entries(iEntry);
271 sum += m_A.values(iEntry) * m_x(iCol,col);
273 m_update( m_y(iRow,col), sum );
284 const size_type row_count = A.graph.row_map.extent(0)-1;
296template <
typename MatrixDevice,
297 typename MatrixStorage,
298 typename MatrixOrdinal,
299 typename MatrixMemory,
301 typename InputStorage,
303 typename OutputStorage,
304 typename ... OutputP,
311 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
313 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
360template <
typename MatrixDevice,
361 typename MatrixStorage,
362 typename MatrixOrdinal,
363 typename MatrixMemory,
365 typename InputStorage,
367 typename OutputStorage,
368 typename ... OutputP,
375 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
377 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
426template <
typename MatrixDevice,
427 typename MatrixStorage,
428 typename MatrixOrdinal,
429 typename MatrixMemory,
431 typename InputStorage,
433 typename OutputStorage,
434 typename ... OutputP>
440 Kokkos::View< const Sacado::MP::Vector<InputStorage>*,
442 Kokkos::View< Sacado::MP::Vector<OutputStorage>*,
483template <
typename MatrixDevice,
484 typename MatrixStorage,
485 typename MatrixOrdinal,
486 typename MatrixMemory,
488 typename InputStorage,
490 typename OutputStorage,
491 typename ... OutputP>
497 Kokkos::View< const Sacado::MP::Vector<InputStorage>**,
499 Kokkos::View< Sacado::MP::Vector<OutputStorage>**,
537template <
typename AlphaType,
543 typename ... OutputP>
544typename std::enable_if<
552 const Kokkos::View< InputType, InputP... >& x,
554 const Kokkos::View< OutputType, OutputP... >& y,
557 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
558 typedef Kokkos::View< InputType, InputP... > InputVectorType;
559 using input_vector_type = const_type_t<InputVectorType>;
560 typedef typename InputVectorType::array_type::non_const_value_type value_type;
564 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
569 "MV_Multiply not implemented for non-constant a or b");
572 value_type aa = Sacado::Value<AlphaType>::eval(a);
573 value_type bb = Sacado::Value<BetaType>::eval(b);
574 if (bb == value_type(0)) {
575 if (aa == value_type(1)) {
579 input_vector_type, OutputVectorType,
580 UpdateType> multiply_type;
581 multiply_type::apply( A, x, y, UpdateType() );
587 input_vector_type, OutputVectorType,
588 UpdateType> multiply_type;
589 multiply_type::apply( A, x, y, UpdateType(aa) );
592 else if (bb == value_type(1)) {
593 if (aa == value_type(1)) {
597 input_vector_type, OutputVectorType,
598 UpdateType> multiply_type;
599 multiply_type::apply( A, x, y, UpdateType() );
605 input_vector_type, OutputVectorType,
606 UpdateType> multiply_type;
607 multiply_type::apply( A, x, y, UpdateType(aa) );
614 input_vector_type, OutputVectorType,
615 UpdateType> multiply_type;
616 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
620template <
typename AlphaType,
626 typename ... OutputP>
627typename std::enable_if<
632 KokkosKernels::Experimental::Controls,
636 const Kokkos::View< InputType, InputP... >& x,
638 const Kokkos::View< OutputType, OutputP... >& y,
641 spmv(mode, a, A, x, b, y, RANK_ONE());
644template <
typename AlphaType,
650 typename ... OutputP>
651typename std::enable_if<
659 const Kokkos::View< InputType, InputP... >& x,
661 const Kokkos::View< OutputType, OutputP... >& y,
666 "Stokhos spmv not implemented for transposed or conjugated matrix-vector multiplies");
668 if (y.extent(1) == 1) {
669 auto y_1D = subview(y, Kokkos::ALL(), 0);
670 auto x_1D = subview(x, Kokkos::ALL(), 0);
671 spmv(mode, a, A, x_1D, b, y_1D, RANK_ONE());
674 typedef Kokkos::View< OutputType, OutputP... > OutputVectorType;
675 typedef Kokkos::View< InputType, InputP... > InputVectorType;
676 using input_vector_type = const_type_t<InputVectorType>;
677 typedef typename InputVectorType::array_type::non_const_value_type value_type;
681 "Stokhos spmv not implemented for non-constant a or b");
684 value_type aa = Sacado::Value<AlphaType>::eval(a);
685 value_type bb = Sacado::Value<BetaType>::eval(b);
686 if (bb == value_type(0)) {
687 if (aa == value_type(1)) {
691 input_vector_type, OutputVectorType,
692 UpdateType> multiply_type;
693 multiply_type::apply( A, x, y, UpdateType() );
699 input_vector_type, OutputVectorType,
700 UpdateType> multiply_type;
701 multiply_type::apply( A, x, y, UpdateType(aa) );
704 else if (bb == value_type(1)) {
705 if (aa == value_type(1)) {
709 input_vector_type, OutputVectorType,
710 UpdateType> multiply_type;
711 multiply_type::apply( A, x, y, UpdateType() );
717 input_vector_type, OutputVectorType,
718 UpdateType> multiply_type;
719 multiply_type::apply( A, x, y, UpdateType(aa) );
726 input_vector_type, OutputVectorType,
727 UpdateType> multiply_type;
728 multiply_type::apply( A, x, y, UpdateType(aa,bb) );
733template <
typename AlphaType,
739 typename ... OutputP>
740typename std::enable_if<
745 KokkosKernels::Experimental::Controls,
749 const Kokkos::View< InputType, InputP... >& x,
751 const Kokkos::View< OutputType, OutputP... >& y,
754 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)