40 #ifndef TPETRA_DETAILS_LOCALDEEPCOPYROWMATRIX_DEF_HPP
41 #define TPETRA_DETAILS_LOCALDEEPCOPYROWMATRIX_DEF_HPP
43 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
48 #include "Tpetra_Map.hpp"
49 #include "Tpetra_RowMatrix.hpp"
50 #include "Tpetra_Details_localRowOffsets.hpp"
51 #include "Teuchos_TestForException.hpp"
52 #include "Teuchos_Array.hpp"
53 #include "Kokkos_Core.hpp"
60 template <
class SC,
class LO,
class GO,
class NT>
61 KokkosSparse::CrsMatrix<
62 typename Kokkos::ArithTraits<SC>::val_type,
64 typename NT::device_type,
68 localDeepCopyLocallyIndexedRowMatrix
69 (
const RowMatrix<SC, LO, GO, NT>& A,
72 TEUCHOS_TEST_FOR_EXCEPTION
73 (A.isGloballyIndexed (), std::logic_error,
74 "Tpetra::Details::localDeepCopyLocallyIndexedRowMatrix: "
75 "Input RowMatrix is globally indexed.");
77 using lro_result_type = LocalRowOffsetsResult<NT>;
78 using offsets_type =
typename lro_result_type::offsets_type;
79 using offset_type =
typename lro_result_type::offset_type;
84 const auto& G = * (A.getGraph ());
88 maxNumEnt = result.maxNumEnt;
91 using Kokkos::view_alloc;
92 using Kokkos::WithoutInitializing;
93 using IST =
typename Kokkos::ArithTraits<SC>::val_type;
94 using local_matrix_device_type = KokkosSparse::CrsMatrix<
95 IST, LO,
typename NT::device_type, void,
size_t>;
96 using local_graph_device_type =
97 typename local_matrix_device_type::staticcrsgraph_type;
98 using inds_type =
typename local_graph_device_type::entries_type;
99 inds_type ind (view_alloc (
"ind", WithoutInitializing), nnz);
100 auto ind_h = Kokkos::create_mirror_view (ind);
102 using values_type =
typename local_matrix_device_type::values_type;
103 values_type val (view_alloc (
"val", WithoutInitializing), nnz);
104 auto val_h = Kokkos::create_mirror_view (val);
106 const bool hasViews = A.supportsRowViews ();
107 using row_matrix_type = RowMatrix<SC, LO, GO, NT>;
108 using h_lids_type =
typename row_matrix_type::nonconst_local_inds_host_view_type;
109 using h_vals_type =
typename row_matrix_type::nonconst_values_host_view_type;
110 using h_lids_type_const =
typename row_matrix_type::local_inds_host_view_type;
111 using h_vals_type_const =
typename row_matrix_type::values_host_view_type;
114 h_lids_type inputIndsBuf;
115 h_vals_type inputValsBuf;
117 Kokkos::resize(inputIndsBuf,maxNumEnt);
118 Kokkos::resize(inputValsBuf,maxNumEnt);
121 const LO lclNumRows (A.getNodeNumRows ());
122 offset_type curPos = 0;
123 for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
124 h_lids_type_const inputInds_av;
125 h_vals_type_const inputVals_av;
128 A.getLocalRowView (lclRow, inputInds_av,
130 numEnt =
static_cast<size_t> (inputInds_av.size ());
133 A.getLocalRowCopy (lclRow, inputIndsBuf,
134 inputValsBuf, numEnt);
135 inputInds_av = Kokkos::subview(inputIndsBuf,std::make_pair((
size_t)0,numEnt));
136 inputVals_av = Kokkos::subview(inputValsBuf,std::make_pair((
size_t)0,numEnt));
139 reinterpret_cast<const IST*
> (inputVals_av.data());
140 const LO* inInds = inputInds_av.data();
141 std::copy (inInds, inInds + numEnt, ind_h.data () + curPos);
142 std::copy (inVals, inVals + numEnt, val_h.data () + curPos);
143 curPos += offset_type (numEnt);
148 local_graph_device_type lclGraph (ind, ptr);
149 const size_t numCols = A.getColMap ()->getNodeNumElements ();
150 return local_matrix_device_type (label, numCols, val, lclGraph);
163 #define TPETRA_DETAILS_LOCALDEEPCOPYROWMATRIX_INSTANT(SC, LO, GO, NT) \
164 namespace Details { \
165 template KokkosSparse::CrsMatrix< \
166 Kokkos::ArithTraits<SC>::val_type, \
167 LO, NT::device_type, void, size_t> \
168 localDeepCopyLocallyIndexedRowMatrix<SC, LO, GO, NT> \
169 (const RowMatrix<SC, LO, GO, NT>& A, \
170 const char label[]); \
Implementation details of Tpetra.
LocalRowOffsetsResult< NT > localRowOffsets(const RowGraph< LO, GO, NT > &G)
Get local row offsets ("ptr", in compressed sparse row terms) for the given graph.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
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.