24 #include <Teuchos_DefaultComm.hpp>
25 #include <Teuchos_RCP.hpp>
26 #include <Teuchos_Comm.hpp>
27 #include <Teuchos_CommHelpers.hpp>
31 using Teuchos::rcp_const_cast;
34 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
tmatrix_t;
35 typedef Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
xmatrix_t;
42 template<
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;
69 template <
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())
105 printMatrix<offset_t>(comm, nrows, rowIds, offsets.getRawPtr(),
109 if (!fail) fail = 10;
113 const zgno_t *colIds2=
nullptr;
116 ArrayRCP<const zgno_t> ccsRowIds;
117 ArrayRCP<const offset_t> ccsOffsets;
120 printMatrix<offset_t>(comm, nCols, colIds2, ccsOffsets.getRawPtr(),
126 int main(
int narg,
char *arg[])
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();
168 part_t *p =
new part_t [nrows];
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;
194 fail = verifyInputAdapter<tmatrix_t>(*tMInput, *tM);
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" <<
228 fail = verifyInputAdapter<tmatrix_t>(*newInput, *newM);
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;
259 fail = verifyInputAdapter<xmatrix_t>(*xMInput, *tM);
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" <<
293 fail = verifyInputAdapter<xmatrix_t>(*newInput, *newM);
294 if (fail) fail += 100;
303 #ifdef HAVE_EPETRA_DATA_TYPES
306 typedef Epetra_CrsMatrix ematrix_t;
309 std::cout <<
"Input adapter for Epetra_CrsMatrix" << std::endl;
311 RCP<ematrix_t> eM = uinput->getUIEpetraCrsMatrix();
312 RCP<const ematrix_t> ceM = rcp_const_cast<
const ematrix_t>(eM);
313 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > eMInput;
315 bool goodAdapter =
true;
320 catch (std::exception &e){
321 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
324 std::cout << e.what() << std::endl;
329 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;"
330 <<
" Skipping this test." << std::endl;
331 std::cout <<
"FYI: Here's the exception message: " << std::endl
332 << e.what() << std::endl;
339 fail = verifyInputAdapter<ematrix_t>(*eMInput, *tM);
344 ematrix_t *mMigrate =NULL;
346 eMInput->applyPartitioningSolution(*eM, mMigrate, solution);
348 catch (std::exception &e){
349 std::cout <<
"Error caught: " << e.what() << std::endl;
356 RCP<const ematrix_t> cnewM(mMigrate,
true);
357 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > newInput;
362 catch (std::exception &e){
364 std::cout << e.what() << std::endl;
370 "Input adapter for Epetra_CrsMatrix migrated to proc 0" <<
373 fail = verifyInputAdapter<ematrix_t>(*newInput, *newM);
374 if (fail) fail += 100;
389 std::cout <<
"PASS" << std::endl;
void printFailureCode(const Comm< int > &comm, int fail)
void getColumnIDsView(const gno_t *&colIds) const
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
size_t getLocalNumColumns() const
Returns the number of columns on this process.
void getCRSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &colIds) const
int main(int narg, char **arg)
common code used by tests
void getCCSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &rowIds) const override
SparseMatrixAdapter_t::part_t part_t
Defines the XpetraCrsMatrixAdapter class.
A PartitioningSolution is a solution to a partitioning problem.
size_t getLocalNumRows() const
Returns the number of rows on this process.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
Tpetra::Map::local_ordinal_type zlno_t
static const std::string fail
int globalFail(const Comm< int > &comm, int fail)
Tpetra::Map::global_ordinal_type zgno_t
void getRowIDsView(const gno_t *&rowIds) const