70 using idsHost_t =
typename adapter_t::ConstIdsHostView;
71 using offsetsHost_t =
typename adapter_t::ConstOffsetsHostView;
73 typename adapter_t::user_t::nonconst_local_inds_host_view_type;
75 const auto nvtx = graph.getLocalNumRows();
76 const auto nedges = graph.getLocalNumEntries();
77 const auto maxNumEntries = graph.getLocalMaxNumRowEntries();
79 typename adapter_t::Base::ConstIdsHostView adjIdsHost_(
"adjIdsHost_", nedges);
80 typename adapter_t::Base::ConstOffsetsHostView offsHost_(
"offsHost_",
83 localInds_t nbors(
"nbors", maxNumEntries);
85 for (
size_t v = 0; v < nvtx; v++) {
86 size_t numColInds = 0;
87 graph.getLocalRowCopy(v, nbors, numColInds);
89 offsHost_(v + 1) = offsHost_(v) + numColInds;
90 for (
size_t e = offsHost_(v), i = 0; e < offsHost_(v + 1); e++) {
91 adjIdsHost_(e) = graph.getColMap()->getGlobalElement(nbors(i++));
96 ia.getVertexIDsHostView(vtxIdsHost);
98 const auto graphIDS = graph.getRowMap()->getLocalElementList();
102 idsHost_t adjIdsHost;
103 offsetsHost_t offsetsHost;
104 ia.getEdgesHostView(offsetsHost, adjIdsHost);
112 using idsDevice_t =
typename adapter_t::ConstIdsDeviceView;
113 using idsHost_t =
typename adapter_t::ConstIdsHostView;
114 using offsetsDevice_t =
typename adapter_t::ConstOffsetsDeviceView;
115 using offsetsHost_t =
typename adapter_t::ConstOffsetsHostView;
116 using weightsDevice_t =
typename adapter_t::WeightsDeviceView1D;
117 using weightsHost_t =
typename adapter_t::WeightsHostView1D;
119 const auto nVtx = ia.getLocalNumIDs();
128 idsDevice_t vtxIdsDevice;
129 ia.getVertexIDsDeviceView(vtxIdsDevice);
130 idsHost_t vtxIdsHost;
131 ia.getVertexIDsHostView(vtxIdsHost);
139 idsDevice_t adjIdsDevice;
140 offsetsDevice_t offsetsDevice;
142 ia.getEdgesDeviceView(offsetsDevice, adjIdsDevice);
144 idsHost_t adjIdsHost;
145 offsetsHost_t offsetsHost;
146 ia.getEdgesHostView(offsetsHost, adjIdsHost);
155 typename adapter_t::ConstWeightsDeviceView1D{}, 50),
158 weightsDevice_t wgts0(
"wgts0", nVtx);
159 Kokkos::parallel_for(
160 nVtx, KOKKOS_LAMBDA(
const int idx) { wgts0(idx) = idx * 2; });
167 weightsDevice_t wgts1(
"wgts1", nVtx);
168 Kokkos::parallel_for(
169 nVtx, KOKKOS_LAMBDA(
const int idx) { wgts1(idx) = idx * 3; });
177 weightsDevice_t weightsDevice;
180 weightsHost_t weightsHost;
188 weightsDevice_t weightsDevice;
191 weightsHost_t weightsHost;
199 weightsDevice_t wgtsDevice;
203 weightsHost_t wgtsHost;
204 Z2_TEST_THROW(ia.getVertexWeightsHostView(wgtsHost, 2), std::runtime_error);
210int main(
int narg,
char *arg[]) {
217 Tpetra::ScopeGuard tscope(&narg, &arg);
218 const auto comm = Tpetra::getDefaultComm();
221 Teuchos::ParameterList params;
222 params.set(
"input file",
"simple");
223 params.set(
"file type",
"Chaco");
228 const auto crsGraph = uinput->getUITpetraCrsGraph();
229 const auto rowGraph = rcp_dynamic_cast<ztrowgraph_t>(crsGraph);
231 const auto nvtx = rowGraph->getLocalNumRows();
236 const int nWeights = 2;
244 auto tpetraCrsGraphInput = rcp(
new crsAdapter_t(crsGraph, nWeights));
249 crsPart_t *p =
new crsPart_t[nvtx];
250 memset(p, 0,
sizeof(crsPart_t) * nvtx);
251 ArrayRCP<crsPart_t> solnParts(p, 0, nvtx,
true);
253 crsSoln_t solution(env, comm, nWeights);
254 solution.setParts(solnParts);
255 tpetraCrsGraphInput->applyPartitioningSolution(*crsGraph, mMigrate,
257 const auto newG = rcp(mMigrate);
259 auto cnewG = rcp_const_cast<const ztcrsgraph_t>(newG);
262 PrintFromRoot(
"Input adapter for Tpetra::RowGraph migrated to proc 0");
273 auto tpetraRowGraphInput = rcp(
new rowAdapter_t(rowGraph, nWeights));
277 rowPart_t *p =
new rowPart_t[nvtx];
278 memset(p, 0,
sizeof(rowPart_t) * nvtx);
279 ArrayRCP<rowPart_t> solnParts(p, 0, nvtx,
true);
281 rowSoln_t solution(env, comm, nWeights);
282 solution.setParts(solnParts);
285 tpetraRowGraphInput->applyPartitioningSolution(*crsGraph, mMigrate,
287 const auto newG = rcp(mMigrate);
289 auto cnewG = rcp_const_cast<const ztrowgraph_t>(newG);
292 PrintFromRoot(
"Input adapter for Tpetra::RowGraph migrated to proc 0");
296 }
catch (std::exception &e) {
297 std::cout << e.what() << std::endl;