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"
29 template<
class SC,
class LO,
class GO,
class NT>
33 const typename Kokkos::ArithTraits<SC>::mag_type*,
34 typename NT::device_type>& rowScalingFactors,
36 const typename Kokkos::ArithTraits<SC>::mag_type*,
37 typename NT::device_type>& colScalingFactors,
39 const bool rightScale,
40 const bool assumeSymmetric,
43 if (! leftScale && ! rightScale) {
48 if (! A_fillComplete_on_input) {
56 static_cast<LO
> (A.
getRowMap ()->getLocalNumElements ());
57 TEUCHOS_TEST_FOR_EXCEPTION
58 (A_lcl.numRows () != lclNumRows, std::invalid_argument,
59 "leftAndOrRightScaleCrsMatrix: Local matrix is not valid. "
60 "This means that A was not created with a local matrix, "
61 "and that fillComplete has never yet been called on A before. "
62 "Please call fillComplete on A at least once first "
63 "before calling this method.");
69 const bool divide = scaling == SCALING_DIVIDE;
83 if (A_fillComplete_on_input) {
84 Teuchos::RCP<Teuchos::ParameterList> params = Teuchos::parameterList ();
85 params->set (
"No Nonlocal Changes",
true);
90 template<
class SC,
class LO,
class GO,
class NT>
94 typename Kokkos::ArithTraits<SC>::mag_type,
95 LO, GO, NT>& rowScalingFactors,
97 typename Kokkos::ArithTraits<SC>::mag_type,
98 LO, GO, NT>& colScalingFactors,
100 const bool rightScale,
101 const bool assumeSymmetric,
104 using device_type =
typename NT::device_type;
105 using dev_memory_space =
typename device_type::memory_space;
106 using mag_type =
typename Kokkos::ArithTraits<SC>::mag_type;
107 const char prefix[] =
"leftAndOrRightScaleCrsMatrix: ";
110 Kokkos::View<const mag_type*, device_type> row_lcl;
111 Kokkos::View<const mag_type*, device_type> col_lcl;
114 const bool same = rowScalingFactors.getMap ()->isSameAs (* (A.
getRowMap ()));
115 TEUCHOS_TEST_FOR_EXCEPTION
116 (! same, std::invalid_argument, prefix <<
"rowScalingFactors's Map "
117 "must be the same as the CrsMatrix's row Map. If you see this "
118 "message, it's likely that you are using a range Map Vector and that "
119 "the CrsMatrix's row Map is overlapping.");
124 auto row_lcl_2d = rowScalingFactors.template getLocalView<dev_memory_space> (Access::ReadOnly);
125 row_lcl = Kokkos::subview (row_lcl_2d, Kokkos::ALL (), 0);
129 const bool same = colScalingFactors.getMap ()->isSameAs (* (A.
getColMap ()));
130 TEUCHOS_TEST_FOR_EXCEPTION
131 (! same, std::invalid_argument, prefix <<
"colScalingFactors's Map "
132 "must be the same as the CrsMatrix's column Map. If you see this "
133 "message, it's likely that you are using a domain Map Vector.");
138 auto col_lcl_2d = colScalingFactors.template getLocalView<dev_memory_space> (Access::ReadOnly);
139 col_lcl = Kokkos::subview (col_lcl_2d, Kokkos::ALL (), 0);
143 assumeSymmetric, scaling);
154 #define TPETRA_LEFTANDORRIGHTSCALECRSMATRIX_INSTANT(SC,LO,GO,NT) \
156 leftAndOrRightScaleCrsMatrix ( \
157 Tpetra::CrsMatrix<SC, LO, GO, NT>& A, \
158 const Kokkos::View< \
159 const Kokkos::ArithTraits<SC>::mag_type*, \
160 NT::device_type>& rowScalingFactors, \
161 const Kokkos::View< \
162 const Kokkos::ArithTraits<SC>::mag_type*, \
163 NT::device_type>& colScalingFactors, \
164 const bool leftScale, \
165 const bool rightScale, \
166 const bool assumeSymmetric, \
167 const EScaling scaling); \
170 leftAndOrRightScaleCrsMatrix ( \
171 Tpetra::CrsMatrix<SC, LO, GO, NT>& A, \
172 const Tpetra::Vector<Kokkos::ArithTraits<SC>::mag_type, LO, GO, NT>& rowScalingFactors, \
173 const Tpetra::Vector<Kokkos::ArithTraits<SC>::mag_type, LO, GO, NT>& colScalingFactors, \
174 const bool leftScale, \
175 const bool rightScale, \
176 const bool assumeSymmetric, \
177 const EScaling scaling);
179 #endif // TPETRA_LEFTANDORRIGHTSCALECRSMATRIX_DEF_HPP
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this matrix.
void leftAndOrRightScaleCrsMatrix(Tpetra::CrsMatrix< SC, LO, GO, NT > &A, const Kokkos::View< const typename Kokkos::ArithTraits< SC >::mag_type *, typename NT::device_type > &rowScalingFactors, const Kokkos::View< const typename Kokkos::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...
EScaling
Whether "scaling" a matrix means multiplying or dividing its entries.
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.
void leftScaleLocalCrsMatrix(const LocalSparseMatrixType &A_lcl, const ScalingFactorsViewType &scalingFactors, const bool assumeSymmetric, const bool divide=true)
Left-scale a KokkosSparse::CrsMatrix.
bool isFillComplete() const override
Whether the matrix is fill complete.
TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type getLocalMatrixDevice() const
The local sparse 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...
Declaration and definition of Tpetra::Details::leftScaleLocalCrsMatrix.
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this matrix.
A distributed dense vector.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
Declaration and definition of Tpetra::Details::rightScaleLocalCrsMatrix.
void rightScaleLocalCrsMatrix(const LocalSparseMatrixType &A_lcl, const ScalingFactorsViewType &scalingFactors, const bool assumeSymmetric, const bool divide=true)
Right-scale a KokkosSparse::CrsMatrix.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Teuchos::RCP< const map_type > getRowMap() const override
The Map that describes the row distribution in this matrix.