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" 65 template<
class... Ts>
struct make_void {
typedef void type; };
67 using replace_me_with_void_t_in_cxx17 =
68 typename make_void<Ts...>::type;
70 template<
class T,
class = replace_me_with_
void_t_in_cxx17<> >
71 struct const_type_impl {
76 struct const_type_impl<T,
77 replace_me_with_void_t_in_cxx17<typename T::const_type> > {
78 using type =
typename T::const_type;
82 using const_type_t =
typename const_type_impl<T>::type;
90 template <
typename Matrix,
typename InputVector,
typename OutputVector,
91 typename Update = MultiplyAssign,
92 typename Enabled =
void>
102 template <
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;
196 template <
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;
296 template <
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>*,
360 template <
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>**,
426 template <
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>*,
483 template <
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>**,
537 template <
typename AlphaType,
543 typename ... OutputP>
544 typename 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);
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) );
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) );
620 template <
typename AlphaType,
626 typename ... OutputP>
627 typename 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());
644 template <
typename AlphaType,
650 typename ... OutputP>
651 typename 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);
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) );
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) );
733 template <
typename AlphaType,
739 typename ... OutputP>
740 typename 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
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
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
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)
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
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
MatrixDevice::execution_space execution_space
Sacado::MP::Vector< OutputStorage > OutputVectorValue
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
matrix_type::values_type matrix_values_type
matrix_type::values_type matrix_values_type
KokkosSparse::CrsMatrix< MatrixValue, MatrixOrdinal, MatrixDevice, MatrixMemory, MatrixSize > matrix_type
Top-level namespace for Stokhos classes and functions.
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)
KOKKOS_INLINE_FUNCTION void operator()(const size_type iRow) const
Sacado::MP::Vector< MatrixStorage > MatrixValue
Kokkos::View< const InputVectorValue *, InputP... > input_vector_type
execution_space::size_type size_type
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType ValueType * y
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