24#include <Teuchos_DefaultComm.hpp>
25#include <Teuchos_RCP.hpp>
26#include <Teuchos_Comm.hpp>
27#include <Teuchos_CommHelpers.hpp>
31using Teuchos::rcp_const_cast;
34typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
tmatrix_t;
35typedef Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
xmatrix_t;
42template<
typename offset_t>
44 const zgno_t *primaryIds,
const offset_t *offsets,
const zgno_t *secondaryIds,
Type type)
46 const auto rank = comm->getRank();
47 const auto nprocs = comm->getSize();
48 const std::string primaryIdName = type ==
Type::CRS ?
"row" :
"col";
52 for (
int p=0; p < nprocs; p++){
54 std::cout << rank <<
":" << std::endl;
55 for (
zlno_t i=0; i < nPrimaryIds; i++){
56 std::cout <<
" " << primaryIdName <<
" " << primaryIds[i] <<
": ";
57 for (offset_t j=offsets[i]; j < offsets[i+1]; j++){
58 std::cout << secondaryIds[j] <<
" ";
60 std::cout << std::endl;
69template <
typename User>
75 RCP<const Comm<int> > comm = M.getComm();
76 int fail = 0, gfail=0;
81 if (M.getLocalNumRows()){
89 ArrayRCP<const zgno_t> colIds;
90 ArrayRCP<const offset_t> offsets;
99 if (nrows != M.getLocalNumRows())
113 const zgno_t *colIds2=
nullptr;
116 ArrayRCP<const zgno_t> ccsRowIds;
117 ArrayRCP<const offset_t> ccsOffsets;
128 Tpetra::ScopeGuard tscope(&narg, &arg);
129 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
131 int rank = comm->getRank();
132 int fail = 0, gfail=0;
138 RCP<UserInputForTests> uinput;
139 Teuchos::ParameterList params;
140 params.set(
"input file",
"simple");
141 params.set(
"file type",
"Chaco");
146 catch(std::exception &e){
148 std::cout << e.what() << std::endl;
155 tM = uinput->getUITpetraCrsMatrix();
156 size_t nrows = tM->getLocalNumRows();
166 typedef adapter_t::part_t
part_t;
169 memset(p, 0,
sizeof(
part_t) * nrows);
170 ArrayRCP<part_t> solnParts(p, 0, nrows,
true);
172 soln_t solution(env, comm, nWeights);
173 solution.setParts(solnParts);
179 std::cout <<
"Input adapter for Tpetra::CrsMatrix" << std::endl;
181 RCP<const tmatrix_t> ctM = rcp_const_cast<const tmatrix_t>(tM);
182 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > tMInput;
188 catch (std::exception &e){
190 std::cout << e.what() << std::endl;
201 tMInput->applyPartitioningSolution(*tM, mMigrate, solution);
202 newM = rcp(mMigrate);
204 catch (std::exception &e){
206 std::cout <<
"Error caught: " << e.what() << std::endl;
212 RCP<const tmatrix_t> cnewM = rcp_const_cast<const tmatrix_t>(newM);
213 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > newInput;
217 catch (std::exception &e){
219 std::cout << e.what() << std::endl;
225 "Input adapter for Tpetra::CrsMatrix migrated to proc 0" <<
243 std::cout <<
"Input adapter for Xpetra::CrsMatrix" << std::endl;
245 RCP<xmatrix_t> xM = uinput->getUIXpetraCrsMatrix();
246 RCP<const xmatrix_t> cxM = rcp_const_cast<const xmatrix_t>(xM);
247 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > xMInput;
253 catch (std::exception &e){
255 std::cout << e.what() << std::endl;
266 xMInput->applyPartitioningSolution(*xM, mMigrate, solution);
268 catch (std::exception &e){
269 std::cout <<
"Error caught: " << e.what() << std::endl;
276 RCP<const xmatrix_t> cnewM(mMigrate);
277 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > newInput;
282 catch (std::exception &e){
284 std::cout << e.what() << std::endl;
290 "Input adapter for Xpetra::CrsMatrix migrated to proc 0" <<
307 std::cout <<
"PASS" << std::endl;
int globalFail(const Comm< int > &comm, int fail)
void printFailureCode(const Comm< int > &comm, int fail)
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
common code used by tests
Tpetra::Map ::local_ordinal_type zlno_t
Tpetra::Map ::global_ordinal_type zgno_t
Defines the XpetraCrsMatrixAdapter class.
The user parameters, debug, timing and memory profiling output objects, and error checking methods.
A PartitioningSolution is a solution to a partitioning problem.
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
void getCRSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &colIds) const
void getRowIDsView(const gno_t *&rowIds) const
size_t getLocalNumColumns() const
Returns the number of columns on this process.
void getCCSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &rowIds) const override
void getColumnIDsView(const gno_t *&colIds) const
size_t getLocalNumRows() const
Returns the number of rows on this process.
static const std::string fail
SparseMatrixAdapter_t::part_t part_t