22 #include <Teuchos_Comm.hpp>
23 #include <Teuchos_CommHelpers.hpp>
24 #include <Teuchos_DefaultComm.hpp>
25 #include <Teuchos_RCP.hpp>
32 using Teuchos::rcp_const_cast;
33 using Teuchos::rcp_dynamic_cast;
42 typename rowAdapter_t::ConstWeightsHostView1D::execution_space;
44 template <
typename offset_t>
46 const offset_t *offsets,
const zgno_t *edgeIds) {
47 int rank = comm->getRank();
48 int nprocs = comm->getSize();
50 for (
int p = 0; p < nprocs; p++) {
52 std::cout << rank <<
":" << std::endl;
53 for (
zlno_t i = 0; i < nvtx; i++) {
54 std::cout <<
" vertex " << vtxIds[i] <<
": ";
55 for (offset_t j = offsets[i]; j < offsets[i + 1]; j++) {
56 std::cout << edgeIds[j] <<
" ";
58 std::cout << std::endl;
67 template <
typename adapter_t,
typename graph_t>
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);
110 template <
typename adapter_t,
typename graph_t>
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);
210 int 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);
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);
292 PrintFromRoot(
"Input adapter for Tpetra::RowGraph migrated to proc 0");
296 }
catch (std::exception &e) {
297 std::cout << e.what() << std::endl;
void PrintFromRoot(const std::string &message)
Defines TpetraRowGraphAdapter class.
Defines TpetraCrsGraphAdapter class.
Provides access for Zoltan2 to Tpetra::CrsMatrix data.
Provides access for Zoltan2 to Tpetra::CrsGraph data.
int main(int narg, char **arg)
common code used by tests
typename InputTraits< User >::part_t part_t
#define Z2_TEST_COMPARE_ARRAYS(val1, val2)
A PartitioningSolution is a solution to a partitioning problem.
#define Z2_TEST_DEVICE_HOST_VIEWS(deviceView, hostView)
#define Z2_TEST_EQUALITY(val1, val2)
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
Tpetra::Map::local_ordinal_type zlno_t
#define Z2_TEST_THROW(code, ExceptType)
Tpetra::Map::global_ordinal_type zgno_t
#define Z2_TEST_NOTHROW(code)
Provides access for Zoltan2 to Tpetra::RowGraph data.