58 #include <Teuchos_Comm.hpp>
59 #include <Teuchos_CommHelpers.hpp>
60 #include <Teuchos_DefaultComm.hpp>
61 #include <Teuchos_RCP.hpp>
69 using Teuchos::rcp_const_cast;
70 using Teuchos::rcp_dynamic_cast;
72 using ztcrsmatrix_t = Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
73 using ztrowmatrix_t = Tpetra::RowMatrix<zscalar_t, zlno_t, zgno_t, znode_t>;
79 typename rowAdapter_t::ConstWeightsHostView1D::execution_space;
83 template<
typename offset_t>
85 const zgno_t *rowIds,
const offset_t *offsets,
const zgno_t *colIds) {
86 int rank = comm->getRank();
87 int nprocs = comm->getSize();
89 for (
int p=0; p < nprocs; p++){
91 std::cout << rank <<
":" << std::endl;
92 for (
zlno_t i=0; i < nrows; i++){
93 std::cout <<
" row " << rowIds[i] <<
": ";
94 for (offset_t j=offsets[i]; j < offsets[i+1]; j++){
95 std::cout << colIds[j] <<
" ";
97 std::cout << std::endl;
108 template <
typename adapter_t,
typename matrix_t>
111 using idsHost_t =
typename adapter_t::ConstIdsHostView;
112 using offsetsHost_t =
typename adapter_t::ConstOffsetsHostView;
114 typename adapter_t::user_t::nonconst_local_inds_host_view_type;
116 typename adapter_t::user_t::nonconst_values_host_view_type;
119 const auto nrows = matrix.getLocalNumRows();
120 const auto ncols = matrix.getLocalNumEntries();
121 const auto maxNumEntries = matrix.getLocalMaxNumRowEntries();
123 typename adapter_t::Base::ConstIdsHostView colIdsHost_(
"colIdsHost_", ncols);
124 typename adapter_t::Base::ConstOffsetsHostView offsHost_(
"offsHost_",
127 localInds_t localColInds(
"localColInds", maxNumEntries);
128 localVals_t localVals(
"localVals", maxNumEntries);
130 for (
size_t r = 0; r < nrows; r++) {
131 size_t numEntries = 0;
132 matrix.getLocalRowCopy(r, localColInds, localVals, numEntries);;
134 offsHost_(r + 1) = offsHost_(r) + numEntries;
135 for (
size_t e = offsHost_(r), i = 0; e < offsHost_(r + 1); e++) {
136 colIdsHost_(e) = matrix.getColMap()->getGlobalElement(localColInds(i++));
140 idsHost_t rowIdsHost;
141 ia.getRowIDsHostView(rowIdsHost);
143 const auto matrixIDS = matrix.getRowMap()->getLocalElementList();
147 idsHost_t colIdsHost;
148 offsetsHost_t offsetsHost;
149 ia.getCRSHostView(offsetsHost, colIdsHost);
155 template <
typename adapter_t,
typename matrix_t>
157 using idsDevice_t =
typename adapter_t::ConstIdsDeviceView;
158 using idsHost_t =
typename adapter_t::ConstIdsHostView;
159 using weightsDevice_t =
typename adapter_t::WeightsDeviceView1D;
160 using weightsHost_t =
typename adapter_t::WeightsHostView1D;
162 const auto nrows = ia.getLocalNumIDs();
172 idsDevice_t rowIdsDevice;
173 ia.getRowIDsDeviceView(rowIdsDevice);
174 idsHost_t rowIdsHost;
175 ia.getRowIDsHostView(rowIdsHost);
183 typename adapter_t::WeightsDeviceView1D{}, 50),
186 weightsDevice_t wgts0(
"wgts0", nrows);
187 Kokkos::parallel_for(
188 nrows, KOKKOS_LAMBDA(
const int idx) { wgts0(idx) = idx * 2; });
194 weightsDevice_t wgts1(
"wgts1", nrows);
195 Kokkos::parallel_for(
196 nrows, KOKKOS_LAMBDA(
const int idx) { wgts1(idx) = idx * 3; });
204 weightsDevice_t weightsDevice;
207 weightsHost_t weightsHost;
215 weightsDevice_t weightsDevice;
218 weightsHost_t weightsHost;
226 weightsDevice_t wgtsDevice;
230 weightsHost_t wgtsHost;
231 Z2_TEST_THROW(ia.getRowWeightsHostView(wgtsHost, 2), std::runtime_error);
239 int main(
int narg,
char *arg[]) {
243 Tpetra::ScopeGuard tscope(&narg, &arg);
244 const auto comm = Tpetra::getDefaultComm();
247 Teuchos::ParameterList params;
248 params.set(
"input file",
"simple");
249 params.set(
"file type",
"Chaco");
254 const auto crsMatrix = uinput->getUITpetraCrsMatrix();
255 const auto rowMatrix = rcp_dynamic_cast<
ztrowmatrix_t>(crsMatrix);
257 const auto nrows = rowMatrix->getLocalNumRows();
262 const int nWeights = 2;
271 auto tpetraRowMatrixInput = rcp(
new rowAdapter_t(rowMatrix, nWeights));
275 rowPart_t *p =
new rowPart_t[nrows];
276 memset(p, 0,
sizeof(rowPart_t) * nrows);
277 ArrayRCP<rowPart_t> solnParts(p, 0, nrows,
true);
279 rowSoln_t solution(env, comm, nWeights);
280 solution.setParts(solnParts);
283 tpetraRowMatrixInput->applyPartitioningSolution(*rowMatrix, mMigrate,
285 const auto newM = rcp(mMigrate);
289 PrintFromRoot(
"Input adapter for Tpetra::RowMatrix migrated to proc 0");
293 }
catch (std::exception &e) {
294 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)
Provides access for Zoltan2 to Tpetra::RowMatrix data.
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...
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.