10 #ifndef TPETRA_DETAILS_GETDIAGCOPYWITHOUTOFFSETS_DECL_HPP
11 #define TPETRA_DETAILS_GETDIAGCOPYWITHOUTOFFSETS_DECL_HPP
22 #include "TpetraCore_config.h"
23 #include "Kokkos_Core.hpp"
24 #include "Kokkos_ArithTraits.hpp"
26 #include "Tpetra_RowMatrix_decl.hpp"
28 #include <type_traits>
45 template<
class DiagType,
49 typedef typename LocalMapType::local_ordinal_type LO;
50 typedef typename LocalMapType::global_ordinal_type GO;
51 typedef typename CrsMatrixType::device_type device_type;
52 typedef typename CrsMatrixType::value_type scalar_type;
53 typedef typename CrsMatrixType::size_type offset_type;
66 const LocalMapType& rowMap,
67 const LocalMapType& colMap,
68 const CrsMatrixType& A) :
69 D_ (D), rowMap_ (rowMap), colMap_ (colMap), A_ (A)
78 const LO INV = Tpetra::Details::OrdinalTraits<LO>::invalid ();
79 const scalar_type
ZERO =
80 Kokkos::ArithTraits<scalar_type>::zero ();
84 const GO gblInd = rowMap_.getGlobalElement (lclRowInd);
85 const LO lclColInd = colMap_.getLocalElement (gblInd);
87 if (lclColInd != INV) {
88 auto curRow = A_.rowConst (lclRowInd);
94 const LO numEnt = curRow.length;
95 for ( ; offset < numEnt; ++offset) {
96 if (curRow.colidx(offset) == lclColInd) {
101 if (offset == numEnt) {
105 D_(lclRowInd) = curRow.value(offset);
114 LocalMapType rowMap_;
116 LocalMapType colMap_;
144 template<
class DiagType,
147 static typename LocalMapType::local_ordinal_type
149 const LocalMapType& rowMap,
150 const LocalMapType& colMap,
151 const CrsMatrixType& A)
153 static_assert (Kokkos::is_view<DiagType>::value,
154 "DiagType must be a Kokkos::View.");
155 static_assert (static_cast<int> (DiagType::rank) == 1,
156 "DiagType must be a 1-D Kokkos::View.");
157 static_assert (std::is_same<typename DiagType::value_type, typename DiagType::non_const_value_type>::value,
158 "DiagType must be a nonconst Kokkos::View.");
159 typedef typename LocalMapType::local_ordinal_type LO;
160 typedef typename CrsMatrixType::device_type device_type;
161 typedef typename device_type::execution_space execution_space;
162 typedef Kokkos::RangePolicy<execution_space, LO> policy_type;
164 typedef Kokkos::View<
typename DiagType::non_const_value_type*,
165 typename DiagType::array_layout,
166 typename DiagType::device_type,
167 Kokkos::MemoryUnmanaged> diag_type;
170 functor (D_out, rowMap, colMap, A);
171 const LO numRows =
static_cast<LO
> (D.extent (0));
173 Kokkos::parallel_reduce (policy_type (0, numRows), functor, errCount);
213 template<
class SC,
class LO,
class GO,
class NT>
216 const ::Tpetra::RowMatrix<SC, LO, GO, NT>& A,
218 #ifdef HAVE_TPETRA_DEBUG
220 #else // ! HAVE_TPETRA_DEBUG
222 #endif // HAVE_TPETRA_DEBUG
227 #endif // TPETRA_DETAILS_GETDIAGCOPYWITHOUTOFFSETS_DECL_HPP
Import KokkosSparse::OrdinalTraits, a traits class for "invalid" (flag) values of integer types...
Functor that implements much of the one-argument overload of Tpetra::CrsMatrix::getLocalDiagCopy, for the case where the matrix is fill complete.
LO value_type
The result of the reduction; number of errors.
Declaration of the Tpetra::Vector class.
KOKKOS_FUNCTION void operator()(const LO &lclRowInd, value_type &errCount) const
Operator for Kokkos::parallel_for.
static LocalMapType::local_ordinal_type getDiagCopyWithoutOffsets(const DiagType &D, const LocalMapType &rowMap, const LocalMapType &colMap, const CrsMatrixType &A)
Given a locally indexed, local sparse matrix, and corresponding local row and column Maps...
LO getLocalDiagCopyWithoutOffsetsNotFillComplete(::Tpetra::Vector< SC, LO, GO, NT > &diag, const ::Tpetra::RowMatrix< SC, LO, GO, NT > &A, const bool debug=false)
Given a locally indexed, global sparse matrix, extract the matrix's diagonal entries into a Tpetra::V...
Replace old values with zero.
A distributed dense vector.
CrsMatrixGetDiagCopyFunctor(const DiagType &D, const LocalMapType &rowMap, const LocalMapType &colMap, const CrsMatrixType &A)
Constructor.