57 #include <Teuchos_GlobalMPISession.hpp> 58 #include <Teuchos_DefaultComm.hpp> 59 #include <Teuchos_RCP.hpp> 60 #include <Teuchos_Array.hpp> 61 #include <Teuchos_ArrayRCP.hpp> 62 #include <Teuchos_Comm.hpp> 63 #include <Teuchos_VerboseObject.hpp> 64 #include <Tpetra_CrsMatrix.hpp> 65 #include <Tpetra_Vector.hpp> 67 #ifdef HAVE_ZOLTAN_EPETRA 68 #include <Xpetra_EpetraUtils.hpp> 74 using Teuchos::ArrayRCP;
75 using Teuchos::ArrayView;
81 const RCP<
const Xpetra::Map<zlno_t, zgno_t, znode_t> > &m)
83 const RCP<const Comm<int> > &comm = m->getComm();
84 int proc = comm->getRank();
85 int nprocs = comm->getSize();
86 zgno_t base = m->getMinAllGlobalIndex();
87 zgno_t max = m->getMaxAllGlobalIndex();
88 size_t globalrows = m->getGlobalNumElements();
89 if (globalrows !=
size_t(max - base + 1)){
92 RCP<Array<zgno_t> > mygids = rcp(
new Array<zgno_t>);
94 if (firstzgno_t < base){
97 firstzgno_t = base - n + proc;
101 for (
zgno_t gid=firstzgno_t; gid <= max; gid+=nprocs){
102 (*mygids).append(gid);
105 ArrayRCP<zgno_t> newIdArcp = Teuchos::arcp(mygids);
110 int main(
int argc,
char *argv[])
112 Teuchos::GlobalMPISession session(&argc, &argv);
113 RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
114 int rank = comm->getRank();
117 Teuchos::RCP<Teuchos::FancyOStream> outStream =
118 Teuchos::VerboseObjectBase::getDefaultOStream();
119 Teuchos::EVerbosityLevel v=Teuchos::VERB_EXTREME;
121 typedef Tpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t>
tmatrix_t;
122 typedef Tpetra::CrsGraph<zlno_t,zgno_t,znode_t>
tgraph_t;
123 typedef Tpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t>
tvector_t;
124 typedef Tpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> tmvector_t;
125 typedef Xpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t>
xmatrix_t;
126 typedef Xpetra::CrsGraph<zlno_t,zgno_t,znode_t>
xgraph_t;
127 typedef Xpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t>
xvector_t;
128 typedef Xpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> xmvector_t;
129 typedef Xpetra::TpetraMap<zlno_t,zgno_t,znode_t> xtmap_t;
133 RCP<UserInputForTests> uinput;
139 catch(std::exception &e){
141 std::cout << e.what() << std::endl;
157 M = uinput->getUITpetraCrsMatrix();
159 catch(std::exception &e){
161 std::cout << e.what() << std::endl;
166 std::cout <<
"Original Tpetra matrix " << M->getGlobalNumRows()
167 <<
" x " << M->getGlobalNumCols() << std::endl;
169 M->describe(*outStream,v);
171 RCP<const xtmap_t> xmap(
new xtmap_t(M->getRowMap()));
175 zgno_t localNumRows = newRowIds.size();
177 RCP<const tmatrix_t> newM;
180 localNumRows, newRowIds.getRawPtr());
182 catch(std::exception &e){
184 std::cout << e.what() << std::endl;
187 " Zoltan2::XpetraTraits<tmatrix_t>::doMigration ", 1);
190 std::cout <<
"Migrated Tpetra matrix" << std::endl;
192 newM->describe(*outStream,v);
200 G = uinput->getUITpetraCrsGraph();
202 catch(std::exception &e){
204 std::cout << e.what() << std::endl;
209 std::cout <<
"Original Tpetra graph" << std::endl;
211 G->describe(*outStream,v);
213 RCP<const xtmap_t> xmap(
new xtmap_t(G->getRowMap()));
216 zgno_t localNumRows = newRowIds.size();
218 RCP<const tgraph_t> newG;
221 localNumRows, newRowIds.getRawPtr());
223 catch(std::exception &e){
225 std::cout << e.what() << std::endl;
228 " Zoltan2::XpetraTraits<tgraph_t>::doMigration ", 1);
231 std::cout <<
"Migrated Tpetra graph" << std::endl;
233 newG->describe(*outStream,v);
241 V = rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
244 catch(std::exception &e){
246 std::cout << e.what() << std::endl;
251 std::cout <<
"Original Tpetra vector" << std::endl;
253 V->describe(*outStream,v);
255 RCP<const xtmap_t> xmap(
new xtmap_t(V->getMap()));
258 zgno_t localNumRows = newRowIds.size();
260 RCP<const tvector_t> newV;
263 localNumRows, newRowIds.getRawPtr());
265 catch(std::exception &e){
267 std::cout << e.what() << std::endl;
270 " Zoltan2::XpetraTraits<tvector_t>::doMigration ", 1);
273 std::cout <<
"Migrated Tpetra vector" << std::endl;
275 newV->describe(*outStream,v);
283 MV = rcp(
new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
286 catch(std::exception &e){
288 std::cout << e.what() << std::endl;
293 std::cout <<
"Original Tpetra multivector" << std::endl;
295 MV->describe(*outStream,v);
297 RCP<const xtmap_t> xmap(
new xtmap_t(MV->getMap()));
300 zgno_t localNumRows = newRowIds.size();
302 RCP<const tmvector_t> newMV;
305 localNumRows, newRowIds.getRawPtr());
307 catch(std::exception &e){
309 std::cout << e.what() << std::endl;
312 " Zoltan2::XpetraTraits<tmvector_t>::doMigration ", 1);
315 std::cout <<
"Migrated Tpetra multivector" << std::endl;
317 newMV->describe(*outStream,v);
332 M = uinput->getUIXpetraCrsMatrix();
334 catch(std::exception &e){
336 std::cout << e.what() << std::endl;
341 std::cout <<
"Original Xpetra matrix" << std::endl;
343 M->describe(*outStream,v);
347 zgno_t localNumRows = newRowIds.size();
349 RCP<const xmatrix_t> newM;
352 localNumRows, newRowIds.getRawPtr());
354 catch(std::exception &e){
356 std::cout << e.what() << std::endl;
359 " Zoltan2::XpetraTraits<xmatrix_t>::doMigration ", 1);
362 std::cout <<
"Migrated Xpetra matrix" << std::endl;
364 newM->describe(*outStream,v);
372 G = uinput->getUIXpetraCrsGraph();
374 catch(std::exception &e){
376 std::cout << e.what() << std::endl;
381 std::cout <<
"Original Xpetra graph" << std::endl;
383 G->describe(*outStream,v);
387 zgno_t localNumRows = newRowIds.size();
389 RCP<const xgraph_t> newG;
392 localNumRows, newRowIds.getRawPtr());
394 catch(std::exception &e){
396 std::cout << e.what() << std::endl;
399 " Zoltan2::XpetraTraits<xgraph_t>::doMigration ", 1);
402 std::cout <<
"Migrated Xpetra graph" << std::endl;
404 newG->describe(*outStream,v);
413 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
417 catch(std::exception &e){
419 std::cout << e.what() << std::endl;
424 std::cout <<
"Original Xpetra vector" << std::endl;
426 V->describe(*outStream,v);
430 zgno_t localNumRows = newRowIds.size();
432 RCP<const xvector_t> newV;
435 localNumRows, newRowIds.getRawPtr());
437 catch(std::exception &e){
439 std::cout << e.what() << std::endl;
442 " Zoltan2::XpetraTraits<xvector_t>::doMigration ", 1);
445 std::cout <<
"Migrated Xpetra vector" << std::endl;
447 newV->describe(*outStream,v);
455 RCP<tmvector_t> tMV =
456 rcp(
new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
460 catch(std::exception &e){
462 std::cout << e.what() << std::endl;
467 std::cout <<
"Original Xpetra multivector" << std::endl;
469 MV->describe(*outStream,v);
473 zgno_t localNumRows = newRowIds.size();
475 RCP<const xmvector_t> newMV;
478 localNumRows, newRowIds.getRawPtr());
480 catch(std::exception &e){
482 std::cout << e.what() << std::endl;
485 " Zoltan2::XpetraTraits<xmvector_t>::doMigration ", 1);
488 std::cout <<
"Migrated Xpetra multivector" << std::endl;
490 newMV->describe(*outStream,v);
493 #ifdef HAVE_EPETRA_DATA_TYPES 501 typedef Epetra_CrsMatrix ematrix_t;
502 typedef Epetra_CrsGraph egraph_t;
503 typedef Epetra_Vector evector_t;
504 typedef Epetra_MultiVector emvector_t;
505 typedef Xpetra::EpetraMapT<zgno_t, znode_t> xemap_t;
506 typedef Epetra_BlockMap emap_t;
510 RCP<UserInputForTests> euinput;
516 catch(std::exception &e){
518 std::cout << e.what() << std::endl;
527 M = euinput->getUIEpetraCrsMatrix();
529 catch(std::exception &e){
531 std::cout << e.what() << std::endl;
536 std::cout <<
"Original Epetra matrix" << std::endl;
540 RCP<const emap_t> emap = Teuchos::rcpFromRef(M->RowMap());
541 RCP<const xemap_t> xmap(
new xemap_t(emap));
545 zgno_t localNumRows = newRowIds.size();
547 RCP<const ematrix_t> newM;
550 localNumRows, newRowIds.getRawPtr());
552 catch(std::exception &e){
554 std::cout << e.what() << std::endl;
557 " Zoltan2::XpetraTraits<ematrix_t>::doMigration ", 1);
560 std::cout <<
"Migrated Epetra matrix" << std::endl;
562 newM->Print(std::cout);
570 G = euinput->getUIEpetraCrsGraph();
572 catch(std::exception &e){
574 std::cout << e.what() << std::endl;
579 std::cout <<
"Original Epetra graph" << std::endl;
583 RCP<const emap_t> emap = Teuchos::rcpFromRef(G->RowMap());
584 RCP<const xemap_t> xmap(
new xemap_t(emap));
587 zgno_t localNumRows = newRowIds.size();
589 RCP<const egraph_t> newG;
592 localNumRows, newRowIds.getRawPtr());
594 catch(std::exception &e){
596 std::cout << e.what() << std::endl;
599 " Zoltan2::XpetraTraits<egraph_t>::doMigration ", 1);
602 std::cout <<
"Migrated Epetra graph" << std::endl;
604 newG->Print(std::cout);
612 V = rcp(
new Epetra_Vector(euinput->getUIEpetraCrsGraph()->RowMap()));
615 catch(std::exception &e){
617 std::cout << e.what() << std::endl;
622 std::cout <<
"Original Epetra vector" << std::endl;
626 RCP<const emap_t> emap = Teuchos::rcpFromRef(V->Map());
627 RCP<const xemap_t> xmap(
new xemap_t(emap));
630 zgno_t localNumRows = newRowIds.size();
632 RCP<const evector_t> newV;
635 localNumRows, newRowIds.getRawPtr());
637 catch(std::exception &e){
639 std::cout << e.what() << std::endl;
642 " Zoltan2::XpetraTraits<evector_t>::doMigration ", 1);
645 std::cout <<
"Migrated Epetra vector" << std::endl;
647 newV->Print(std::cout);
656 rcp(
new Epetra_MultiVector(euinput->getUIEpetraCrsGraph()->RowMap(),3));
659 catch(std::exception &e){
661 std::cout << e.what() << std::endl;
666 std::cout <<
"Original Epetra multivector" << std::endl;
668 MV->Print(std::cout);
670 RCP<const emap_t> emap = Teuchos::rcpFromRef(MV->Map());
671 RCP<const xemap_t> xmap(
new xemap_t(emap));
674 zgno_t localNumRows = newRowIds.size();
676 RCP<const emvector_t> newMV;
679 localNumRows, newRowIds.getRawPtr());
681 catch(std::exception &e){
683 std::cout << e.what() << std::endl;
686 " Zoltan2::XpetraTraits<emvector_t>::doMigration ", 1);
689 std::cout <<
"Migrated Epetra multivector" << std::endl;
691 newMV->Print(std::cout);
693 #endif // have epetra data types (int, int, double) 700 std::cout <<
"PASS" << std::endl;
#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
int main(int argc, char *argv[])
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.
ArrayRCP< zgno_t > roundRobinMap(const RCP< const Xpetra::Map< zlno_t, zgno_t, znode_t > > &m)
std::string testDataFilePath(".")