40 #ifndef TPETRA_DETAILS_LOCALROWOFFSETS_DEF_HPP
41 #define TPETRA_DETAILS_LOCALROWOFFSETS_DEF_HPP
47 #include "Tpetra_CrsGraph.hpp"
48 #include "Tpetra_RowGraph.hpp"
51 #include "Kokkos_Core.hpp"
57 template <
class LO,
class GO,
class NT>
58 std::pair<typename LocalRowOffsetsResult<NT>::offsets_type,
size_t>
59 localRowCounts (
const RowGraph<LO, GO, NT>& G)
61 using result_type = LocalRowOffsetsResult<NT>;
62 using offsets_type =
typename result_type::offsets_type;
63 using offset_type =
typename result_type::offset_type;
65 const LO lclNumRows (G.getNodeNumRows ());
66 offsets_type entPerRow;
67 if (lclNumRows != 0) {
68 using Kokkos::view_alloc;
69 using Kokkos::WithoutInitializing;
71 offsets_type (view_alloc (
"entPerRow", WithoutInitializing),
74 using host = Kokkos::DefaultHostExecutionSpace;
75 auto entPerRow_h = Kokkos::create_mirror_view (host (), entPerRow);
82 for (LO i = 0; i < lclNumRows; ++i) {
83 const size_t lclNumEnt = G.getNumEntriesInLocalRow (i);
84 entPerRow_h[i] = offset_type (lclNumEnt);
85 maxNumEnt = maxNumEnt < lclNumEnt ? lclNumEnt : maxNumEnt;
88 return {entPerRow, maxNumEnt};
91 template <
class LO,
class GO,
class NT>
92 LocalRowOffsetsResult<NT>
93 localRowOffsetsFromRowGraph (
const RowGraph<LO, GO, NT>& G)
95 using result_type = LocalRowOffsetsResult<NT>;
96 using offsets_type =
typename result_type::offsets_type;
97 using offset_type =
typename result_type::offset_type;
99 offsets_type entPerRow;
100 size_t maxNumEnt = 0;
102 auto result = localRowCounts (G);
103 entPerRow = result.first;
104 maxNumEnt = result.second;
107 const LO lclNumRows (G.getNodeNumRows ());
110 if (lclNumRows != 0) {
111 using Kokkos::view_alloc;
112 using Kokkos::WithoutInitializing;
113 ptr = offsets_type (view_alloc (
"ptr", WithoutInitializing),
118 return {ptr, nnz, maxNumEnt};
121 template <
class LO,
class GO,
class NT>
122 LocalRowOffsetsResult<NT>
123 localRowOffsetsFromFillCompleteCrsGraph (
const CrsGraph<LO, GO, NT>& G)
125 using Kokkos::view_alloc;
126 using Kokkos::WithoutInitializing;
127 using result_type = LocalRowOffsetsResult<NT>;
128 using offsets_type =
typename result_type::offsets_type;
129 using offset_type =
typename result_type::offset_type;
131 auto G_lcl = G.getLocalGraph ();
132 offsets_type ptr (view_alloc (
"ptr", WithoutInitializing),
133 G_lcl.row_map.extent (0));
136 const offset_type nnz = G.getNodeNumEntries ();
137 const size_t maxNumEnt = G.getNodeMaxNumRowEntries ();
138 return {ptr, nnz, maxNumEnt};
143 template <
class LO,
class GO,
class NT>
144 LocalRowOffsetsResult<NT>
149 const crs_graph_type* G_crs =
150 dynamic_cast<const crs_graph_type*
> (&G);
151 if (G_crs !=
nullptr) {
152 return Impl::localRowOffsetsFromFillCompleteCrsGraph (*G_crs);
155 return Impl::localRowOffsetsFromRowGraph (G);
166 #define TPETRA_DETAILS_LOCALROWOFFSETS_INSTANT(LO, GO, NT) \
167 namespace Details { \
170 template std::pair<LocalRowOffsetsResult<NT>::offsets_type, size_t> \
171 localRowCounts (const RowGraph<LO, GO, NT>& G); \
173 template LocalRowOffsetsResult<NT> \
174 localRowOffsetsFromRowGraph (const RowGraph<LO, GO, NT>& G); \
176 template LocalRowOffsetsResult<NT> \
177 localRowOffsetsFromFillCompleteCrsGraph (const CrsGraph<LO, GO, NT>& G); \
181 template LocalRowOffsetsResult<NT> \
182 localRowOffsets (const RowGraph<LO, GO, NT>& A); \
185 #endif // TPETRA_DETAILS_LOCALROWOFFSETS_DEF_HPP
An abstract interface for graphs accessed by rows.
virtual bool isFillComplete() const =0
Whether fillComplete() has been called (without an intervening resumeFill()).
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
Declare and define the functions Tpetra::Details::computeOffsetsFromCounts and Tpetra::computeOffsets...
LocalRowOffsetsResult< NT > localRowOffsets(const RowGraph< LO, GO, NT > &G)
Get local row offsets ("ptr", in compressed sparse row terms) for the given graph.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
OffsetsViewType::non_const_value_type computeOffsetsFromCounts(const ExecutionSpace &execSpace, const OffsetsViewType &ptr, const CountsViewType &counts)
Compute offsets from counts.
Declaration and definition of Tpetra::Details::getEntryOnHost.