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;
88 if (nglobalrows !=
size_t(maxgid - basegid + 1)){
89 std::cout <<
"Error: Map is invalid for test - fix test" << std::endl;
90 std::cerr <<
"Error: Map is invalid for test - fix test" << std::endl;
91 std::cout <<
"FAIL" << std::endl;
94 RCP<Array<zgno_t> > mygids = rcp(
new Array<zgno_t>);
96 if (firstzgno_t < basegid){
99 firstzgno_t = basegid - n + proc;
101 firstzgno_t = basegid;
103 for (
zgno_t gid=firstzgno_t; gid <= maxgid; gid+=nprocs){
104 (*mygids).append(gid);
107 ArrayRCP<zgno_t> newIdArcp = Teuchos::arcp(mygids);
112 #ifdef HAVE_EPETRA_DATA_TYPES 115 const Epetra_Comm &comm = emap.Comm();
116 int proc = comm.MyPID();
117 int nprocs = comm.NumProc();
118 zgno_t basegid = emap.MinAllGID();
119 zgno_t maxgid = emap.MaxAllGID();
120 size_t nglobalrows = emap.NumGlobalElements();
126 ArrayRCP<zgno_t>
roundRobinMap(
const Tpetra::Map<zlno_t, zgno_t, znode_t> &tmap)
128 const RCP<const Comm<int> > &comm = tmap.getComm();
129 int proc = comm->getRank();
130 int nprocs = comm->getSize();
131 zgno_t basegid = tmap.getMinAllGlobalIndex();
132 zgno_t maxgid = tmap.getMaxAllGlobalIndex();
133 size_t nglobalrows = tmap.getGlobalNumElements();
138 ArrayRCP<zgno_t>
roundRobinMap(
const Xpetra::Map<zlno_t, zgno_t, znode_t> &xmap)
140 const RCP<const Comm<int> > &comm = xmap.getComm();
141 int proc = comm->getRank();
142 int nprocs = comm->getSize();
143 zgno_t basegid = xmap.getMinAllGlobalIndex();
144 zgno_t maxgid = xmap.getMaxAllGlobalIndex();
145 size_t nglobalrows = xmap.getGlobalNumElements();
150 int main(
int argc,
char *argv[])
152 Teuchos::GlobalMPISession session(&argc, &argv);
153 RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
154 int rank = comm->getRank();
157 Teuchos::RCP<Teuchos::FancyOStream> outStream =
158 Teuchos::VerboseObjectBase::getDefaultOStream();
159 Teuchos::EVerbosityLevel v=Teuchos::VERB_EXTREME;
161 typedef Tpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t>
tmatrix_t;
162 typedef Tpetra::CrsGraph<zlno_t,zgno_t,znode_t>
tgraph_t;
163 typedef Tpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t>
tvector_t;
164 typedef Tpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> tmvector_t;
165 typedef Xpetra::CrsMatrix<zscalar_t,zlno_t,zgno_t,znode_t>
xmatrix_t;
166 typedef Xpetra::CrsGraph<zlno_t,zgno_t,znode_t>
xgraph_t;
167 typedef Xpetra::Vector<zscalar_t,zlno_t,zgno_t,znode_t>
xvector_t;
168 typedef Xpetra::MultiVector<zscalar_t,zlno_t,zgno_t,znode_t> xmvector_t;
172 RCP<UserInputForTests> uinput;
178 catch(std::exception &e){
180 std::cout << e.what() << std::endl;
197 M = uinput->getUITpetraCrsMatrix();
199 catch(std::exception &e){
201 std::cout << e.what() << std::endl;
206 std::cout <<
"Original Tpetra matrix " << M->getGlobalNumRows()
207 <<
" x " << M->getGlobalNumCols() << std::endl;
209 M->describe(*outStream,v);
211 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(M->getRowMap()));
213 zgno_t localNumRows = newRowIds.size();
215 RCP<const tmatrix_t> newM;
218 localNumRows, newRowIds.getRawPtr());
220 catch(std::exception &e){
222 std::cout << e.what() << std::endl;
225 " Zoltan2::XpetraTraits<tmatrix_t>::doMigration ", 1);
228 std::cout <<
"Migrated Tpetra matrix" << std::endl;
230 newM->describe(*outStream,v);
238 G = uinput->getUITpetraCrsGraph();
240 catch(std::exception &e){
242 std::cout << e.what() << std::endl;
247 std::cout <<
"Original Tpetra graph" << std::endl;
249 G->describe(*outStream,v);
251 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(G->getRowMap()));
253 zgno_t localNumRows = newRowIds.size();
255 RCP<const tgraph_t> newG;
258 localNumRows, newRowIds.getRawPtr());
260 catch(std::exception &e){
262 std::cout << e.what() << std::endl;
265 " Zoltan2::XpetraTraits<tgraph_t>::doMigration ", 1);
268 std::cout <<
"Migrated Tpetra graph" << std::endl;
270 newG->describe(*outStream,v);
278 V = rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
281 catch(std::exception &e){
283 std::cout << e.what() << std::endl;
288 std::cout <<
"Original Tpetra vector" << std::endl;
290 V->describe(*outStream,v);
294 zgno_t localNumRows = newRowIds.size();
296 RCP<const tvector_t> newV;
299 localNumRows, newRowIds.getRawPtr());
301 catch(std::exception &e){
303 std::cout << e.what() << std::endl;
306 " Zoltan2::XpetraTraits<tvector_t>::doMigration ", 1);
309 std::cout <<
"Migrated Tpetra vector" << std::endl;
311 newV->describe(*outStream,v);
319 MV = rcp(
new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
322 catch(std::exception &e){
324 std::cout << e.what() << std::endl;
329 std::cout <<
"Original Tpetra multivector" << std::endl;
331 MV->describe(*outStream,v);
335 zgno_t localNumRows = newRowIds.size();
337 RCP<const tmvector_t> newMV;
340 localNumRows, newRowIds.getRawPtr());
342 catch(std::exception &e){
344 std::cout << e.what() << std::endl;
347 " Zoltan2::XpetraTraits<tmvector_t>::doMigration ", 1);
350 std::cout <<
"Migrated Tpetra multivector" << std::endl;
352 newMV->describe(*outStream,v);
367 M = uinput->getUIXpetraCrsMatrix();
369 catch(std::exception &e){
371 std::cout << e.what() << std::endl;
376 std::cout <<
"Original Xpetra matrix" << std::endl;
378 M->describe(*outStream,v);
380 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(M->getRowMap()));
382 zgno_t localNumRows = newRowIds.size();
384 RCP<const xmatrix_t> newM;
387 localNumRows, newRowIds.getRawPtr());
389 catch(std::exception &e){
391 std::cout << e.what() << std::endl;
394 " Zoltan2::XpetraTraits<xmatrix_t>::doMigration ", 1);
397 std::cout <<
"Migrated Xpetra matrix" << std::endl;
399 newM->describe(*outStream,v);
407 G = uinput->getUIXpetraCrsGraph();
409 catch(std::exception &e){
411 std::cout << e.what() << std::endl;
416 std::cout <<
"Original Xpetra graph" << std::endl;
418 G->describe(*outStream,v);
420 ArrayRCP<zgno_t> newRowIds =
roundRobinMap(*(G->getRowMap()));
422 zgno_t localNumRows = newRowIds.size();
424 RCP<const xgraph_t> newG;
427 localNumRows, newRowIds.getRawPtr());
429 catch(std::exception &e){
431 std::cout << e.what() << std::endl;
434 " Zoltan2::XpetraTraits<xgraph_t>::doMigration ", 1);
437 std::cout <<
"Migrated Xpetra graph" << std::endl;
439 newG->describe(*outStream,v);
448 rcp(
new tvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 1));
452 catch(std::exception &e){
454 std::cout << e.what() << std::endl;
459 std::cout <<
"Original Xpetra vector" << std::endl;
461 V->describe(*outStream,v);
465 zgno_t localNumRows = newRowIds.size();
467 RCP<const xvector_t> newV;
470 localNumRows, newRowIds.getRawPtr());
472 catch(std::exception &e){
474 std::cout << e.what() << std::endl;
477 " Zoltan2::XpetraTraits<xvector_t>::doMigration ", 1);
480 std::cout <<
"Migrated Xpetra vector" << std::endl;
482 newV->describe(*outStream,v);
490 RCP<tmvector_t> tMV =
491 rcp(
new tmvector_t(uinput->getUITpetraCrsGraph()->getRowMap(), 3));
495 catch(std::exception &e){
497 std::cout << e.what() << std::endl;
502 std::cout <<
"Original Xpetra multivector" << std::endl;
504 MV->describe(*outStream,v);
508 zgno_t localNumRows = newRowIds.size();
510 RCP<const xmvector_t> newMV;
513 localNumRows, newRowIds.getRawPtr());
515 catch(std::exception &e){
517 std::cout << e.what() << std::endl;
520 " Zoltan2::XpetraTraits<xmvector_t>::doMigration ", 1);
523 std::cout <<
"Migrated Xpetra multivector" << std::endl;
525 newMV->describe(*outStream,v);
528 #ifdef HAVE_EPETRA_DATA_TYPES 536 typedef Epetra_CrsMatrix ematrix_t;
537 typedef Epetra_CrsGraph egraph_t;
538 typedef Epetra_Vector evector_t;
539 typedef Epetra_MultiVector emvector_t;
540 typedef Epetra_BlockMap emap_t;
544 RCP<UserInputForTests> euinput;
550 catch(std::exception &e){
552 std::cout << e.what() << std::endl;
561 M = euinput->getUIEpetraCrsMatrix();
563 catch(std::exception &e){
565 std::cout << e.what() << std::endl;
570 std::cout <<
"Original Epetra matrix" << std::endl;
574 RCP<const emap_t> emap = Teuchos::rcpFromRef(M->RowMap());
577 zgno_t localNumRows = newRowIds.size();
579 RCP<const ematrix_t> newM;
582 localNumRows, newRowIds.getRawPtr());
584 catch(std::exception &e){
586 std::cout << e.what() << std::endl;
589 " Zoltan2::XpetraTraits<ematrix_t>::doMigration ", 1);
592 std::cout <<
"Migrated Epetra matrix" << std::endl;
594 newM->Print(std::cout);
602 G = euinput->getUIEpetraCrsGraph();
604 catch(std::exception &e){
606 std::cout << e.what() << std::endl;
611 std::cout <<
"Original Epetra graph" << std::endl;
615 RCP<const emap_t> emap = Teuchos::rcpFromRef(G->RowMap());
618 zgno_t localNumRows = newRowIds.size();
620 RCP<const egraph_t> newG;
623 localNumRows, newRowIds.getRawPtr());
625 catch(std::exception &e){
627 std::cout << e.what() << std::endl;
630 " Zoltan2::XpetraTraits<egraph_t>::doMigration ", 1);
633 std::cout <<
"Migrated Epetra graph" << std::endl;
635 newG->Print(std::cout);
643 V = rcp(
new Epetra_Vector(euinput->getUIEpetraCrsGraph()->RowMap()));
646 catch(std::exception &e){
648 std::cout << e.what() << std::endl;
653 std::cout <<
"Original Epetra vector" << std::endl;
657 RCP<const emap_t> emap = Teuchos::rcpFromRef(V->Map());
660 zgno_t localNumRows = newRowIds.size();
662 RCP<const evector_t> newV;
665 localNumRows, newRowIds.getRawPtr());
667 catch(std::exception &e){
669 std::cout << e.what() << std::endl;
672 " Zoltan2::XpetraTraits<evector_t>::doMigration ", 1);
675 std::cout <<
"Migrated Epetra vector" << std::endl;
677 newV->Print(std::cout);
686 rcp(
new Epetra_MultiVector(euinput->getUIEpetraCrsGraph()->RowMap(),3));
689 catch(std::exception &e){
691 std::cout << e.what() << std::endl;
696 std::cout <<
"Original Epetra multivector" << std::endl;
698 MV->Print(std::cout);
700 RCP<const emap_t> emap = Teuchos::rcpFromRef(MV->Map());
703 zgno_t localNumRows = newRowIds.size();
705 RCP<const emvector_t> newMV;
708 localNumRows, newRowIds.getRawPtr());
710 catch(std::exception &e){
712 std::cout << e.what() << std::endl;
715 " Zoltan2::XpetraTraits<emvector_t>::doMigration ", 1);
718 std::cout <<
"Migrated Epetra multivector" << std::endl;
720 newMV->Print(std::cout);
722 #endif // have epetra data types (int, int, double) 729 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.
common code used by tests
int main(int argc, char *argv[])
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.
std::string testDataFilePath(".")