48 #ifndef PACKAGES_XPETRA_SUP_UTILS_XPETRA_IO_HPP_ 49 #define PACKAGES_XPETRA_SUP_UTILS_XPETRA_IO_HPP_ 54 #ifdef HAVE_XPETRA_EPETRA 56 # include "Epetra_MpiComm.h" 60 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 61 #include <EpetraExt_MatrixMatrix.h> 62 #include <EpetraExt_RowMatrixOut.h> 63 #include <EpetraExt_MultiVectorOut.h> 64 #include <EpetraExt_CrsMatrixIn.h> 65 #include <EpetraExt_MultiVectorIn.h> 66 #include <EpetraExt_BlockMapIn.h> 69 #include <EpetraExt_BlockMapOut.h> 72 #ifdef HAVE_XPETRA_TPETRA 73 #include <MatrixMarket_Tpetra.hpp> 74 #include <Tpetra_RowMatrixTransposer.hpp> 75 #include <TpetraExt_MatrixMatrix.hpp> 76 #include <Xpetra_TpetraMultiVector.hpp> 77 #include <Xpetra_TpetraCrsGraph.hpp> 78 #include <Xpetra_TpetraCrsMatrix.hpp> 79 #include <Xpetra_TpetraBlockCrsMatrix.hpp> 82 #ifdef HAVE_XPETRA_EPETRA 89 #include "Xpetra_CrsMatrixWrap.hpp" 92 #include "Xpetra_Map.hpp" 93 #include "Xpetra_StridedMap.hpp" 94 #include "Xpetra_StridedMapFactory.hpp" 95 #include "Xpetra_MapExtractor.hpp" 98 #include <Teuchos_MatrixMarket_Raw_Writer.hpp> 105 #ifdef HAVE_XPETRA_EPETRA 107 template<
class SC,
class LO,
class GO,
class NO>
108 RCP<Xpetra::CrsMatrixWrap<SC,LO,GO,NO> >
111 "Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
112 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
117 inline RCP<Xpetra::CrsMatrixWrap<double,int,int,Xpetra::EpetraNode> > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<double,int,int,Xpetra::EpetraNode> (RCP<Epetra_CrsMatrix> &epAB) {
131 template<
class SC,
class LO,
class GO,
class NO>
132 RCP<Xpetra::MultiVector<SC,LO,GO,NO> >
135 "Convert_Epetra_MultiVector_ToXpetra_MultiVector cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
136 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
141 inline RCP<Xpetra::MultiVector<double,int,int,Xpetra::EpetraNode> > Convert_Epetra_MultiVector_ToXpetra_MultiVector<double,int,int,Xpetra::EpetraNode> (RCP<Epetra_MultiVector> &epX) {
147 RCP<Xpetra::MultiVector<SC,LO,GO,NO >> tmp = Xpetra::toXpetra<GO,NO>(epX);
157 template <
class Scalar,
158 class LocalOrdinal = int,
159 class GlobalOrdinal = LocalOrdinal,
164 #undef XPETRA_IO_SHORT 169 #ifdef HAVE_XPETRA_EPETRA 186 if (xeMap == Teuchos::null)
187 throw Exceptions::BadCast(
"Utils::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
188 return xeMap->getEpetra_Map();
193 #ifdef HAVE_XPETRA_TPETRA 215 if (tmp_TMap == Teuchos::null)
216 throw Exceptions::BadCast(
"Utils::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
217 return tmp_TMap->getTpetra_Map();
226 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > tmp_Map = rcpFromRef(M);
227 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 229 if (tmp_EMap != Teuchos::null) {
230 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
235 #endif // HAVE_XPETRA_EPETRAEXT 237 #ifdef HAVE_XPETRA_TPETRA 238 const RCP<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node> > &tmp_TMap =
240 if (tmp_TMap != Teuchos::null) {
241 RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > TMap = tmp_TMap->
getTpetra_Map();
242 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
245 #endif // HAVE_XPETRA_TPETRA 253 std::string mapfile =
"map_" + fileName;
256 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_Vec = Teuchos::rcpFromRef(vec);
257 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 259 if (tmp_EVec != Teuchos::null) {
260 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
265 #endif // HAVE_XPETRA_EPETRA 267 #ifdef HAVE_XPETRA_TPETRA 268 const RCP<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &tmp_TVec =
270 if (tmp_TVec != Teuchos::null) {
271 RCP<const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > TVec = tmp_TVec->
getTpetra_MultiVector();
272 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeDenseFile(fileName, TVec);
275 #endif // HAVE_XPETRA_TPETRA 277 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
295 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
296 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 298 if (tmp_ECrsMtx != Teuchos::null) {
300 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
307 #ifdef HAVE_XPETRA_TPETRA 308 const RCP<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& tmp_TCrsMtx =
310 if (tmp_TCrsMtx != Teuchos::null) {
311 RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A = tmp_TCrsMtx->
getTpetra_CrsMatrix();
312 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
315 #endif // HAVE_XPETRA_TPETRA 317 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
325 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
327 ArrayRCP<const size_t> rowptr_RCP;
328 ArrayRCP<LocalOrdinal> rowptr2_RCP;
329 ArrayRCP<const LocalOrdinal> colind_RCP;
330 ArrayRCP<const Scalar> vals_RCP;
331 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
333 ArrayView<const size_t> rowptr = rowptr_RCP();
334 ArrayView<const LocalOrdinal> colind = colind_RCP();
335 ArrayView<const Scalar> vals = vals_RCP();
337 rowptr2_RCP.resize(rowptr.size());
338 ArrayView<LocalOrdinal> rowptr2 = rowptr2_RCP();
339 for (
size_t j = 0; j<rowptr.size(); j++)
340 rowptr2[j] = rowptr[j];
342 Teuchos::MatrixMarket::Raw::Writer<Scalar,LocalOrdinal> writer;
343 writer.writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
345 rowptr.size()-1,Op.
getColMap()->getNodeNumElements());
367 for (
size_t row = 0; row < Op.
Rows(); ++row) {
368 for (
size_t col = 0; col < Op.
Cols(); ++col) {
369 RCP<const Matrix > m = Op.
getMatrix(row,col);
370 if(m != Teuchos::null) {
372 "Sub block matrix (" << row <<
"," << col <<
") is not of type CrsMatrixWrap.");
373 XpIO::Write(fileName +
toString(row) +
toString(col) +
".m", *m, writeAllMaps);
382 for(
size_t row = 0; row < rangeMapExtractor->NumMaps(); ++row) {
383 RCP<const Map> map = rangeMapExtractor->getMap(row);
384 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(row) +
".m", *map);
386 XpIO::Write(
"fullRangeMap_" + fileName +
".m",*(rangeMapExtractor->getFullMap()));
388 for(
size_t col = 0; col < domainMapExtractor->NumMaps(); ++col) {
389 RCP<const Map> map = domainMapExtractor->getMap(col);
390 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(col) +
".m", *map);
392 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
396 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
Read(
const std::string& fileName,
Xpetra::UnderlyingLib lib,
const RCP<
const Teuchos::Comm<int> >& comm,
bool binary =
false) {
397 if (binary ==
false) {
400 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 401 Epetra_CrsMatrix *eA;
403 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
407 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
409 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A =
410 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
416 #ifdef HAVE_XPETRA_TPETRA 417 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
419 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
421 bool callFillComplete =
true;
423 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(fileName, comm, callFillComplete);
441 std::ifstream ifs(fileName.c_str(), std::ios::binary);
444 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
445 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
446 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
448 int myRank = comm->getRank();
453 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A;
456 Teuchos::Array<GlobalOrdinal> inds;
457 Teuchos::Array<Scalar> vals;
459 Teuchos::ArrayRCP<size_t> numEntriesPerRow(m);
460 for (
int i = 0; i < m; i++) {
462 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
463 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
464 numEntriesPerRow[i] = rownnz;
465 for (
int j = 0; j < rownnz; j++) {
467 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
469 for (
int j = 0; j < rownnz; j++) {
471 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
478 ifs.seekg(0, ifs.beg);
480 ifs.read(reinterpret_cast<char*>(&m),
sizeof(junk));
481 ifs.read(reinterpret_cast<char*>(&n),
sizeof(junk));
482 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(junk));
483 for (
int i = 0; i < m; i++) {
485 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
486 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
489 for (
int j = 0; j < rownnz; j++) {
491 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
492 inds[j] = Teuchos::as<GlobalOrdinal>(index);
494 for (
int j = 0; j < rownnz; j++) {
496 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
497 vals[j] = Teuchos::as<Scalar>(value);
499 A->insertGlobalValues(row, inds, vals);
503 A->fillComplete(domainMap, rangeMap);
508 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
517 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
518 Read(
const std::string& filename,
523 const bool callFillComplete =
true,
524 const bool binary =
false,
525 const bool tolerant =
false,
526 const bool debug =
false) {
529 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domain = (domainMap.is_null() ? rowMap : domainMap);
530 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > range = (rangeMap .is_null() ? rowMap : rangeMap);
533 if (binary ==
false) {
535 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 536 Epetra_CrsMatrix *eA;
542 if (colMap.is_null()) {
543 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
547 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
553 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
554 RCP<Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A =
555 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
562 #ifdef HAVE_XPETRA_TPETRA 563 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
564 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
565 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
567 const RCP<const map_type> tpetraRowMap =
Map2TpetraMap(*rowMap);
568 RCP<const map_type> tpetraColMap = (colMap.is_null() ? Teuchos::null :
Map2TpetraMap(*colMap));
569 const RCP<const map_type> tpetraRangeMap = (rangeMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*rangeMap));
570 const RCP<const map_type> tpetraDomainMap = (domainMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*domainMap));
572 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
573 callFillComplete, tolerant, debug);
590 std::ifstream ifs(filename.c_str(), std::ios::binary);
593 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
594 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
595 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
603 Teuchos::ArrayView<const GlobalOrdinal> rowElements = rowMap->getNodeElementList();
604 Teuchos::ArrayView<const GlobalOrdinal> colElements = colMap->getNodeElementList();
606 Teuchos::Array<GlobalOrdinal> inds;
607 Teuchos::Array<Scalar> vals;
608 for (
int i = 0; i < m; i++) {
610 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
611 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
614 for (
int j = 0; j < rownnz; j++) {
616 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
617 inds[j] = colElements[Teuchos::as<LocalOrdinal>(index)];
619 for (
int j = 0; j < rownnz; j++) {
621 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
622 vals[j] = Teuchos::as<SC>(value);
625 A->insertGlobalValues(rowElements[row], inds, vals);
627 A->fillComplete(domainMap, rangeMap);
631 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
636 static RCP<MultiVector>
ReadMultiVector (
const std::string& fileName,
const RCP<const Map>& map) {
643 #ifdef HAVE_XPETRA_TPETRA 644 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
645 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
646 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
647 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
649 RCP<const map_type> temp =
toTpetra(map);
650 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),temp);
660 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
667 #ifdef HAVE_XPETRA_TPETRA 668 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
669 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
671 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > tMap = reader_type::readMapFile(fileName, comm);
683 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
703 size_t numBlocks = 2;
705 std::vector<RCP<const Map> > rangeMapVec;
706 for(
size_t row = 0; row < numBlocks; ++row) {
707 RCP<const Map> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(row) +
".m", lib, comm);
708 rangeMapVec.push_back(map);
710 RCP<const Map> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
712 std::vector<RCP<const Map> > domainMapVec;
713 for(
size_t col = 0; col < numBlocks; ++col) {
714 RCP<const Map> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(col) +
".m", lib, comm);
715 domainMapVec.push_back(map);
717 RCP<const Map> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
733 bool bRangeUseThyraStyleNumbering =
false;
740 RCP<const MapExtractor> rangeMapExtractor =
741 Teuchos::rcp(
new MapExtractor(fullRangeMap, rangeMapVec, bRangeUseThyraStyleNumbering));
745 bool bDomainUseThyraStyleNumbering =
false;
752 RCP<const MapExtractor> domainMapExtractor =
753 Teuchos::rcp(
new MapExtractor(fullDomainMap, domainMapVec, bDomainUseThyraStyleNumbering));
755 RCP<BlockedCrsMatrix> bOp = Teuchos::rcp(
new BlockedCrsMatrix(rangeMapExtractor, domainMapExtractor,33));
758 for (
size_t row = 0; row < numBlocks; ++row) {
759 for (
size_t col = 0; col < numBlocks; ++col) {
760 RCP<const Map> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
761 RCP<const Map> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
762 RCP<const Map> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
763 RCP<const Map> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
764 RCP<Matrix> mat = XpIO::Read(fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
765 bOp->setMatrix(row, col, mat);
778 std::ostringstream buf;
785 #ifdef HAVE_XPETRA_EPETRA 795 template <
class Scalar>
802 #ifdef HAVE_XPETRA_EPETRA 807 if (xeMap == Teuchos::null)
808 throw Exceptions::BadCast(
"IO::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
809 return xeMap->getEpetra_Map();
814 #ifdef HAVE_XPETRA_TPETRA 819 if (tmp_TMap == Teuchos::null)
820 throw Exceptions::BadCast(
"IO::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
821 return tmp_TMap->getTpetra_Map();
830 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > tmp_Map = rcpFromRef(M);
831 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 833 if (tmp_EMap != Teuchos::null) {
834 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
839 #endif // HAVE_XPETRA_EPETRA 841 #ifdef HAVE_XPETRA_TPETRA 842 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 843 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 846 const RCP<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node> > &tmp_TMap =
848 if (tmp_TMap != Teuchos::null) {
849 RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > TMap = tmp_TMap->
getTpetra_Map();
850 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
854 #endif // HAVE_XPETRA_TPETRA 860 std::string mapfile =
"map_" + fileName;
863 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_Vec = Teuchos::rcpFromRef(vec);
864 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 866 if (tmp_EVec != Teuchos::null) {
867 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
872 #endif // HAVE_XPETRA_EPETRAEXT 874 #ifdef HAVE_XPETRA_TPETRA 875 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 876 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 879 const RCP<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &tmp_TVec =
881 if (tmp_TVec != Teuchos::null) {
882 RCP<const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > TVec = tmp_TVec->
getTpetra_MultiVector();
883 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeDenseFile(fileName, TVec);
887 #endif // HAVE_XPETRA_TPETRA 889 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
908 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
909 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 911 if (tmp_ECrsMtx != Teuchos::null) {
913 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
918 #endif // endif HAVE_XPETRA_EPETRA 920 #ifdef HAVE_XPETRA_TPETRA 921 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 922 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 925 const RCP<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& tmp_TCrsMtx =
927 if (tmp_TCrsMtx != Teuchos::null) {
928 RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A = tmp_TCrsMtx->
getTpetra_CrsMatrix();
929 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
933 #endif // HAVE_XPETRA_TPETRA 935 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
950 RCP<const Xpetra::CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > tmp_Graph = rcpFromRef(graph);
952 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 954 if (tmp_ECrsGraph != Teuchos::null) {
957 #endif // endif HAVE_XPETRA_EPETRA 959 #ifdef HAVE_XPETRA_TPETRA 960 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 961 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 964 RCP<const Xpetra::TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node> > tmp_TCrsGraph =
966 if (tmp_TCrsGraph != Teuchos::null) {
967 RCP<const Tpetra::CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > G = tmp_TCrsGraph->
getTpetra_CrsGraph();
968 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseGraphFile(fileName, G);
972 #endif // HAVE_XPETRA_TPETRA 974 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
982 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
984 ArrayRCP<const size_t> rowptr_RCP;
985 ArrayRCP<LocalOrdinal> rowptr2_RCP;
986 ArrayRCP<const LocalOrdinal> colind_RCP;
987 ArrayRCP<const Scalar> vals_RCP;
988 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
990 ArrayView<const size_t> rowptr = rowptr_RCP();
991 ArrayView<const LocalOrdinal> colind = colind_RCP();
992 ArrayView<const Scalar> vals = vals_RCP();
994 rowptr2_RCP.resize(rowptr.size());
995 ArrayView<LocalOrdinal> rowptr2 = rowptr2_RCP();
996 for (
size_t j = 0; j<Teuchos::as<size_t>(rowptr.size()); j++)
997 rowptr2[j] = rowptr[j];
999 Teuchos::MatrixMarket::Raw::Writer<Scalar,LocalOrdinal> writer;
1000 writer.writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
1001 rowptr2,colind,vals,
1002 rowptr.size()-1,Op.
getColMap()->getNodeNumElements());
1026 for (
size_t row = 0; row < Op.
Rows(); ++row) {
1027 for (
size_t col = 0; col < Op.
Cols(); ++col) {
1028 RCP<const Matrix> m = Op.
getMatrix(row, col);
1029 if(m != Teuchos::null) {
1031 "Sub block matrix (" << row <<
"," << col <<
") is not of type CrsMatrixWrap.");
1032 XpIO::Write(fileName +
toString(row) +
toString(col) +
".m", *m, writeAllMaps);
1041 for(
size_t row = 0; row < rangeMapExtractor->NumMaps(); ++row) {
1042 RCP<const Map> map = rangeMapExtractor->getMap(row);
1043 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(row) +
".m", *map);
1045 XpIO::Write(
"fullRangeMap_" + fileName +
".m", *(rangeMapExtractor->getFullMap()));
1047 for(
size_t col = 0; col < domainMapExtractor->NumMaps(); ++col) {
1048 RCP<const Map> map = domainMapExtractor->getMap(col);
1049 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(col) +
".m", *map);
1051 XpIO::Write(
"fullDomainMap_" + fileName+
".m", *(domainMapExtractor->getFullMap()));
1055 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
Read(
const std::string& fileName,
Xpetra::UnderlyingLib lib,
const RCP<
const Teuchos::Comm<int> >& comm,
bool binary =
false) {
1056 if (binary ==
false) {
1059 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1060 Epetra_CrsMatrix *eA;
1062 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
1066 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
1068 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A =
1069 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
1075 #ifdef HAVE_XPETRA_TPETRA 1076 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 1077 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 1080 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1082 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1084 bool callFillComplete =
true;
1086 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(fileName, comm, callFillComplete);
1105 std::ifstream ifs(fileName.c_str(), std::ios::binary);
1108 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
1109 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
1110 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
1112 int myRank = comm->getRank();
1118 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A;
1121 Teuchos::Array<GlobalOrdinal> inds;
1122 Teuchos::Array<Scalar> vals;
1124 Teuchos::ArrayRCP<size_t> numEntriesPerRow(m);
1125 for (
int i = 0; i < m; i++) {
1127 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1128 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1129 numEntriesPerRow[i] = rownnz;
1130 for (
int j = 0; j < rownnz; j++) {
1132 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1134 for (
int j = 0; j < rownnz; j++) {
1136 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1143 ifs.seekg(0, ifs.beg);
1145 ifs.read(reinterpret_cast<char*>(&m),
sizeof(junk));
1146 ifs.read(reinterpret_cast<char*>(&n),
sizeof(junk));
1147 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(junk));
1148 for (
int i = 0; i < m; i++) {
1150 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1151 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1152 inds.resize(rownnz);
1153 vals.resize(rownnz);
1154 for (
int j = 0; j < rownnz; j++) {
1156 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1157 inds[j] = Teuchos::as<GlobalOrdinal>(index);
1159 for (
int j = 0; j < rownnz; j++) {
1161 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1162 vals[j] = Teuchos::as<Scalar>(value);
1164 A->insertGlobalValues(row, inds, vals);
1168 A->fillComplete(domainMap, rangeMap);
1173 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1182 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
Read(
const std::string& filename,
1187 const bool callFillComplete =
true,
1188 const bool binary =
false,
1189 const bool tolerant =
false,
1190 const bool debug =
false) {
1193 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domain = (domainMap.is_null() ? rowMap : domainMap);
1194 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > range = (rangeMap .is_null() ? rowMap : rangeMap);
1197 if (binary ==
false) {
1199 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1200 Epetra_CrsMatrix *eA;
1206 if (colMap.is_null()) {
1207 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
1211 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
1217 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
1218 RCP<Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A =
1219 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
1226 #ifdef HAVE_XPETRA_TPETRA 1227 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 1228 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 1231 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1232 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1233 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1235 const RCP<const map_type> tpetraRowMap =
Map2TpetraMap(*rowMap);
1236 RCP<const map_type> tpetraColMap = (colMap.is_null() ? Teuchos::null :
Map2TpetraMap(*colMap));
1237 const RCP<const map_type> tpetraRangeMap = (rangeMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*rangeMap));
1238 const RCP<const map_type> tpetraDomainMap = (domainMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*domainMap));
1240 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
1241 callFillComplete, tolerant, debug);
1259 std::ifstream ifs(filename.c_str(), std::ios::binary);
1262 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
1263 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
1264 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
1272 Teuchos::ArrayView<const GlobalOrdinal> rowElements = rowMap->getNodeElementList();
1273 Teuchos::ArrayView<const GlobalOrdinal> colElements = colMap->getNodeElementList();
1275 Teuchos::Array<GlobalOrdinal> inds;
1276 Teuchos::Array<Scalar> vals;
1277 for (
int i = 0; i < m; i++) {
1279 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1280 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1281 inds.resize(rownnz);
1282 vals.resize(rownnz);
1283 for (
int j = 0; j < rownnz; j++) {
1285 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1286 inds[j] = colElements[Teuchos::as<LocalOrdinal>(index)];
1288 for (
int j = 0; j < rownnz; j++) {
1290 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1291 vals[j] = Teuchos::as<Scalar>(value);
1294 A->insertGlobalValues(rowElements[row], inds, vals);
1296 A->fillComplete(domainMap, rangeMap);
1300 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1311 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1312 Epetra_MultiVector * MV;
1313 int rv = EpetraExt::MatrixMarketFileToMultiVector(fileName.c_str(),
toEpetra(map), MV);
1315 RCP<Epetra_MultiVector> MVrcp = rcp(MV);
1316 return Convert_Epetra_MultiVector_ToXpetra_MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(MVrcp);
1321 #ifdef HAVE_XPETRA_TPETRA 1322 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 1323 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 1326 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1327 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1328 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1329 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
1331 RCP<const map_type> temp =
toTpetra(map);
1332 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),temp);
1333 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > rmv =
Xpetra::toXpetra(TMV);
1343 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1348 static RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
ReadMap (
const std::string& fileName,
Xpetra::UnderlyingLib lib,
const RCP<
const Teuchos::Comm<int> >& comm) {
1352 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1354 int rv = EpetraExt::MatrixMarketFileToMap(fileName.c_str(), *(
Xpetra::toEpetra(comm)), eMap);
1358 RCP<Epetra_Map> eMap1 = rcp(
new Epetra_Map(*eMap));
1359 return Xpetra::toXpetra<int,Node>(*eMap1);
1364 #ifdef HAVE_XPETRA_TPETRA 1365 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 1366 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 1369 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1370 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1372 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > tMap = reader_type::readMapFile(fileName, comm);
1385 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1408 size_t numBlocks = 2;
1410 std::vector<RCP<const Map> > rangeMapVec;
1411 for(
size_t row = 0; row < numBlocks; ++row) {
1412 RCP<const Map> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(row) +
".m", lib, comm);
1413 rangeMapVec.push_back(map);
1415 RCP<const Map> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
1417 std::vector<RCP<const Map> > domainMapVec;
1418 for(
size_t col = 0; col < numBlocks; ++col) {
1419 RCP<const Map> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(col) +
".m", lib, comm);
1420 domainMapVec.push_back(map);
1422 RCP<const Map> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
1438 bool bRangeUseThyraStyleNumbering =
false;
1445 RCP<const MapExtractor> rangeMapExtractor =
1446 rcp(
new MapExtractor(fullRangeMap, rangeMapVec, bRangeUseThyraStyleNumbering));
1449 bool bDomainUseThyraStyleNumbering =
false;
1455 RCP<const MapExtractor> domainMapExtractor =
1456 rcp(
new MapExtractor(fullDomainMap, domainMapVec, bDomainUseThyraStyleNumbering));
1458 RCP<BlockedCrsMatrix> bOp = Teuchos::rcp(
new BlockedCrsMatrix(rangeMapExtractor, domainMapExtractor, 33));
1461 for (
size_t row = 0; row < numBlocks; ++row) {
1462 for (
size_t col = 0; col < numBlocks; ++col) {
1463 RCP<const Map> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
1464 RCP<const Map> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
1465 RCP<const Map> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
1466 RCP<const Map> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
1467 RCP<Matrix> mat = XpIO::Read(fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
1468 bOp->setMatrix(row, col, mat);
1472 bOp->fillComplete();
1480 std::ostringstream buf;
1485 #endif // HAVE_XPETRA_EPETRA 1490 #define XPETRA_IO_SHORT std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.
static void Write(const std::string &fileName, const Xpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, const bool &writeAllMaps=false)
Save CrsGraph to file in Matrix Market format.
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Read(const std::string &filename, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > rowMap, RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > colMap=Teuchos::null, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > domainMap=Teuchos::null, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > rangeMap=Teuchos::null, const bool callFillComplete=true, const bool binary=false, const bool tolerant=false, const bool debug=false)
Read matrix from file in Matrix Market or binary format.
RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetra_Map() const
Get the underlying Tpetra map.
RCP< Xpetra::CrsMatrixWrap< SC, LO, GO, NO > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP< Epetra_CrsMatrix > &)
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Read(const std::string &filename, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > rowMap, RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > colMap=Teuchos::null, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > domainMap=Teuchos::null, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > rangeMap=Teuchos::null, const bool callFillComplete=true, const bool binary=false, const bool tolerant=false, const bool debug=false)
Read matrix from file in Matrix Market or binary format.
virtual const RCP< const Map > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrix() const
Get the underlying Tpetra matrix.
static void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
Read/Write methods.
static RCP< Matrix > Build(const RCP< const Map > &rowMap)
static void WriteLocal(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Save local parts of matrix to files in Matrix Market format.
Exception throws to report errors in the internal logical of the program.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
static RCP< const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadBlockedCrsMatrix(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
Read block matrix from one file per block in Matrix Market format.
static const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > Map2TpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
Helper utility to pull out the underlying Tpetra objects from an Xpetra object.
RCP< const MapExtractor > getRangeMapExtractor() const
Returns map extractor class for range map.
static const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > Map2TpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
Helper utility to pull out the underlying Tpetra objects from an Xpetra object.
virtual const RCP< const Map > & getColMap() const
Returns the Map that describes the column distribution in this matrix. This might be null until fillC...
Exception indicating invalid cast attempted.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
static RCP< const Map > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const =0
Returns the Map associated with the domain of this graph.
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Read(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, bool binary=false)
Read matrix from file in Matrix Market or binary format.
static RCP< MultiVector > ReadMultiVector(const std::string &fileName, const RCP< const Map > &map)
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const=0
The Map describing the parallel distribution of this object.
static void WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
Save block matrix to one file per block in Matrix Market format.
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_MultiVector() const
Get the underlying Tpetra multivector.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const =0
Returns the Map associated with the domain of this graph.
RCP< Xpetra::MultiVector< SC, LO, GO, NO > > Convert_Epetra_MultiVector_ToXpetra_MultiVector(RCP< Epetra_MultiVector > &epX)
static void WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
Save block matrix to one file per block in Matrix Market format.
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.
static RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadMultiVector(const std::string &fileName, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
static void Write(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
Save matrix to file in Matrix Market format.
static void WriteLocal(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Save local parts of matrix to files in Matrix Market format.
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Read(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, bool binary=false)
Read matrix from file in Matrix Market or binary format.
static const Epetra_Map & Map2EpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
Concrete implementation of Xpetra::Matrix.
Teuchos::RCP< Matrix > getMatrix(size_t r, size_t c) const
return block (r,c)
virtual Teuchos::RCP< const Map > getRangeMap() const =0
The Map associated with the range of this operator, which must be compatible with Y...
RCP< const MapExtractor > getDomainMapExtractor() const
Returns map extractor for domain map.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const =0
Returns the Map that describes the row distribution in this graph.
static RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
static const Epetra_Map & Map2EpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
virtual size_t Rows() const
number of row blocks
virtual size_t Cols() const
number of column blocks
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsGraph() const
Get the underlying Tpetra graph.
RCP< CrsMatrix > getCrsMatrix() const
Xpetra utility class containing IO routines to read/write vectors, matrices etc...
static void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
Read/Write methods.
static void Write(const std::string &fileName, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec)
Save vector to file in Matrix Market format.
static void Write(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
Save matrix to file in Matrix Market format.
static void Write(const std::string &fileName, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec)
Save vector to file in Matrix Market format.
virtual Teuchos::RCP< const Map > getDomainMap() const =0
The Map associated with the domain of this operator, which must be compatible with X...
Xpetra-specific matrix class.
static RCP< const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadBlockedCrsMatrix(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
Read block matrix from one file per block in Matrix Market format.
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const =0
Returns the Map that describes the column distribution in this graph.