42 #ifndef TPETRA_LEFTANDORRIGHTSCALECRSMATRIX_DEF_HPP
43 #define TPETRA_LEFTANDORRIGHTSCALECRSMATRIX_DEF_HPP
52 #include "Tpetra_CrsMatrix.hpp"
53 #include "Tpetra_Vector.hpp"
57 #include "Teuchos_TestForException.hpp"
61 template<
class SC,
class LO,
class GO,
class NT>
65 const typename Kokkos::ArithTraits<SC>::mag_type*,
66 typename NT::device_type>& rowScalingFactors,
68 const typename Kokkos::ArithTraits<SC>::mag_type*,
69 typename NT::device_type>& colScalingFactors,
71 const bool rightScale,
72 const bool assumeSymmetric,
75 if (! leftScale && ! rightScale) {
80 if (! A_fillComplete_on_input) {
88 static_cast<LO
> (A.
getRowMap ()->getNodeNumElements ());
89 TEUCHOS_TEST_FOR_EXCEPTION
90 (A_lcl.numRows () != lclNumRows, std::invalid_argument,
91 "leftAndOrRightScaleCrsMatrix: Local matrix is not valid. "
92 "This means that A was not created with a local matrix, "
93 "and that fillComplete has never yet been called on A before. "
94 "Please call fillComplete on A at least once first "
95 "before calling this method.");
101 const bool divide = scaling == SCALING_DIVIDE;
115 if (A_fillComplete_on_input) {
116 Teuchos::RCP<Teuchos::ParameterList> params = Teuchos::parameterList ();
117 params->set (
"No Nonlocal Changes",
true);
122 template<
class SC,
class LO,
class GO,
class NT>
126 typename Kokkos::ArithTraits<SC>::mag_type,
127 LO, GO, NT>& rowScalingFactors,
129 typename Kokkos::ArithTraits<SC>::mag_type,
130 LO, GO, NT>& colScalingFactors,
131 const bool leftScale,
132 const bool rightScale,
133 const bool assumeSymmetric,
136 using device_type =
typename NT::device_type;
137 using dev_memory_space =
typename device_type::memory_space;
138 using mag_type =
typename Kokkos::ArithTraits<SC>::mag_type;
140 const char prefix[] =
"leftAndOrRightScaleCrsMatrix: ";
143 Kokkos::View<const mag_type*, device_type> row_lcl;
144 Kokkos::View<const mag_type*, device_type> col_lcl;
147 const bool same = rowScalingFactors.getMap ()->isSameAs (* (A.
getRowMap ()));
148 TEUCHOS_TEST_FOR_EXCEPTION
149 (! same, std::invalid_argument, prefix <<
"rowScalingFactors's Map "
150 "must be the same as the CrsMatrix's row Map. If you see this "
151 "message, it's likely that you are using a range Map Vector and that "
152 "the CrsMatrix's row Map is overlapping.");
154 if (rowScalingFactors.template need_sync<dev_memory_space> ()) {
155 const_cast<vec_type&
> (rowScalingFactors).
template sync<dev_memory_space> ();
157 auto row_lcl_2d = rowScalingFactors.template getLocalView<dev_memory_space> ();
158 row_lcl = Kokkos::subview (row_lcl_2d, Kokkos::ALL (), 0);
162 const bool same = colScalingFactors.getMap ()->isSameAs (* (A.
getColMap ()));
163 TEUCHOS_TEST_FOR_EXCEPTION
164 (! same, std::invalid_argument, prefix <<
"colScalingFactors's Map "
165 "must be the same as the CrsMatrix's column Map. If you see this "
166 "message, it's likely that you are using a domain Map Vector.");
168 if (colScalingFactors.template need_sync<dev_memory_space> ()) {
169 const_cast<vec_type&
> (colScalingFactors).
template sync<dev_memory_space> ();
171 auto col_lcl_2d = colScalingFactors.template getLocalView<dev_memory_space> ();
172 col_lcl = Kokkos::subview (col_lcl_2d, Kokkos::ALL (), 0);
176 assumeSymmetric, scaling);
187 #define TPETRA_LEFTANDORRIGHTSCALECRSMATRIX_INSTANT(SC,LO,GO,NT) \
189 leftAndOrRightScaleCrsMatrix ( \
190 Tpetra::CrsMatrix<SC, LO, GO, NT>& A, \
191 const Kokkos::View< \
192 const Kokkos::ArithTraits<SC>::mag_type*, \
193 NT::device_type>& rowScalingFactors, \
194 const Kokkos::View< \
195 const Kokkos::ArithTraits<SC>::mag_type*, \
196 NT::device_type>& colScalingFactors, \
197 const bool leftScale, \
198 const bool rightScale, \
199 const bool assumeSymmetric, \
200 const EScaling scaling); \
203 leftAndOrRightScaleCrsMatrix ( \
204 Tpetra::CrsMatrix<SC, LO, GO, NT>& A, \
205 const Tpetra::Vector<Kokkos::ArithTraits<SC>::mag_type, LO, GO, NT>& rowScalingFactors, \
206 const Tpetra::Vector<Kokkos::ArithTraits<SC>::mag_type, LO, GO, NT>& colScalingFactors, \
207 const bool leftScale, \
208 const bool rightScale, \
209 const bool assumeSymmetric, \
210 const EScaling scaling);
212 #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.
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.
local_matrix_type getLocalMatrix() const
The local sparse 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.