10 #ifndef TPETRA_LOCALCRSMATRIXOPERATOR_DEF_HPP
11 #define TPETRA_LOCALCRSMATRIXOPERATOR_DEF_HPP
13 #include "Tpetra_LocalOperator.hpp"
15 #include "KokkosSparse.hpp"
16 #include "Teuchos_TestForException.hpp"
17 #include "Teuchos_OrdinalTraits.hpp"
21 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
22 LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::
23 LocalCrsMatrixOperator (
const std::shared_ptr<local_matrix_device_type>& A)
24 : A_ (A), have_A_cusparse(false)
26 const char tfecfFuncName[] =
"LocalCrsMatrixOperator: ";
27 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
28 (A_.get () ==
nullptr, std::invalid_argument,
29 "Input matrix A is null.");
32 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
33 LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::
34 LocalCrsMatrixOperator (
const std::shared_ptr<local_matrix_device_type>& A,
const ordinal_view_type& A_ordinal_rowptrs) :
36 A_cusparse(
"LocalCrsMatrixOperator_cuSPARSE", A->numRows(), A->numCols(), A->nnz(),
37 A->values, A_ordinal_rowptrs, A->graph.entries),
40 const char tfecfFuncName[] =
"LocalCrsMatrixOperator: ";
41 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
42 (A_.get () ==
nullptr, std::invalid_argument,
43 "Input matrix A is null.");
46 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
48 LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::
49 hasTransposeApply ()
const
54 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
56 LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::
57 apply (Kokkos::View<
const mv_scalar_type**, array_layout,
58 device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged> > X,
59 Kokkos::View<mv_scalar_type**, array_layout,
60 device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged> > Y,
61 const Teuchos::ETransp mode,
62 const mv_scalar_type alpha,
63 const mv_scalar_type beta)
const
65 const bool conjugate = (mode == Teuchos::CONJ_TRANS);
66 const bool transpose = (mode != Teuchos::NO_TRANS);
68 #ifdef HAVE_TPETRA_DEBUG
69 const char tfecfFuncName[] =
"apply: ";
71 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
72 (X.extent (1) != Y.extent (1), std::runtime_error,
73 "X.extent(1) = " << X.extent (1) <<
" != Y.extent(1) = "
74 << Y.extent (1) <<
".");
77 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
78 (X.data () == Y.data () && X.data () !=
nullptr,
79 std::runtime_error,
"X and Y may not alias one another.");
80 #endif // HAVE_TPETRA_DEBUG
82 const auto op = transpose ?
83 (conjugate ? KokkosSparse::ConjugateTranspose :
84 KokkosSparse::Transpose) : KokkosSparse::NoTranspose;
87 KokkosSparse::spmv (op, alpha, A_cusparse, X, beta, Y);
91 KokkosSparse::spmv (op, alpha, *A_, X, beta, Y);
97 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
101 Kokkos::View<
const mv_scalar_type**, array_layout,
102 device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged> > X,
103 Kokkos::View<mv_scalar_type**, array_layout,
104 device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged> > Y,
105 const Teuchos::ETransp mode,
106 const mv_scalar_type alpha,
107 const mv_scalar_type beta)
const
109 apply(X, Y, mode, alpha, beta);
112 template<
class MultiVectorScalar,
class MatrixScalar,
class Device>
113 const typename LocalCrsMatrixOperator<MultiVectorScalar, MatrixScalar, Device>::local_matrix_device_type&
131 #define TPETRA_LOCALCRSMATRIXOPERATOR_INSTANT(SC,NT) \
132 template class LocalCrsMatrixOperator< SC, SC, NT::device_type >;
136 #define TPETRA_LOCALCRSMATRIXOPERATOR_MIXED_INSTANT(SC,MATSC,LO,GO,NT) \
137 template class LocalCrsMatrixOperator< SC, MATSC, NT::device_type >;
139 #endif // TPETRA_LOCALCRSMATRIXOPERATOR_DEF_HPP
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.