10#ifndef TPETRA_LEFTANDORRIGHTSCALECRSMATRIX_DEF_HPP
11#define TPETRA_LEFTANDORRIGHTSCALECRSMATRIX_DEF_HPP
20#include "Tpetra_CrsMatrix.hpp"
21#include "Tpetra_Vector.hpp"
25#include "Teuchos_TestForException.hpp"
29template <
class SC,
class LO,
class GO,
class NT>
32 const typename KokkosKernels::ArithTraits<SC>::mag_type*,
33 typename NT::device_type>& rowScalingFactors,
35 const typename KokkosKernels::ArithTraits<SC>::mag_type*,
36 typename NT::device_type>& colScalingFactors,
38 const bool rightScale,
39 const bool assumeSymmetric,
41 if (!leftScale && !rightScale) {
46 if (!A_fillComplete_on_input) {
54 static_cast<LO
>(A.
getRowMap()->getLocalNumElements());
55 TEUCHOS_TEST_FOR_EXCEPTION(A_lcl.numRows() != lclNumRows, std::invalid_argument,
56 "leftAndOrRightScaleCrsMatrix: Local matrix is not valid. "
57 "This means that A was not created with a local matrix, "
58 "and that fillComplete has never yet been called on A before. "
59 "Please call fillComplete on A at least once first "
60 "before calling this method.");
65 const bool divide = scaling == SCALING_DIVIDE;
79 if (A_fillComplete_on_input) {
80 Teuchos::RCP<Teuchos::ParameterList> params = Teuchos::parameterList();
81 params->set(
"No Nonlocal Changes",
true);
86template <
class SC,
class LO,
class GO,
class NT>
89 typename KokkosKernels::ArithTraits<SC>::mag_type,
90 LO, GO, NT>& rowScalingFactors,
92 typename KokkosKernels::ArithTraits<SC>::mag_type,
93 LO, GO, NT>& colScalingFactors,
95 const bool rightScale,
96 const bool assumeSymmetric,
99 using dev_memory_space =
typename device_type::memory_space;
100 using mag_type =
typename KokkosKernels::ArithTraits<SC>::mag_type;
101 const char prefix[] =
"leftAndOrRightScaleCrsMatrix: ";
104 Kokkos::View<const mag_type*, device_type> row_lcl;
105 Kokkos::View<const mag_type*, device_type> col_lcl;
108 const bool same = rowScalingFactors.getMap()->isSameAs(*(A.
getRowMap()));
109 TEUCHOS_TEST_FOR_EXCEPTION(!same, std::invalid_argument, prefix <<
"rowScalingFactors's Map "
110 "must be the same as the CrsMatrix's row Map. If you see this "
111 "message, it's likely that you are using a range Map Vector and that "
112 "the CrsMatrix's row Map is overlapping.");
117 auto row_lcl_2d = rowScalingFactors.template getLocalView<dev_memory_space>(Access::ReadOnly);
118 row_lcl = Kokkos::subview(row_lcl_2d, Kokkos::ALL(), 0);
122 const bool same = colScalingFactors.getMap()->isSameAs(*(A.
getColMap()));
123 TEUCHOS_TEST_FOR_EXCEPTION(!same, std::invalid_argument, prefix <<
"colScalingFactors's Map "
124 "must be the same as the CrsMatrix's column Map. If you see this "
125 "message, it's likely that you are using a domain Map Vector.");
130 auto col_lcl_2d = colScalingFactors.template getLocalView<dev_memory_space>(Access::ReadOnly);
131 col_lcl = Kokkos::subview(col_lcl_2d, Kokkos::ALL(), 0);
135 assumeSymmetric, scaling);
146#define TPETRA_LEFTANDORRIGHTSCALECRSMATRIX_INSTANT(SC, LO, GO, NT) \
148 leftAndOrRightScaleCrsMatrix( \
149 Tpetra::CrsMatrix<SC, LO, GO, NT>& A, \
150 const Kokkos::View< \
151 const KokkosKernels::ArithTraits<SC>::mag_type*, \
152 NT::device_type>& rowScalingFactors, \
153 const Kokkos::View< \
154 const KokkosKernels::ArithTraits<SC>::mag_type*, \
155 NT::device_type>& colScalingFactors, \
156 const bool leftScale, \
157 const bool rightScale, \
158 const bool assumeSymmetric, \
159 const EScaling scaling); \
162 leftAndOrRightScaleCrsMatrix( \
163 Tpetra::CrsMatrix<SC, LO, GO, NT>& A, \
164 const Tpetra::Vector<KokkosKernels::ArithTraits<SC>::mag_type, LO, GO, NT>& rowScalingFactors, \
165 const Tpetra::Vector<KokkosKernels::ArithTraits<SC>::mag_type, LO, GO, NT>& colScalingFactors, \
166 const bool leftScale, \
167 const bool rightScale, \
168 const bool assumeSymmetric, \
169 const EScaling scaling);
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration and definition of Tpetra::Details::leftScaleLocalCrsMatrix.
Declaration and definition of Tpetra::Details::rightScaleLocalCrsMatrix.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this matrix.
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this matrix.
TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type getLocalMatrixDevice() const
The local sparse matrix.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
void fillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Tell the matrix that you are done changing its structure or values, and that you are ready to do comp...
bool isFillComplete() const override
Whether the matrix is fill complete.
Teuchos::RCP< const map_type > getRowMap() const override
The Map that describes the row distribution in this matrix.
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Resume operations that may change the values or structure of the matrix.
static bool debug()
Whether Tpetra is in debug mode.
A distributed dense vector.
void leftScaleLocalCrsMatrix(const LocalSparseMatrixType &A_lcl, const ScalingFactorsViewType &scalingFactors, const bool assumeSymmetric, const bool divide=true)
Left-scale a KokkosSparse::CrsMatrix.
void rightScaleLocalCrsMatrix(const LocalSparseMatrixType &A_lcl, const ScalingFactorsViewType &scalingFactors, const bool assumeSymmetric, const bool divide=true)
Right-scale a KokkosSparse::CrsMatrix.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
EScaling
Whether "scaling" a matrix means multiplying or dividing its entries.
void leftAndOrRightScaleCrsMatrix(Tpetra::CrsMatrix< SC, LO, GO, NT > &A, const Kokkos::View< const typename KokkosKernels::ArithTraits< SC >::mag_type *, typename NT::device_type > &rowScalingFactors, const Kokkos::View< const typename KokkosKernels::ArithTraits< SC >::mag_type *, typename NT::device_type > &colScalingFactors, const bool leftScale, const bool rightScale, const bool assumeSymmetric, const EScaling scaling)
Left-scale and/or right-scale (in that order) the entries of the input Tpetra::CrsMatrix A.