10 #ifndef TPETRA_DETAILS_RIGHTSCALELOCALCRSMATRIX_HPP
11 #define TPETRA_DETAILS_RIGHTSCALELOCALCRSMATRIX_HPP
20 #include "TpetraCore_config.h"
21 #include "Kokkos_Core.hpp"
22 #include "Kokkos_ArithTraits.hpp"
23 #include <type_traits>
36 template<
class LocalSparseMatrixType,
37 class ScalingFactorsViewType,
42 typename std::remove_const<typename LocalSparseMatrixType::value_type>::type;
43 using mag_type =
typename ScalingFactorsViewType::non_const_value_type;
44 static_assert (ScalingFactorsViewType::rank == 1,
45 "scalingFactors must be a rank-1 Kokkos::View.");
46 using device_type =
typename LocalSparseMatrixType::device_type;
47 using LO =
typename LocalSparseMatrixType::ordinal_type;
48 using policy_type = Kokkos::TeamPolicy<typename device_type::execution_space, LO>;
61 const ScalingFactorsViewType& scalingFactors,
62 const bool assumeSymmetric) :
64 scalingFactors_ (scalingFactors),
65 assumeSymmetric_ (assumeSymmetric)
68 KOKKOS_INLINE_FUNCTION
void
69 operator () (
const typename policy_type::member_type & team)
const
71 using KAM = Kokkos::ArithTraits<mag_type>;
73 const LO lclRow = team.league_rank();
74 auto curRow = A_lcl_.row (lclRow);
75 const LO numEnt = curRow.length;
76 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, numEnt), [&](
const LO k) {
77 const LO lclColInd = curRow.colidx(k);
78 const mag_type curColNorm = scalingFactors_(lclColInd);
81 const mag_type scalingFactor = assumeSymmetric_ ?
82 KAM::sqrt (curColNorm) : curColNorm;
84 curRow.value(k) = curRow.value(k) / scalingFactor;
87 curRow.value(k) = curRow.value(k) * scalingFactor;
93 LocalSparseMatrixType A_lcl_;
94 typename ScalingFactorsViewType::const_type scalingFactors_;
95 bool assumeSymmetric_;
111 template<
class LocalSparseMatrixType,
class ScalingFactorsViewType>
114 const ScalingFactorsViewType& scalingFactors,
115 const bool assumeSymmetric,
116 const bool divide =
true)
118 using device_type =
typename LocalSparseMatrixType::device_type;
119 using execution_space =
typename device_type::execution_space;
120 using LO =
typename LocalSparseMatrixType::ordinal_type;
121 using policy_type = Kokkos::TeamPolicy<execution_space, LO>;
123 const LO lclNumRows = A_lcl.numRows ();
127 typename ScalingFactorsViewType::const_type,
true>;
128 functor_type functor (A_lcl, scalingFactors, assumeSymmetric);
129 Kokkos::parallel_for (
"rightScaleLocalCrsMatrix",
130 policy_type (lclNumRows, Kokkos::AUTO), functor);
135 typename ScalingFactorsViewType::const_type,
false>;
136 functor_type functor (A_lcl, scalingFactors, assumeSymmetric);
137 Kokkos::parallel_for (
"rightScaleLocalCrsMatrix",
138 policy_type (lclNumRows, Kokkos::AUTO), functor);
145 #endif // TPETRA_DETAILS_RIGHTSCALELOCALCRSMATRIX_HPP
RightScaleLocalCrsMatrix(const LocalSparseMatrixType &A_lcl, const ScalingFactorsViewType &scalingFactors, const bool assumeSymmetric)
Kokkos::parallel_for functor that right-scales a KokkosSparse::CrsMatrix.
void rightScaleLocalCrsMatrix(const LocalSparseMatrixType &A_lcl, const ScalingFactorsViewType &scalingFactors, const bool assumeSymmetric, const bool divide=true)
Right-scale a KokkosSparse::CrsMatrix.