57 #include <Teuchos_DefaultComm.hpp>
58 #include <Teuchos_RCP.hpp>
59 #include <Teuchos_Array.hpp>
60 #include <Teuchos_ArrayRCP.hpp>
61 #include <Teuchos_Comm.hpp>
62 #include <Teuchos_VerboseObject.hpp>
63 #include <Tpetra_CrsMatrix.hpp>
64 #include <Tpetra_Vector.hpp>
66 #ifdef HAVE_ZOLTAN_EPETRA
67 #include <Xpetra_EpetraUtils.hpp>
72 using Teuchos::ArrayRCP;
73 using Teuchos::ArrayView;
86 if (nglobalrows !=
size_t(maxgid - basegid + 1)){
87 std::cout <<
"Error: Map is invalid for test - fix test" << std::endl;
88 std::cerr <<
"Error: Map is invalid for test - fix test" << std::endl;
89 std::cout <<
"FAIL" << std::endl;
92 RCP<Array<zgno_t> > mygids = rcp(
new Array<zgno_t>);
94 if (firstzgno_t < basegid){
97 firstzgno_t = basegid - n + proc;
99 firstzgno_t = basegid;
101 for (
zgno_t gid=firstzgno_t; gid <= maxgid; gid+=nprocs){
102 (*mygids).append(gid);
105 ArrayRCP<zgno_t> newIdArcp = Teuchos::arcp(mygids);
110 #ifdef HAVE_EPETRA_DATA_TYPES
113 const Epetra_Comm &comm = emap.Comm();
114 int proc = comm.MyPID();
115 int nprocs = comm.NumProc();
116 zgno_t basegid = emap.MinAllGID();
117 zgno_t maxgid = emap.MaxAllGID();
118 size_t nglobalrows = emap.NumGlobalElements();
124 ArrayRCP<zgno_t>
roundRobinMap(
const Tpetra::Map<zlno_t, zgno_t, znode_t> &tmap)
126 const RCP<const Comm<int> > &comm = tmap.getComm();
127 int proc = comm->getRank();
128 int nprocs = comm->getSize();
129 zgno_t basegid = tmap.getMinAllGlobalIndex();
130 zgno_t maxgid = tmap.getMaxAllGlobalIndex();
131 size_t nglobalrows = tmap.getGlobalNumElements();
136 ArrayRCP<zgno_t>
roundRobinMap(
const Xpetra::Map<zlno_t, zgno_t, znode_t> &xmap)
138 const RCP<const Comm<int> > &comm = xmap.getComm();
139 int proc = comm->getRank();
140 int nprocs = comm->getSize();
141 zgno_t basegid = xmap.getMinAllGlobalIndex();
142 zgno_t maxgid = xmap.getMaxAllGlobalIndex();
143 size_t nglobalrows = xmap.getGlobalNumElements();
148 int main(
int narg,
char *arg[])
150 Tpetra::ScopeGuard tscope(&narg, &arg);
151 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
153 int rank = comm->getRank();
156 Teuchos::RCP<Teuchos::FancyOStream> outStream =
157 Teuchos::VerboseObjectBase::getDefaultOStream();
158 Teuchos::EVerbosityLevel v=Teuchos::VERB_EXTREME;
160 typedef Tpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t>
tmatrix_t;
161 typedef Tpetra::CrsGraph<zlno_t,zgno_t,znode_t>
tgraph_t;
162 typedef Tpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t>
tvector_t;
163 typedef Tpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> tmvector_t;
164 typedef Xpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t>
xmatrix_t;
165 typedef Xpetra::CrsGraph<zlno_t,zgno_t,znode_t>
xgraph_t;
166 typedef Xpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t>
xvector_t;
167 typedef Xpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> xmvector_t;
171 RCP<UserInputForTests> uinput;
172 Teuchos::ParameterList params;
173 params.set(
"input file",
"simple");
174 params.set(
"file type",
"Chaco");
179 catch(std::exception &e){
181 std::cout << e.what() << std::endl;
198 M = uinput->getUITpetraCrsMatrix();
200 catch(std::exception &e){
202 std::cout << e.what() << std::endl;
207 std::cout <<
"Original Tpetra matrix " << M->getGlobalNumRows()
208 <<
" x " << M->getGlobalNumCols() << std::endl;
210 M->describe(*outStream,v);
212 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(M->getRowMap()));
214 zgno_t localNumRows = newRowIds.size();
216 RCP<const tmatrix_t> newM;
219 localNumRows, newRowIds.getRawPtr());
221 catch(std::exception &e){
223 std::cout << e.what() << std::endl;
226 " Zoltan2::XpetraTraits<tmatrix_t>::doMigration ", 1);
229 std::cout <<
"Migrated Tpetra matrix" << std::endl;
231 newM->describe(*outStream,v);
239 G = uinput->getUITpetraCrsGraph();
241 catch(std::exception &e){
243 std::cout << e.what() << std::endl;
248 std::cout <<
"Original Tpetra graph" << std::endl;
250 G->describe(*outStream,v);
252 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(G->getRowMap()));
254 zgno_t localNumRows = newRowIds.size();
256 RCP<const tgraph_t> newG;
259 localNumRows, newRowIds.getRawPtr());
261 catch(std::exception &e){
263 std::cout << e.what() << std::endl;
266 " Zoltan2::XpetraTraits<tgraph_t>::doMigration ", 1);
269 std::cout <<
"Migrated Tpetra graph" << std::endl;
271 newG->describe(*outStream,v);
279 V = rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
282 catch(std::exception &e){
284 std::cout << e.what() << std::endl;
289 std::cout <<
"Original Tpetra vector" << std::endl;
291 V->describe(*outStream,v);
295 zgno_t localNumRows = newRowIds.size();
297 RCP<const tvector_t> newV;
300 localNumRows, newRowIds.getRawPtr());
302 catch(std::exception &e){
304 std::cout << e.what() << std::endl;
307 " Zoltan2::XpetraTraits<tvector_t>::doMigration ", 1);
310 std::cout <<
"Migrated Tpetra vector" << std::endl;
312 newV->describe(*outStream,v);
320 MV = rcp(
new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
323 catch(std::exception &e){
325 std::cout << e.what() << std::endl;
330 std::cout <<
"Original Tpetra multivector" << std::endl;
332 MV->describe(*outStream,v);
336 zgno_t localNumRows = newRowIds.size();
338 RCP<const tmvector_t> newMV;
341 localNumRows, newRowIds.getRawPtr());
343 catch(std::exception &e){
345 std::cout << e.what() << std::endl;
348 " Zoltan2::XpetraTraits<tmvector_t>::doMigration ", 1);
351 std::cout <<
"Migrated Tpetra multivector" << std::endl;
353 newMV->describe(*outStream,v);
368 M = uinput->getUIXpetraCrsMatrix();
370 catch(std::exception &e){
372 std::cout << e.what() << std::endl;
377 std::cout <<
"Original Xpetra matrix" << std::endl;
379 M->describe(*outStream,v);
381 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(M->getRowMap()));
383 zgno_t localNumRows = newRowIds.size();
385 RCP<const xmatrix_t> newM;
388 localNumRows, newRowIds.getRawPtr());
390 catch(std::exception &e){
392 std::cout << e.what() << std::endl;
395 " Zoltan2::XpetraTraits<xmatrix_t>::doMigration ", 1);
398 std::cout <<
"Migrated Xpetra matrix" << std::endl;
400 newM->describe(*outStream,v);
408 G = uinput->getUIXpetraCrsGraph();
410 catch(std::exception &e){
412 std::cout << e.what() << std::endl;
417 std::cout <<
"Original Xpetra graph" << std::endl;
419 G->describe(*outStream,v);
421 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(G->getRowMap()));
423 zgno_t localNumRows = newRowIds.size();
425 RCP<const xgraph_t> newG;
428 localNumRows, newRowIds.getRawPtr());
430 catch(std::exception &e){
432 std::cout << e.what() << std::endl;
435 " Zoltan2::XpetraTraits<xgraph_t>::doMigration ", 1);
438 std::cout <<
"Migrated Xpetra graph" << std::endl;
440 newG->describe(*outStream,v);
449 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
453 catch(std::exception &e){
455 std::cout << e.what() << std::endl;
460 std::cout <<
"Original Xpetra vector" << std::endl;
462 V->describe(*outStream,v);
466 zgno_t localNumRows = newRowIds.size();
468 RCP<const xvector_t> newV;
471 localNumRows, newRowIds.getRawPtr());
473 catch(std::exception &e){
475 std::cout << e.what() << std::endl;
478 " Zoltan2::XpetraTraits<xvector_t>::doMigration ", 1);
481 std::cout <<
"Migrated Xpetra vector" << std::endl;
483 newV->describe(*outStream,v);
491 RCP<tmvector_t> tMV =
492 rcp(
new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
496 catch(std::exception &e){
498 std::cout << e.what() << std::endl;
503 std::cout <<
"Original Xpetra multivector" << std::endl;
505 MV->describe(*outStream,v);
509 zgno_t localNumRows = newRowIds.size();
511 RCP<const xmvector_t> newMV;
514 localNumRows, newRowIds.getRawPtr());
516 catch(std::exception &e){
518 std::cout << e.what() << std::endl;
521 " Zoltan2::XpetraTraits<xmvector_t>::doMigration ", 1);
524 std::cout <<
"Migrated Xpetra multivector" << std::endl;
526 newMV->describe(*outStream,v);
529 #ifdef HAVE_EPETRA_DATA_TYPES
537 typedef Epetra_CrsMatrix ematrix_t;
538 typedef Epetra_CrsGraph egraph_t;
539 typedef Epetra_Vector evector_t;
540 typedef Epetra_MultiVector emvector_t;
541 typedef Epetra_BlockMap emap_t;
548 M = uinput->getUIEpetraCrsMatrix();
550 catch(std::exception &e){
552 std::cout << e.what() << std::endl;
557 std::cout <<
"Original Epetra matrix" << std::endl;
561 RCP<const emap_t> emap = Teuchos::rcpFromRef(M->RowMap());
564 zgno_t localNumRows = newRowIds.size();
566 RCP<const ematrix_t> newM;
569 localNumRows, newRowIds.getRawPtr());
571 catch(std::exception &e){
573 std::cout << e.what() << std::endl;
576 " Zoltan2::XpetraTraits<ematrix_t>::doMigration ", 1);
579 std::cout <<
"Migrated Epetra matrix" << std::endl;
581 newM->Print(std::cout);
589 G = uinput->getUIEpetraCrsGraph();
591 catch(std::exception &e){
593 std::cout << e.what() << std::endl;
598 std::cout <<
"Original Epetra graph" << std::endl;
602 RCP<const emap_t> emap = Teuchos::rcpFromRef(G->RowMap());
605 zgno_t localNumRows = newRowIds.size();
607 RCP<const egraph_t> newG;
610 localNumRows, newRowIds.getRawPtr());
612 catch(std::exception &e){
614 std::cout << e.what() << std::endl;
617 " Zoltan2::XpetraTraits<egraph_t>::doMigration ", 1);
620 std::cout <<
"Migrated Epetra graph" << std::endl;
622 newG->Print(std::cout);
630 V = rcp(
new Epetra_Vector(uinput->getUIEpetraCrsGraph()->RowMap()));
633 catch(std::exception &e){
635 std::cout << e.what() << std::endl;
640 std::cout <<
"Original Epetra vector" << std::endl;
644 RCP<const emap_t> emap = Teuchos::rcpFromRef(V->Map());
647 zgno_t localNumRows = newRowIds.size();
649 RCP<const evector_t> newV;
652 localNumRows, newRowIds.getRawPtr());
654 catch(std::exception &e){
656 std::cout << e.what() << std::endl;
659 " Zoltan2::XpetraTraits<evector_t>::doMigration ", 1);
662 std::cout <<
"Migrated Epetra vector" << std::endl;
664 newV->Print(std::cout);
673 rcp(
new Epetra_MultiVector(uinput->getUIEpetraCrsGraph()->RowMap(),3));
676 catch(std::exception &e){
678 std::cout << e.what() << std::endl;
683 std::cout <<
"Original Epetra multivector" << std::endl;
685 MV->Print(std::cout);
687 RCP<const emap_t> emap = Teuchos::rcpFromRef(MV->Map());
690 zgno_t localNumRows = newRowIds.size();
692 RCP<const emvector_t> newMV;
695 localNumRows, newRowIds.getRawPtr());
697 catch(std::exception &e){
699 std::cout << e.what() << std::endl;
702 " Zoltan2::XpetraTraits<emvector_t>::doMigration ", 1);
705 std::cout <<
"Migrated Epetra multivector" << std::endl;
707 newMV->Print(std::cout);
709 #endif // have epetra data types (int, int, double)
716 std::cout <<
"PASS" << std::endl;
ArrayRCP< zgno_t > roundRobinMapShared(int proc, int nprocs, zgno_t basegid, zgno_t maxgid, size_t nglobalrows)
int main(int narg, char *arg[])
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
static RCP< User > doMigration(const User &from, size_t numLocalRows, const gno_t *myNewRows)
Migrate the object Given a user object and a new row distribution, create and return a new user objec...
Traits of Xpetra classes, including migration method.
common code used by tests
ArrayRCP< zgno_t > roundRobinMap(const Tpetra::Map< zlno_t, zgno_t, znode_t > &tmap)
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.