Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Details_getDiagCopyWithoutOffsets_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_DETAILS_GETDIAGCOPYWITHOUTOFFSETS_DECL_HPP
11#define TPETRA_DETAILS_GETDIAGCOPYWITHOUTOFFSETS_DECL_HPP
12
21
22#include "TpetraCore_config.h"
23#include "Kokkos_Core.hpp"
24#include "KokkosKernels_ArithTraits.hpp"
26#include "Tpetra_RowMatrix_decl.hpp"
28#include <type_traits>
29
30namespace Tpetra {
31namespace Details {
32
45template <class DiagType,
46 class LocalMapType,
47 class CrsMatrixType>
49 typedef typename LocalMapType::local_ordinal_type LO; // local ordinal type
50 typedef typename LocalMapType::global_ordinal_type GO; // global ordinal type
51 typedef typename CrsMatrixType::device_type device_type;
52 typedef typename CrsMatrixType::value_type scalar_type;
53 typedef typename CrsMatrixType::size_type offset_type;
54
56 typedef LO value_type;
57
66 const LocalMapType& rowMap,
67 const LocalMapType& colMap,
68 const CrsMatrixType& A)
69 : D_(D)
70 , rowMap_(rowMap)
71 , colMap_(colMap)
72 , A_(A) {}
73
79 const LO INV = Tpetra::Details::OrdinalTraits<LO>::invalid();
80 const scalar_type ZERO =
81 KokkosKernels::ArithTraits<scalar_type>::zero();
82
83 // If the row lacks a stored diagonal entry, then its value is zero.
84 D_(lclRowInd) = ZERO;
85 const GO gblInd = rowMap_.getGlobalElement(lclRowInd);
86 const LO lclColInd = colMap_.getLocalElement(gblInd);
87
88 if (lclColInd != INV) {
89 auto curRow = A_.rowConst(lclRowInd);
90
91 // FIXME (mfh 12 May 2016) Use binary search when the row is
92 // long enough. findRelOffset currently lives in KokkosKernels
93 // (in tpetra/kernels/src/Kokkos_Sparse_findRelOffset.hpp).
94 LO offset = 0;
95 const LO numEnt = curRow.length;
96 for (; offset < numEnt; ++offset) {
97 if (curRow.colidx(offset) == lclColInd) {
98 break;
99 }
100 }
101
102 if (offset == numEnt) {
103 ++errCount;
104 } else {
105 D_(lclRowInd) = curRow.value(offset);
106 }
107 }
108 }
109
110 private:
112 DiagType D_;
114 LocalMapType rowMap_;
116 LocalMapType colMap_;
118 CrsMatrixType A_;
119};
120
143template <class DiagType,
144 class LocalMapType,
145 class CrsMatrixType>
146static typename LocalMapType::local_ordinal_type
148 const LocalMapType& rowMap,
149 const LocalMapType& colMap,
150 const CrsMatrixType& A) {
151 static_assert(Kokkos::is_view<DiagType>::value,
152 "DiagType must be a Kokkos::View.");
153 static_assert(static_cast<int>(DiagType::rank) == 1,
154 "DiagType must be a 1-D Kokkos::View.");
155 static_assert(std::is_same<typename DiagType::value_type, typename DiagType::non_const_value_type>::value,
156 "DiagType must be a nonconst Kokkos::View.");
157 typedef typename LocalMapType::local_ordinal_type LO;
158 typedef typename CrsMatrixType::device_type device_type;
159 typedef typename device_type::execution_space execution_space;
160 typedef Kokkos::RangePolicy<execution_space, LO> policy_type;
161
162 typedef Kokkos::View<typename DiagType::non_const_value_type*,
163 typename DiagType::array_layout,
164 typename DiagType::device_type,
165 Kokkos::MemoryUnmanaged>
166 diag_type;
167 diag_type D_out = D;
169 functor(D_out, rowMap, colMap, A);
170 const LO numRows = static_cast<LO>(D.extent(0));
171 LO errCount = 0;
172 Kokkos::parallel_reduce(policy_type(0, numRows), functor, errCount);
173 return errCount;
174}
175
212template <class SC, class LO, class GO, class NT>
214 const ::Tpetra::RowMatrix<SC, LO, GO, NT>& A,
215 const bool debug =
217 true);
218#else // ! HAVE_TPETRA_DEBUG
219 false);
220#endif // HAVE_TPETRA_DEBUG
221
222} // namespace Details
223} // namespace Tpetra
224
225#endif // TPETRA_DETAILS_GETDIAGCOPYWITHOUTOFFSETS_DECL_HPP
Import KokkosSparse::OrdinalTraits, a traits class for "invalid" (flag) values of integer types,...
Declaration of the Tpetra::Vector class.
Struct that holds views of the contents of a CrsMatrix.
Implementation details of Tpetra.
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...
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,...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
@ ZERO
Replace old values with zero.
Functor that implements much of the one-argument overload of Tpetra::CrsMatrix::getLocalDiagCopy,...
CrsMatrixGetDiagCopyFunctor(const DiagType &D, const LocalMapType &rowMap, const LocalMapType &colMap, const CrsMatrixType &A)
Constructor.
KOKKOS_FUNCTION void operator()(const LO &lclRowInd, value_type &errCount) const
Operator for Kokkos::parallel_for.