40 #ifndef TPETRA_LOCALCRSMATRIXOPERATOR_DEF_HPP
41 #define TPETRA_LOCALCRSMATRIXOPERATOR_DEF_HPP
43 #include "Tpetra_LocalOperator.hpp"
45 #include "KokkosSparse.hpp"
46 #include "Teuchos_TestForException.hpp"
50 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
51 LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::
52 LocalCrsMatrixOperator (
const std::shared_ptr<local_matrix_type>& A)
55 const char tfecfFuncName[] =
"LocalCrsMatrixOperator: ";
56 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
57 (A_.get () ==
nullptr, std::invalid_argument,
58 "Input matrix A is null.");
61 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
63 LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::
64 hasTransposeApply ()
const
69 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
71 LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::
72 apply (Kokkos::View<
const mv_scalar_type**, array_layout,
73 device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged> > X,
74 Kokkos::View<mv_scalar_type**, array_layout,
75 device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged> > Y,
76 const Teuchos::ETransp mode,
77 const mv_scalar_type alpha,
78 const mv_scalar_type beta)
const
80 const bool conjugate = (mode == Teuchos::CONJ_TRANS);
81 const bool transpose = (mode != Teuchos::NO_TRANS);
83 #ifdef HAVE_TPETRA_DEBUG
84 const char tfecfFuncName[] =
"apply: ";
86 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
87 (X.extent (1) != Y.extent (1), std::runtime_error,
88 "X.extent(1) = " << X.extent (1) <<
" != Y.extent(1) = "
89 << Y.extent (1) <<
".");
92 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
93 (X.data () == Y.data () && X.data () !=
nullptr,
94 std::runtime_error,
"X and Y may not alias one another.");
95 #endif // HAVE_TPETRA_DEBUG
97 const auto op = transpose ?
98 (conjugate ? KokkosSparse::ConjugateTranspose :
99 KokkosSparse::Transpose) : KokkosSparse::NoTranspose;
100 KokkosSparse::spmv (op, alpha, *A_, X, beta, Y);
105 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
109 Kokkos::View<
const mv_scalar_type**, array_layout,
110 device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged> > X,
111 Kokkos::View<mv_scalar_type**, array_layout,
112 device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged> > Y,
113 const Teuchos::ETransp mode,
114 const mv_scalar_type alpha,
115 const mv_scalar_type beta)
const
117 const bool conjugate = (mode == Teuchos::CONJ_TRANS);
118 const bool transpose = (mode != Teuchos::NO_TRANS);
120 #ifdef HAVE_TPETRA_DEBUG
121 const char tfecfFuncName[] =
"applyLoadBalanced: ";
123 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
124 (X.extent (1) != Y.extent (1), std::runtime_error,
125 "X.extent(1) = " << X.extent (1) <<
" != Y.extent(1) = "
126 << Y.extent (1) <<
".");
129 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
130 (X.data () == Y.data () && X.data () !=
nullptr,
131 std::runtime_error,
"X and Y may not alias one another.");
132 #endif // HAVE_TPETRA_DEBUG
134 const auto op = transpose ?
135 (conjugate ? KokkosSparse::ConjugateTranspose :
136 KokkosSparse::Transpose) : KokkosSparse::NoTranspose;
147 KokkosKernels::Experimental::Controls controls;
148 controls.setParameter(
"algorithm",
"merge");
150 for(
size_t vec = 0; vec < X.extent(1); vec++)
152 KokkosSparse::spmv (controls, op,
153 alpha, *A_, Kokkos::subview(X, Kokkos::ALL(), vec),
154 beta, Kokkos::subview(Y, Kokkos::ALL(), vec));
160 KokkosSparse::spmv (op, alpha, *A_, X, beta, Y);
164 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
165 const typename LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::local_matrix_type&
183 #define TPETRA_LOCALCRSMATRIXOPERATOR_INSTANT(SC,NT) \
184 template class LocalCrsMatrixOperator< SC, SC, NT::device_type >;
186 #endif // TPETRA_LOCALCRSMATRIXOPERATOR_DEF_HPP
static bool useMergePathMultiVector()
Whether to use the cuSPARSE merge path algorithm to perform sparse matrix-multivector products...
Abstract interface for local operators (e.g., matrices and preconditioners).
void applyImbalancedRows(Kokkos::View< const mv_scalar_type **, array_layout, device_type, Kokkos::MemoryTraits< Kokkos::Unmanaged > > X, Kokkos::View< mv_scalar_type **, array_layout, device_type, Kokkos::MemoryTraits< Kokkos::Unmanaged > > Y, const Teuchos::ETransp mode, const mv_scalar_type alpha, const mv_scalar_type beta) const
Same behavior as apply() above, except give KokkosKernels a hint to use an SPMV algorithm that can ef...
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.