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);
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;
159 catch(std::exception &e){
161 std::cout << e.what() << std::endl;
168 tM = uinput->getUITpetraCrsMatrix();
169 size_t nrows = tM->getNodeNumRows();
182 memset(p, 0,
sizeof(
part_t) * nrows);
183 ArrayRCP<part_t> solnParts(p, 0, nrows,
true);
185 soln_t solution(env, comm, nWeights);
186 solution.setParts(solnParts);
192 std::cout <<
"Input adapter for Tpetra::CrsMatrix" << std::endl;
194 RCP<const tmatrix_t> ctM = rcp_const_cast<const tmatrix_t>(tM);
195 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > tMInput;
201 catch (std::exception &e){
203 std::cout << e.what() << std::endl;
207 fail = verifyInputAdapter<tmatrix_t>(*tMInput, *tM);
214 tMInput->applyPartitioningSolution(*tM, mMigrate, solution);
215 newM = rcp(mMigrate);
217 catch (std::exception &e){
219 std::cout <<
"Error caught: " << e.what() << std::endl;
225 RCP<const tmatrix_t> cnewM = rcp_const_cast<const tmatrix_t>(newM);
226 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > newInput;
230 catch (std::exception &e){
232 std::cout << e.what() << std::endl;
238 "Input adapter for Tpetra::CrsMatrix migrated to proc 0" <<
241 fail = verifyInputAdapter<tmatrix_t>(*newInput, *newM);
255 std::cout <<
"Input adapter for Xpetra::CrsMatrix" << std::endl;
257 RCP<xmatrix_t> xM = uinput->getUIXpetraCrsMatrix();
258 RCP<const xmatrix_t> cxM = rcp_const_cast<const xmatrix_t>(xM);
259 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > xMInput;
265 catch (std::exception &e){
267 std::cout << e.what() << std::endl;
271 fail = verifyInputAdapter<xmatrix_t>(*xMInput, *tM);
278 xMInput->applyPartitioningSolution(*xM, mMigrate, solution);
280 catch (std::exception &e){
281 std::cout <<
"Error caught: " << e.what() << std::endl;
288 RCP<const xmatrix_t> cnewM(mMigrate);
289 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > newInput;
294 catch (std::exception &e){
296 std::cout << e.what() << std::endl;
302 "Input adapter for Xpetra::CrsMatrix migrated to proc 0" <<
305 fail = verifyInputAdapter<xmatrix_t>(*newInput, *newM);
315 #ifdef HAVE_EPETRA_DATA_TYPES
318 typedef Epetra_CrsMatrix ematrix_t;
321 std::cout <<
"Input adapter for Epetra_CrsMatrix" << std::endl;
323 RCP<ematrix_t> eM = uinput->getUIEpetraCrsMatrix();
324 RCP<const ematrix_t> ceM = rcp_const_cast<const ematrix_t>(eM);
325 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > eMInput;
327 bool goodAdapter =
true;
332 catch (std::exception &e){
333 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
336 std::cout << e.what() << std::endl;
341 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;"
342 <<
" Skipping this test." << std::endl;
343 std::cout <<
"FYI: Here's the exception message: " << std::endl
344 << e.what() << std::endl;
351 fail = verifyInputAdapter<ematrix_t>(*eMInput, *tM);
356 ematrix_t *mMigrate =NULL;
358 eMInput->applyPartitioningSolution(*eM, mMigrate, solution);
360 catch (std::exception &e){
361 std::cout <<
"Error caught: " << e.what() << std::endl;
368 RCP<const ematrix_t> cnewM(mMigrate,
true);
369 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > newInput;
374 catch (std::exception &e){
376 std::cout << e.what() << std::endl;
382 "Input adapter for Epetra_CrsMatrix migrated to proc 0" <<
385 fail = verifyInputAdapter<ematrix_t>(*newInput, *newM);
401 std::cout <<
"PASS" << std::endl;