23 #include <Teuchos_Comm.hpp>
24 #include <Teuchos_CommHelpers.hpp>
25 #include <Teuchos_DefaultComm.hpp>
26 #include <Teuchos_RCP.hpp>
34 using Teuchos::rcp_const_cast;
35 using Teuchos::rcp_dynamic_cast;
37 using ztcrsmatrix_t = Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
42 typename crsAdapter_t::ConstWeightsHostView1D::execution_space;
46 template <
typename adapter_t,
typename matrix_t>
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;
57 const auto nrows = matrix.getLocalNumRows();
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);
93 template <
typename adapter_t,
typename matrix_t>
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);
177 int 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);
226 PrintFromRoot(
"Input adapter for Tpetra::CrsMatrix migrated to proc 0");
230 }
catch (std::exception &e) {
231 std::cout << e.what() << std::endl;
void PrintFromRoot(const std::string &message)
Provides access for Zoltan2 to Tpetra::CrsMatrix 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)
Defines the TpetraRowMatrixAdapter class.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
#define Z2_TEST_THROW(code, ExceptType)
#define Z2_TEST_NOTHROW(code)