40 #ifndef TPETRA_DETAILS_LOCALDEEPCOPYROWMATRIX_DEF_HPP
41 #define TPETRA_DETAILS_LOCALDEEPCOPYROWMATRIX_DEF_HPP
47 #include "Tpetra_Map.hpp"
48 #include "Tpetra_RowMatrix.hpp"
49 #include "Tpetra_Details_localRowOffsets.hpp"
50 #include "Teuchos_TestForException.hpp"
51 #include "Teuchos_Array.hpp"
52 #include "Kokkos_Core.hpp"
56 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
67 template <
class SC,
class LO,
class GO,
class NT>
68 KokkosSparse::CrsMatrix<
69 typename Kokkos::ArithTraits<SC>::val_type,
71 typename NT::device_type,
74 localDeepCopyLocallyIndexedRowMatrix
75 (
const RowMatrix<SC, LO, GO, NT>& A,
78 TEUCHOS_TEST_FOR_EXCEPTION
79 (A.isGloballyIndexed (), std::logic_error,
80 "Tpetra::Details::localDeepCopyLocallyIndexedRowMatrix: "
81 "Input RowMatrix is globally indexed.");
83 using lro_result_type = LocalRowOffsetsResult<NT>;
84 using offsets_type =
typename lro_result_type::offsets_type;
85 using offset_type =
typename lro_result_type::offset_type;
90 const auto& G = * (A.getGraph ());
91 const lro_result_type result = localRowOffsets (G);
94 maxNumEnt = result.maxNumEnt;
97 using Kokkos::view_alloc;
98 using Kokkos::WithoutInitializing;
99 using IST =
typename Kokkos::ArithTraits<SC>::val_type;
100 using local_matrix_device_type = KokkosSparse::CrsMatrix<
101 IST, LO,
typename NT::device_type, void,
size_t>;
102 using local_graph_device_type =
103 typename local_matrix_device_type::staticcrsgraph_type;
104 using inds_type =
typename local_graph_device_type::entries_type;
105 inds_type ind (view_alloc (
"ind", WithoutInitializing), nnz);
106 auto ind_h = Kokkos::create_mirror_view (ind);
108 using values_type =
typename local_matrix_device_type::values_type;
109 values_type val (view_alloc (
"val", WithoutInitializing), nnz);
110 auto val_h = Kokkos::create_mirror_view (val);
112 const bool hasViews = A.supportsRowViews ();
113 using row_matrix_type = RowMatrix<SC, LO, GO, NT>;
114 using h_lids_type =
typename row_matrix_type::nonconst_local_inds_host_view_type;
115 using h_vals_type =
typename row_matrix_type::nonconst_values_host_view_type;
116 using h_lids_type_const =
typename row_matrix_type::local_inds_host_view_type;
117 using h_vals_type_const =
typename row_matrix_type::values_host_view_type;
120 h_lids_type inputIndsBuf;
121 h_vals_type inputValsBuf;
123 Kokkos::resize(inputIndsBuf,maxNumEnt);
124 Kokkos::resize(inputValsBuf,maxNumEnt);
127 const LO lclNumRows (A.getLocalNumRows ());
128 offset_type curPos = 0;
129 for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
130 h_lids_type_const inputInds_av;
131 h_vals_type_const inputVals_av;
134 A.getLocalRowView (lclRow, inputInds_av,
136 numEnt =
static_cast<size_t> (inputInds_av.size ());
139 A.getLocalRowCopy (lclRow, inputIndsBuf,
140 inputValsBuf, numEnt);
141 inputInds_av = Kokkos::subview(inputIndsBuf,std::make_pair((
size_t)0,numEnt));
142 inputVals_av = Kokkos::subview(inputValsBuf,std::make_pair((
size_t)0,numEnt));
145 reinterpret_cast<const IST*
> (inputVals_av.data());
146 const LO* inInds = inputInds_av.data();
147 std::copy (inInds, inInds + numEnt, ind_h.data () + curPos);
148 std::copy (inVals, inVals + numEnt, val_h.data () + curPos);
149 curPos += offset_type (numEnt);
152 using execution_space =
typename inds_type::execution_space;
158 local_graph_device_type lclGraph (ind, ptr);
159 const size_t numCols = A.getColMap ()->getLocalNumElements ();
160 return local_matrix_device_type (label, numCols, val, lclGraph);
173 #define TPETRA_DETAILS_LOCALDEEPCOPYROWMATRIX_INSTANT(SC, LO, GO, NT) \
174 namespace Details { \
175 template KokkosSparse::CrsMatrix< \
176 Kokkos::ArithTraits<SC>::val_type, \
177 LO, NT::device_type, void, size_t> \
178 localDeepCopyLocallyIndexedRowMatrix<SC, LO, GO, NT> \
179 (const RowMatrix<SC, LO, GO, NT>& A, \
180 const char label[]); \
183 #endif // TPETRA_ENABLE_DEPRECATED_CODE
185 #endif // TPETRA_DETAILS_LOCALDEEPCOPYROWMATRIX_DEF_HPP
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.