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 #include <Xpetra_EpetraUtils.hpp> 68 #ifdef HAVE_ZOLTAN2_MPI 69 #include <Epetra_MpiComm.h> 71 #include <Epetra_SerialComm.h> 77 using Teuchos::ArrayRCP;
78 using Teuchos::ArrayView;
84 const RCP<
const Xpetra::Map<lno_t, gno_t, node_t> > &m)
86 const RCP<const Comm<int> > &comm = m->getComm();
87 int proc = comm->getRank();
88 int nprocs = comm->getSize();
89 gno_t base = m->getMinAllGlobalIndex();
90 gno_t max = m->getMaxAllGlobalIndex();
91 size_t globalrows = m->getGlobalNumElements();
92 if (globalrows !=
size_t(max - base + 1)){
94 string(
"Map is invalid for test - fix test"), 1);
96 RCP<Array<gno_t> > mygids = rcp(
new Array<gno_t>);
97 gno_t firstgno_t = proc;
98 if (firstgno_t < base){
99 gno_t n = base % proc;
101 firstgno_t = base - n + proc;
105 for (
gno_t gid=firstgno_t; gid <= max; gid+=nprocs){
106 (*mygids).append(gid);
109 ArrayRCP<gno_t> newIdArcp = Teuchos::arcp(mygids);
114 int main(
int argc,
char *argv[])
116 Teuchos::GlobalMPISession session(&argc, &argv);
117 RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
118 int rank = comm->getRank();
120 Teuchos::RCP<Teuchos::FancyOStream> outStream =
121 Teuchos::VerboseObjectBase::getDefaultOStream();
122 Teuchos::EVerbosityLevel v=Teuchos::VERB_EXTREME;
125 typedef Tpetra::CrsMatrix<scalar_t,lno_t,gno_t,node_t>
tmatrix_t;
126 typedef Tpetra::CrsGraph<lno_t,gno_t,node_t>
tgraph_t;
127 typedef Tpetra::Vector<scalar_t,lno_t,gno_t,node_t>
tvector_t;
128 typedef Tpetra::MultiVector<scalar_t,lno_t,gno_t,node_t> tmvector_t;
129 typedef Xpetra::CrsMatrix<scalar_t,lno_t,gno_t,node_t>
xmatrix_t;
130 typedef Xpetra::CrsGraph<lno_t,gno_t,node_t>
xgraph_t;
131 typedef Xpetra::Vector<scalar_t,lno_t,gno_t,node_t>
xvector_t;
132 typedef Xpetra::MultiVector<scalar_t,lno_t,gno_t,node_t> xmvector_t;
133 typedef Xpetra::TpetraMap<lno_t,gno_t,node_t> xtmap_t;
137 RCP<uinput_t> uinput;
143 catch(std::exception &e){
159 M = uinput->getTpetraCrsMatrix();
161 catch(std::exception &e){
163 string(
"getTpetraCrsMatrix ")+e.what(), 1);
167 std::cout <<
"Original Tpetra matrix " << M->getGlobalNumRows()
168 <<
" x " << M->getGlobalNumCols() << std::endl;
170 M->describe(*outStream,v);
172 RCP<const xtmap_t> xmap(
new xtmap_t(M->getRowMap()));
176 gno_t localNumRows = newRowIds.size();
178 RCP<const tmatrix_t> newM;
181 rcp_const_cast<const tmatrix_t>(M),
182 localNumRows, newRowIds.getRawPtr());
184 catch(std::exception &e){
186 string(
" Zoltan2::XpetraTraits<tmatrix_t>::doMigration ")+e.what(), 1);
190 std::cout <<
"Migrated Tpetra matrix" << std::endl;
192 newM->describe(*outStream,v);
200 G = uinput->getTpetraCrsGraph();
202 catch(std::exception &e){
204 string(
"getTpetraCrsGraph ")+e.what(), 1);
208 std::cout <<
"Original Tpetra graph" << std::endl;
210 G->describe(*outStream,v);
212 RCP<const xtmap_t> xmap(
new xtmap_t(G->getRowMap()));
215 gno_t localNumRows = newRowIds.size();
217 RCP<const tgraph_t> newG;
220 rcp_const_cast<const tgraph_t>(G),
221 localNumRows, newRowIds.getRawPtr());
223 catch(std::exception &e){
225 string(
" Zoltan2::XpetraTraits<tgraph_t>::doMigration ")+e.what(), 1);
229 std::cout <<
"Migrated Tpetra graph" << std::endl;
231 newG->describe(*outStream,v);
239 V = uinput->getTpetraVector();
241 catch(std::exception &e){
243 string(
"getTpetraVector")+e.what(), 1);
247 std::cout <<
"Original Tpetra vector" << std::endl;
249 V->describe(*outStream,v);
251 RCP<const xtmap_t> xmap(
new xtmap_t(V->getMap()));
254 gno_t localNumRows = newRowIds.size();
256 RCP<const tvector_t> newV;
259 rcp_const_cast<const tvector_t>(V),
260 localNumRows, newRowIds.getRawPtr());
262 catch(std::exception &e){
264 string(
" Zoltan2::XpetraTraits<tvector_t>::doMigration ")+e.what(), 1);
268 std::cout <<
"Migrated Tpetra vector" << std::endl;
270 newV->describe(*outStream,v);
278 MV = uinput->getTpetraMultiVector(3);
280 catch(std::exception &e){
282 string(
"getTpetraMultiVector")+e.what(), 1);
286 std::cout <<
"Original Tpetra multivector" << std::endl;
288 MV->describe(*outStream,v);
290 RCP<const xtmap_t> xmap(
new xtmap_t(MV->getMap()));
293 gno_t localNumRows = newRowIds.size();
295 RCP<const tmvector_t> newMV;
298 rcp_const_cast<const tmvector_t>(MV),
299 localNumRows, newRowIds.getRawPtr());
301 catch(std::exception &e){
303 string(
" Zoltan2::XpetraTraits<tmvector_t>::doMigration ")+e.what(), 1);
307 std::cout <<
"Migrated Tpetra multivector" << std::endl;
309 newMV->describe(*outStream,v);
324 M = uinput->getXpetraCrsMatrix();
326 catch(std::exception &e){
328 string(
"getXpetraCrsMatrix ")+e.what(), 1);
332 std::cout <<
"Original Xpetra matrix" << std::endl;
334 M->describe(*outStream,v);
338 gno_t localNumRows = newRowIds.size();
340 RCP<const xmatrix_t> newM;
343 rcp_const_cast<const xmatrix_t>(M),
344 localNumRows, newRowIds.getRawPtr());
346 catch(std::exception &e){
348 string(
" Zoltan2::XpetraTraits<xmatrix_t>::doMigration ")+e.what(), 1);
352 std::cout <<
"Migrated Xpetra matrix" << std::endl;
354 newM->describe(*outStream,v);
362 G = uinput->getXpetraCrsGraph();
364 catch(std::exception &e){
366 string(
"getXpetraCrsGraph ")+e.what(), 1);
370 std::cout <<
"Original Xpetra graph" << std::endl;
372 G->describe(*outStream,v);
376 gno_t localNumRows = newRowIds.size();
378 RCP<const xgraph_t> newG;
381 rcp_const_cast<const xgraph_t>(G),
382 localNumRows, newRowIds.getRawPtr());
384 catch(std::exception &e){
386 string(
" Zoltan2::XpetraTraits<xgraph_t>::doMigration ")+e.what(), 1);
390 std::cout <<
"Migrated Xpetra graph" << std::endl;
392 newG->describe(*outStream,v);
400 V = uinput->getXpetraVector();
402 catch(std::exception &e){
404 string(
"getXpetraVector")+e.what(), 1);
408 std::cout <<
"Original Xpetra vector" << std::endl;
410 V->describe(*outStream,v);
414 gno_t localNumRows = newRowIds.size();
416 RCP<const xvector_t> newV;
419 rcp_const_cast<const xvector_t>(V),
420 localNumRows, newRowIds.getRawPtr());
422 catch(std::exception &e){
424 string(
" Zoltan2::XpetraTraits<xvector_t>::doMigration ")+e.what(), 1);
428 std::cout <<
"Migrated Xpetra vector" << std::endl;
430 newV->describe(*outStream,v);
438 MV = uinput->getXpetraMultiVector(3);
440 catch(std::exception &e){
442 string(
"getXpetraMultiVector")+e.what(), 1);
446 std::cout <<
"Original Xpetra multivector" << std::endl;
448 MV->describe(*outStream,v);
452 gno_t localNumRows = newRowIds.size();
454 RCP<const xmvector_t> newMV;
457 rcp_const_cast<const xmvector_t>(MV),
458 localNumRows, newRowIds.getRawPtr());
460 catch(std::exception &e){
462 string(
" Zoltan2::XpetraTraits<xmvector_t>::doMigration ")+e.what(), 1);
466 std::cout <<
"Migrated Xpetra multivector" << std::endl;
468 newMV->describe(*outStream,v);
471 #ifdef HAVE_EPETRA_DATA_TYPES 482 typedef Epetra_MultiVector emvector_t;
483 typedef Xpetra::EpetraMap xemap_t;
484 typedef Epetra_BlockMap emap_t;
488 RCP<uinput_t> euinput;
494 catch(std::exception &e){
503 M = euinput->getEpetraCrsMatrix();
505 catch(std::exception &e){
507 string(
"getEpetraCrsMatrix ")+e.what(), 1);
511 std::cout <<
"Original Epetra matrix" << std::endl;
515 RCP<const emap_t> emap = Teuchos::rcpFromRef(M->RowMap());
516 RCP<const xemap_t> xmap(
new xemap_t(emap));
520 gno_t localNumRows = newRowIds.size();
522 RCP<const ematrix_t> newM;
525 rcp_const_cast<const ematrix_t>(M),
526 localNumRows, newRowIds.getRawPtr());
528 catch(std::exception &e){
530 string(
" Zoltan2::XpetraTraits<ematrix_t>::doMigration ")+e.what(), 1);
534 std::cout <<
"Migrated Epetra matrix" << std::endl;
536 newM->Print(std::cout);
544 G = euinput->getEpetraCrsGraph();
546 catch(std::exception &e){
548 string(
"getEpetraCrsGraph ")+e.what(), 1);
552 std::cout <<
"Original Epetra graph" << std::endl;
556 RCP<const emap_t> emap = Teuchos::rcpFromRef(G->RowMap());
557 RCP<const xemap_t> xmap(
new xemap_t(emap));
560 gno_t localNumRows = newRowIds.size();
562 RCP<const egraph_t> newG;
565 rcp_const_cast<const egraph_t>(G),
566 localNumRows, newRowIds.getRawPtr());
568 catch(std::exception &e){
570 string(
" Zoltan2::XpetraTraits<egraph_t>::doMigration ")+e.what(), 1);
574 std::cout <<
"Migrated Epetra graph" << std::endl;
576 newG->Print(std::cout);
584 V = euinput->getEpetraVector();
586 catch(std::exception &e){
588 string(
"getEpetraVector")+e.what(), 1);
592 std::cout <<
"Original Epetra vector" << std::endl;
596 RCP<const emap_t> emap = Teuchos::rcpFromRef(V->Map());
597 RCP<const xemap_t> xmap(
new xemap_t(emap));
600 gno_t localNumRows = newRowIds.size();
602 RCP<const evector_t> newV;
605 rcp_const_cast<const evector_t>(V),
606 localNumRows, newRowIds.getRawPtr());
608 catch(std::exception &e){
610 string(
" Zoltan2::XpetraTraits<evector_t>::doMigration ")+e.what(), 1);
614 std::cout <<
"Migrated Epetra vector" << std::endl;
616 newV->Print(std::cout);
624 MV = euinput->getEpetraMultiVector(3);
626 catch(std::exception &e){
628 string(
"getEpetraMultiVector")+e.what(), 1);
632 std::cout <<
"Original Epetra multivector" << std::endl;
634 MV->Print(std::cout);
636 RCP<const emap_t> emap = Teuchos::rcpFromRef(MV->Map());
637 RCP<const xemap_t> xmap(
new xemap_t(emap));
640 gno_t localNumRows = newRowIds.size();
642 RCP<const emvector_t> newMV;
645 rcp_const_cast<const emvector_t>(MV),
646 localNumRows, newRowIds.getRawPtr());
648 catch(std::exception &e){
650 string(
" Zoltan2::XpetraTraits<emvector_t>::doMigration ")+e.what(), 1);
654 std::cout <<
"Migrated Epetra multivector" << std::endl;
656 newMV->Print(std::cout);
658 #endif // have epetra data types (int, int, double) 665 std::cout <<
"PASS" << std::endl;
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
Traits of Xpetra classes, including migration method.
common code used by tests
int main(int argc, char *argv[])
static RCP< const User > doMigration(const RCP< const User > &from, lno_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...
ArrayRCP< gno_t > roundRobinMap(const RCP< const Xpetra::Map< lno_t, gno_t, node_t > > &m)
std::string testDataFilePath(".")