42 #ifndef TPETRA_DETAILS_LEFTSCALELOCALCRSMATRIX_HPP
43 #define TPETRA_DETAILS_LEFTSCALELOCALCRSMATRIX_HPP
52 #include "TpetraCore_config.h"
53 #include "Kokkos_Core.hpp"
54 #include "Kokkos_ArithTraits.hpp"
55 #include <type_traits>
68 template<
class LocalSparseMatrixType,
69 class ScalingFactorsViewType,
74 typename std::remove_const<typename LocalSparseMatrixType::value_type>::type;
75 using mag_type =
typename ScalingFactorsViewType::non_const_value_type;
76 static_assert (ScalingFactorsViewType::Rank == 1,
77 "scalingFactors must be a rank-1 Kokkos::View.");
78 using device_type =
typename LocalSparseMatrixType::device_type;
89 const ScalingFactorsViewType& scalingFactors,
90 const bool assumeSymmetric) :
92 scalingFactors_ (scalingFactors),
93 assumeSymmetric_ (assumeSymmetric)
96 KOKKOS_INLINE_FUNCTION
void
97 operator () (
const typename LocalSparseMatrixType::ordinal_type lclRow)
const
99 using LO =
typename LocalSparseMatrixType::ordinal_type;
100 using KAM = Kokkos::ArithTraits<mag_type>;
102 const mag_type curRowNorm = scalingFactors_(lclRow);
105 const mag_type scalingFactor = assumeSymmetric_ ?
106 KAM::sqrt (curRowNorm) : curRowNorm;
107 auto curRow = A_lcl_.row (lclRow);
108 const LO numEnt = curRow.length;
109 for (LO k = 0; k < numEnt; ++k) {
111 curRow.value (k) = curRow.value(k) / scalingFactor;
114 curRow.value (k) = curRow.value(k) * scalingFactor;
120 LocalSparseMatrixType A_lcl_;
121 typename ScalingFactorsViewType::const_type scalingFactors_;
122 bool assumeSymmetric_;
138 template<
class LocalSparseMatrixType,
class ScalingFactorsViewType>
141 const ScalingFactorsViewType& scalingFactors,
142 const bool assumeSymmetric,
143 const bool divide =
true)
145 using device_type =
typename LocalSparseMatrixType::device_type;
146 using execution_space =
typename device_type::execution_space;
147 using LO =
typename LocalSparseMatrixType::ordinal_type;
148 using range_type = Kokkos::RangePolicy<execution_space, LO>;
150 const LO lclNumRows = A_lcl.numRows ();
154 typename ScalingFactorsViewType::const_type,
true>;
155 functor_type functor (A_lcl, scalingFactors, assumeSymmetric);
156 Kokkos::parallel_for (
"leftScaleLocalCrsMatrix",
157 range_type (0, lclNumRows), functor);
162 typename ScalingFactorsViewType::const_type,
false>;
163 functor_type functor (A_lcl, scalingFactors, assumeSymmetric);
164 Kokkos::parallel_for (
"leftScaleLocalCrsMatrix",
165 range_type (0, lclNumRows), functor);
172 #endif // TPETRA_DETAILS_LEFTSCALELOCALCRSMATRIX_HPP
void leftScaleLocalCrsMatrix(const LocalSparseMatrixType &A_lcl, const ScalingFactorsViewType &scalingFactors, const bool assumeSymmetric, const bool divide=true)
Left-scale a KokkosSparse::CrsMatrix.
Kokkos::parallel_for functor that left-scales a KokkosSparse::CrsMatrix.
LeftScaleLocalCrsMatrix(const LocalSparseMatrixType &A_lcl, const ScalingFactorsViewType &scalingFactors, const bool assumeSymmetric)