59 #include <Teuchos_DefaultComm.hpp>
60 #include <Teuchos_RCP.hpp>
61 #include <Teuchos_Comm.hpp>
62 #include <Teuchos_CommHelpers.hpp>
66 using Teuchos::rcp_const_cast;
69 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
tmatrix_t;
70 typedef Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
xmatrix_t;
72 template<
typename offset_t>
74 const zgno_t *rowIds,
const offset_t *offsets,
const zgno_t *colIds)
76 int rank = comm->getRank();
77 int nprocs = comm->getSize();
79 for (
int p=0; p < nprocs; p++){
81 std::cout << rank <<
":" << std::endl;
82 for (
zlno_t i=0; i < nrows; i++){
83 std::cout <<
" row " << rowIds[i] <<
": ";
84 for (offset_t j=offsets[i]; j < offsets[i+1]; j++){
85 std::cout << colIds[j] <<
" ";
87 std::cout << std::endl;
96 template <
typename User>
102 RCP<const Comm<int> > comm = M.getComm();
103 int fail = 0, gfail=0;
108 if (M.getNodeNumRows()){
115 const zgno_t *rowIds=NULL, *colIds=NULL;
116 const offset_t *offsets=NULL;
125 if (nrows != M.getNodeNumRows())
131 printMatrix<offset_t>(comm, nrows, rowIds, offsets, colIds);
134 if (!fail) fail = 10;
140 int main(
int narg,
char *arg[])
142 Tpetra::ScopeGuard tscope(&narg, &arg);
143 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
145 int rank = comm->getRank();
146 int fail = 0, gfail=0;
152 RCP<UserInputForTests> uinput;
153 Teuchos::ParameterList params;
154 params.set(
"input file",
"simple");
155 params.set(
"file type",
"Chaco");
160 catch(std::exception &e){
162 std::cout << e.what() << std::endl;
169 tM = uinput->getUITpetraCrsMatrix();
170 size_t nrows = tM->getNodeNumRows();
182 part_t *p =
new part_t [nrows];
183 memset(p, 0,
sizeof(part_t) * nrows);
184 ArrayRCP<part_t> solnParts(p, 0, nrows,
true);
186 soln_t solution(env, comm, nWeights);
187 solution.setParts(solnParts);
193 std::cout <<
"Input adapter for Tpetra::CrsMatrix" << std::endl;
195 RCP<const tmatrix_t> ctM = rcp_const_cast<
const tmatrix_t>(tM);
196 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > tMInput;
202 catch (std::exception &e){
204 std::cout << e.what() << std::endl;
208 fail = verifyInputAdapter<tmatrix_t>(*tMInput, *tM);
215 tMInput->applyPartitioningSolution(*tM, mMigrate, solution);
216 newM = rcp(mMigrate);
218 catch (std::exception &e){
220 std::cout <<
"Error caught: " << e.what() << std::endl;
226 RCP<const tmatrix_t> cnewM = rcp_const_cast<
const tmatrix_t>(newM);
227 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > newInput;
231 catch (std::exception &e){
233 std::cout << e.what() << std::endl;
239 "Input adapter for Tpetra::CrsMatrix migrated to proc 0" <<
242 fail = verifyInputAdapter<tmatrix_t>(*newInput, *newM);
243 if (fail) fail += 100;
256 std::cout <<
"Input adapter for Xpetra::CrsMatrix" << std::endl;
258 RCP<xmatrix_t> xM = uinput->getUIXpetraCrsMatrix();
259 RCP<const xmatrix_t> cxM = rcp_const_cast<
const xmatrix_t>(xM);
260 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > xMInput;
266 catch (std::exception &e){
268 std::cout << e.what() << std::endl;
272 fail = verifyInputAdapter<xmatrix_t>(*xMInput, *tM);
279 xMInput->applyPartitioningSolution(*xM, mMigrate, solution);
281 catch (std::exception &e){
282 std::cout <<
"Error caught: " << e.what() << std::endl;
289 RCP<const xmatrix_t> cnewM(mMigrate);
290 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > newInput;
295 catch (std::exception &e){
297 std::cout << e.what() << std::endl;
303 "Input adapter for Xpetra::CrsMatrix migrated to proc 0" <<
306 fail = verifyInputAdapter<xmatrix_t>(*newInput, *newM);
307 if (fail) fail += 100;
316 #ifdef HAVE_EPETRA_DATA_TYPES
319 typedef Epetra_CrsMatrix ematrix_t;
322 std::cout <<
"Input adapter for Epetra_CrsMatrix" << std::endl;
324 RCP<ematrix_t> eM = uinput->getUIEpetraCrsMatrix();
325 RCP<const ematrix_t> ceM = rcp_const_cast<
const ematrix_t>(eM);
326 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > eMInput;
328 bool goodAdapter =
true;
333 catch (std::exception &e){
334 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
337 std::cout << e.what() << std::endl;
342 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;"
343 <<
" Skipping this test." << std::endl;
344 std::cout <<
"FYI: Here's the exception message: " << std::endl
345 << e.what() << std::endl;
352 fail = verifyInputAdapter<ematrix_t>(*eMInput, *tM);
357 ematrix_t *mMigrate =NULL;
359 eMInput->applyPartitioningSolution(*eM, mMigrate, solution);
361 catch (std::exception &e){
362 std::cout <<
"Error caught: " << e.what() << std::endl;
369 RCP<const ematrix_t> cnewM(mMigrate,
true);
370 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > newInput;
375 catch (std::exception &e){
377 std::cout << e.what() << std::endl;
383 "Input adapter for Epetra_CrsMatrix migrated to proc 0" <<
386 fail = verifyInputAdapter<ematrix_t>(*newInput, *newM);
387 if (fail) fail += 100;
402 std::cout <<
"PASS" << std::endl;
void printFailureCode(const Comm< int > &comm, int fail)
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
int main(int narg, char *arg[])
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
size_t getLocalNumColumns() const
Returns the number of columns on this process.
common code used by tests
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.
void getCRSView(const offset_t *&offsets, const gno_t *&colIds) const
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
static const std::string fail
int globalFail(const Comm< int > &comm, int fail)
void getRowIDsView(const gno_t *&rowIds) const