22 #include <Teuchos_DefaultComm.hpp>
23 #include <Teuchos_RCP.hpp>
24 #include <Teuchos_Array.hpp>
25 #include <Teuchos_ArrayRCP.hpp>
26 #include <Teuchos_Comm.hpp>
27 #include <Teuchos_VerboseObject.hpp>
28 #include <Tpetra_CrsMatrix.hpp>
29 #include <Tpetra_Vector.hpp>
31 #ifdef HAVE_ZOLTAN_EPETRA
32 #include <Xpetra_EpetraUtils.hpp>
37 using Teuchos::ArrayRCP;
38 using Teuchos::ArrayView;
51 if (nglobalrows !=
size_t(maxgid - basegid + 1)){
52 std::cout <<
"Error: Map is invalid for test - fix test" << std::endl;
53 std::cerr <<
"Error: Map is invalid for test - fix test" << std::endl;
54 std::cout <<
"FAIL" << std::endl;
57 RCP<Array<zgno_t> > mygids = rcp(
new Array<zgno_t>);
59 if (firstzgno_t < basegid){
62 firstzgno_t = basegid - n + proc;
64 firstzgno_t = basegid;
66 for (
zgno_t gid=firstzgno_t; gid <= maxgid; gid+=nprocs){
67 (*mygids).append(gid);
70 ArrayRCP<zgno_t> newIdArcp = Teuchos::arcp(mygids);
75 #ifdef HAVE_EPETRA_DATA_TYPES
78 const Epetra_Comm &comm = emap.Comm();
79 int proc = comm.MyPID();
80 int nprocs = comm.NumProc();
81 zgno_t basegid = emap.MinAllGID();
82 zgno_t maxgid = emap.MaxAllGID();
83 size_t nglobalrows = emap.NumGlobalElements();
89 ArrayRCP<zgno_t>
roundRobinMap(
const Tpetra::Map<zlno_t, zgno_t, znode_t> &tmap)
91 const RCP<const Comm<int> > &comm = tmap.getComm();
92 int proc = comm->getRank();
93 int nprocs = comm->getSize();
94 zgno_t basegid = tmap.getMinAllGlobalIndex();
95 zgno_t maxgid = tmap.getMaxAllGlobalIndex();
96 size_t nglobalrows = tmap.getGlobalNumElements();
101 ArrayRCP<zgno_t>
roundRobinMap(
const Xpetra::Map<zlno_t, zgno_t, znode_t> &xmap)
103 const RCP<const Comm<int> > &comm = xmap.getComm();
104 int proc = comm->getRank();
105 int nprocs = comm->getSize();
106 zgno_t basegid = xmap.getMinAllGlobalIndex();
107 zgno_t maxgid = xmap.getMaxAllGlobalIndex();
108 size_t nglobalrows = xmap.getGlobalNumElements();
113 int main(
int narg,
char *arg[])
115 Tpetra::ScopeGuard tscope(&narg, &arg);
116 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
118 int rank = comm->getRank();
121 Teuchos::RCP<Teuchos::FancyOStream> outStream =
122 Teuchos::VerboseObjectBase::getDefaultOStream();
123 Teuchos::EVerbosityLevel v=Teuchos::VERB_EXTREME;
125 typedef Tpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t>
tmatrix_t;
126 typedef Tpetra::CrsGraph<zlno_t,zgno_t,znode_t>
tgraph_t;
127 typedef Tpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t>
tvector_t;
128 typedef Tpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> tmvector_t;
129 typedef Xpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t>
xmatrix_t;
130 typedef Xpetra::CrsGraph<zlno_t,zgno_t,znode_t>
xgraph_t;
131 typedef Xpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t>
xvector_t;
132 typedef Xpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> xmvector_t;
136 RCP<UserInputForTests> uinput;
137 Teuchos::ParameterList params;
138 params.set(
"input file",
"simple");
139 params.set(
"file type",
"Chaco");
144 catch(std::exception &e){
146 std::cout << e.what() << std::endl;
163 M = uinput->getUITpetraCrsMatrix();
165 catch(std::exception &e){
167 std::cout << e.what() << std::endl;
172 std::cout <<
"Original Tpetra matrix " << M->getGlobalNumRows()
173 <<
" x " << M->getGlobalNumCols() << std::endl;
175 M->describe(*outStream,v);
177 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(M->getRowMap()));
179 zgno_t localNumRows = newRowIds.size();
181 RCP<const tmatrix_t> newM;
184 localNumRows, newRowIds.getRawPtr());
186 catch(std::exception &e){
188 std::cout << e.what() << std::endl;
191 " Zoltan2::XpetraTraits<tmatrix_t>::doMigration ", 1);
194 std::cout <<
"Migrated Tpetra matrix" << std::endl;
196 newM->describe(*outStream,v);
204 G = uinput->getUITpetraCrsGraph();
206 catch(std::exception &e){
208 std::cout << e.what() << std::endl;
213 std::cout <<
"Original Tpetra graph" << std::endl;
215 G->describe(*outStream,v);
217 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(G->getRowMap()));
219 zgno_t localNumRows = newRowIds.size();
221 RCP<const tgraph_t> newG;
224 localNumRows, newRowIds.getRawPtr());
226 catch(std::exception &e){
228 std::cout << e.what() << std::endl;
231 " Zoltan2::XpetraTraits<tgraph_t>::doMigration ", 1);
234 std::cout <<
"Migrated Tpetra graph" << std::endl;
236 newG->describe(*outStream,v);
244 V = rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
247 catch(std::exception &e){
249 std::cout << e.what() << std::endl;
254 std::cout <<
"Original Tpetra vector" << std::endl;
256 V->describe(*outStream,v);
260 zgno_t localNumRows = newRowIds.size();
262 RCP<const tvector_t> newV;
265 localNumRows, newRowIds.getRawPtr());
267 catch(std::exception &e){
269 std::cout << e.what() << std::endl;
272 " Zoltan2::XpetraTraits<tvector_t>::doMigration ", 1);
275 std::cout <<
"Migrated Tpetra vector" << std::endl;
277 newV->describe(*outStream,v);
285 MV = rcp(
new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
288 catch(std::exception &e){
290 std::cout << e.what() << std::endl;
295 std::cout <<
"Original Tpetra multivector" << std::endl;
297 MV->describe(*outStream,v);
301 zgno_t localNumRows = newRowIds.size();
303 RCP<const tmvector_t> newMV;
306 localNumRows, newRowIds.getRawPtr());
308 catch(std::exception &e){
310 std::cout << e.what() << std::endl;
313 " Zoltan2::XpetraTraits<tmvector_t>::doMigration ", 1);
316 std::cout <<
"Migrated Tpetra multivector" << std::endl;
318 newMV->describe(*outStream,v);
333 M = uinput->getUIXpetraCrsMatrix();
335 catch(std::exception &e){
337 std::cout << e.what() << std::endl;
342 std::cout <<
"Original Xpetra matrix" << std::endl;
344 M->describe(*outStream,v);
346 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(M->getRowMap()));
348 zgno_t localNumRows = newRowIds.size();
350 RCP<const xmatrix_t> newM;
353 localNumRows, newRowIds.getRawPtr());
355 catch(std::exception &e){
357 std::cout << e.what() << std::endl;
360 " Zoltan2::XpetraTraits<xmatrix_t>::doMigration ", 1);
363 std::cout <<
"Migrated Xpetra matrix" << std::endl;
365 newM->describe(*outStream,v);
373 G = uinput->getUIXpetraCrsGraph();
375 catch(std::exception &e){
377 std::cout << e.what() << std::endl;
382 std::cout <<
"Original Xpetra graph" << std::endl;
384 G->describe(*outStream,v);
386 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(G->getRowMap()));
388 zgno_t localNumRows = newRowIds.size();
390 RCP<const xgraph_t> newG;
393 localNumRows, newRowIds.getRawPtr());
395 catch(std::exception &e){
397 std::cout << e.what() << std::endl;
400 " Zoltan2::XpetraTraits<xgraph_t>::doMigration ", 1);
403 std::cout <<
"Migrated Xpetra graph" << std::endl;
405 newG->describe(*outStream,v);
414 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
418 catch(std::exception &e){
420 std::cout << e.what() << std::endl;
425 std::cout <<
"Original Xpetra vector" << std::endl;
427 V->describe(*outStream,v);
431 zgno_t localNumRows = newRowIds.size();
433 RCP<const xvector_t> newV;
436 localNumRows, newRowIds.getRawPtr());
438 catch(std::exception &e){
440 std::cout << e.what() << std::endl;
443 " Zoltan2::XpetraTraits<xvector_t>::doMigration ", 1);
446 std::cout <<
"Migrated Xpetra vector" << std::endl;
448 newV->describe(*outStream,v);
456 RCP<tmvector_t> tMV =
457 rcp(
new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
461 catch(std::exception &e){
463 std::cout << e.what() << std::endl;
468 std::cout <<
"Original Xpetra multivector" << std::endl;
470 MV->describe(*outStream,v);
474 zgno_t localNumRows = newRowIds.size();
476 RCP<const xmvector_t> newMV;
479 localNumRows, newRowIds.getRawPtr());
481 catch(std::exception &e){
483 std::cout << e.what() << std::endl;
486 " Zoltan2::XpetraTraits<xmvector_t>::doMigration ", 1);
489 std::cout <<
"Migrated Xpetra multivector" << std::endl;
491 newMV->describe(*outStream,v);
494 #ifdef HAVE_EPETRA_DATA_TYPES
502 typedef Epetra_CrsMatrix ematrix_t;
503 typedef Epetra_CrsGraph egraph_t;
504 typedef Epetra_Vector evector_t;
505 typedef Epetra_MultiVector emvector_t;
506 typedef Epetra_BlockMap emap_t;
513 M = uinput->getUIEpetraCrsMatrix();
515 catch(std::exception &e){
517 std::cout << e.what() << std::endl;
522 std::cout <<
"Original Epetra matrix" << std::endl;
526 RCP<const emap_t> emap = Teuchos::rcpFromRef(M->RowMap());
529 zgno_t localNumRows = newRowIds.size();
531 RCP<const ematrix_t> newM;
534 localNumRows, newRowIds.getRawPtr());
536 catch(std::exception &e){
538 std::cout << e.what() << std::endl;
541 " Zoltan2::XpetraTraits<ematrix_t>::doMigration ", 1);
544 std::cout <<
"Migrated Epetra matrix" << std::endl;
546 newM->Print(std::cout);
554 G = uinput->getUIEpetraCrsGraph();
556 catch(std::exception &e){
558 std::cout << e.what() << std::endl;
563 std::cout <<
"Original Epetra graph" << std::endl;
567 RCP<const emap_t> emap = Teuchos::rcpFromRef(G->RowMap());
570 zgno_t localNumRows = newRowIds.size();
572 RCP<const egraph_t> newG;
575 localNumRows, newRowIds.getRawPtr());
577 catch(std::exception &e){
579 std::cout << e.what() << std::endl;
582 " Zoltan2::XpetraTraits<egraph_t>::doMigration ", 1);
585 std::cout <<
"Migrated Epetra graph" << std::endl;
587 newG->Print(std::cout);
595 V = rcp(
new Epetra_Vector(uinput->getUIEpetraCrsGraph()->RowMap()));
598 catch(std::exception &e){
600 std::cout << e.what() << std::endl;
605 std::cout <<
"Original Epetra vector" << std::endl;
609 RCP<const emap_t> emap = Teuchos::rcpFromRef(V->Map());
612 zgno_t localNumRows = newRowIds.size();
614 RCP<const evector_t> newV;
617 localNumRows, newRowIds.getRawPtr());
619 catch(std::exception &e){
621 std::cout << e.what() << std::endl;
624 " Zoltan2::XpetraTraits<evector_t>::doMigration ", 1);
627 std::cout <<
"Migrated Epetra vector" << std::endl;
629 newV->Print(std::cout);
638 rcp(
new Epetra_MultiVector(uinput->getUIEpetraCrsGraph()->RowMap(),3));
641 catch(std::exception &e){
643 std::cout << e.what() << std::endl;
648 std::cout <<
"Original Epetra multivector" << std::endl;
650 MV->Print(std::cout);
652 RCP<const emap_t> emap = Teuchos::rcpFromRef(MV->Map());
655 zgno_t localNumRows = newRowIds.size();
657 RCP<const emvector_t> newMV;
660 localNumRows, newRowIds.getRawPtr());
662 catch(std::exception &e){
664 std::cout << e.what() << std::endl;
667 " Zoltan2::XpetraTraits<emvector_t>::doMigration ", 1);
670 std::cout <<
"Migrated Epetra multivector" << std::endl;
672 newMV->Print(std::cout);
674 #endif // have epetra data types (int, int, double)
681 std::cout <<
"PASS" << std::endl;
ArrayRCP< zgno_t > roundRobinMapShared(int proc, int nprocs, zgno_t basegid, zgno_t maxgid, size_t nglobalrows)
#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.
int main(int narg, char **arg)
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.
Tpetra::Map::global_ordinal_type zgno_t