49 using idsHost_t =
typename adapter_t::ConstIdsHostView;
50 using offsetsHost_t =
typename adapter_t::ConstOffsetsHostView;
52 typename adapter_t::user_t::nonconst_local_inds_host_view_type;
54 typename adapter_t::user_t::nonconst_values_host_view_type;
58 const auto ncols = matrix.getLocalNumEntries();
59 const auto maxNumEntries = matrix.getLocalMaxNumRowEntries();
61 typename adapter_t::Base::ConstIdsHostView colIdsHost_(
"colIdsHost_", ncols);
62 typename adapter_t::Base::ConstOffsetsHostView offsHost_(
"offsHost_",
65 localInds_t localColInds(
"localColInds", maxNumEntries);
66 localVals_t localVals(
"localVals", maxNumEntries);
68 for (
size_t r = 0; r < nrows; r++) {
69 size_t numEntries = 0;
70 matrix.getLocalRowCopy(r, localColInds, localVals, numEntries);;
72 offsHost_(r + 1) = offsHost_(r) + numEntries;
73 for (
size_t e = offsHost_(r), i = 0; e < offsHost_(r + 1); e++) {
74 colIdsHost_(e) = matrix.getColMap()->getGlobalElement(localColInds(i++));
79 ia.getRowIDsHostView(rowIdsHost);
81 const auto matrixIDS = matrix.getRowMap()->getLocalElementList();
86 offsetsHost_t offsetsHost;
87 ia.getCRSHostView(offsetsHost, colIdsHost);
95 using idsDevice_t =
typename adapter_t::ConstIdsDeviceView;
96 using idsHost_t =
typename adapter_t::ConstIdsHostView;
97 using weightsDevice_t =
typename adapter_t::WeightsDeviceView1D;
98 using weightsHost_t =
typename adapter_t::WeightsHostView1D;
100 const auto nrows = ia.getLocalNumIDs();
110 idsDevice_t rowIdsDevice;
111 ia.getRowIDsDeviceView(rowIdsDevice);
112 idsHost_t rowIdsHost;
113 ia.getRowIDsHostView(rowIdsHost);
121 typename adapter_t::WeightsDeviceView1D{}, 50),
124 weightsDevice_t wgts0(
"wgts0", nrows);
125 Kokkos::parallel_for(
126 nrows, KOKKOS_LAMBDA(
const int idx) { wgts0(idx) = idx * 2; });
132 weightsDevice_t wgts1(
"wgts1", nrows);
133 Kokkos::parallel_for(
134 nrows, KOKKOS_LAMBDA(
const int idx) { wgts1(idx) = idx * 3; });
142 weightsDevice_t weightsDevice;
145 weightsHost_t weightsHost;
153 weightsDevice_t weightsDevice;
156 weightsHost_t weightsHost;
164 weightsDevice_t wgtsDevice;
168 weightsHost_t wgtsHost;
169 Z2_TEST_THROW(ia.getRowWeightsHostView(wgtsHost, 2), std::runtime_error);
177int main(
int narg,
char *arg[]) {
181 Tpetra::ScopeGuard tscope(&narg, &arg);
182 const auto comm = Tpetra::getDefaultComm();
185 Teuchos::ParameterList params;
186 params.set(
"input file",
"simple");
187 params.set(
"file type",
"Chaco");
192 const auto crsMatrix = uinput->getUITpetraCrsMatrix();
194 const auto nrows = crsMatrix->getLocalNumRows();
199 const int nWeights = 2;
208 auto tpetraCrsMatrixInput = rcp(
new crsAdapter_t(crsMatrix, nWeights));
212 crsPart_t *p =
new crsPart_t[nrows];
213 memset(p, 0,
sizeof(crsPart_t) * nrows);
214 ArrayRCP<crsPart_t> solnParts(p, 0, nrows,
true);
216 crsSoln_t solution(env, comm, nWeights);
217 solution.setParts(solnParts);
220 tpetraCrsMatrixInput->applyPartitioningSolution(*crsMatrix, mMigrate,
222 const auto newM = rcp(mMigrate);
223 auto cnewM = rcp_const_cast<const ztcrsmatrix_t>(newM);
226 PrintFromRoot(
"Input adapter for Tpetra::CrsMatrix migrated to proc 0");
230 }
catch (std::exception &e) {
231 std::cout << e.what() << std::endl;