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_TpetraCrsMatrix.hpp>
78 #include <Xpetra_TpetraBlockCrsMatrix.hpp>
81 #ifdef HAVE_XPETRA_EPETRA
87 #include "Xpetra_CrsMatrixWrap.hpp"
90 #include "Xpetra_Map.hpp"
91 #include "Xpetra_StridedMap.hpp"
92 #include "Xpetra_StridedMapFactory.hpp"
93 #include "Xpetra_MapExtractor.hpp"
96 #include <Teuchos_MatrixMarket_Raw_Writer.hpp>
103 #ifdef HAVE_XPETRA_EPETRA
105 template<
class SC,
class LO,
class GO,
class NO>
106 RCP<Xpetra::CrsMatrixWrap<SC,LO,GO,NO> >
109 "Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
110 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
115 inline RCP<Xpetra::CrsMatrixWrap<double,int,int,Xpetra::EpetraNode> > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<double,int,int,Xpetra::EpetraNode> (RCP<Epetra_CrsMatrix> &epAB) {
129 template<
class SC,
class LO,
class GO,
class NO>
130 RCP<Xpetra::MultiVector<SC,LO,GO,NO> >
133 "Convert_Epetra_MultiVector_ToXpetra_MultiVector cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
134 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
139 inline RCP<Xpetra::MultiVector<double,int,int,Xpetra::EpetraNode> > Convert_Epetra_MultiVector_ToXpetra_MultiVector<double,int,int,Xpetra::EpetraNode> (RCP<Epetra_MultiVector> &epX) {
145 RCP<Xpetra::MultiVector<SC,LO,GO,NO >> tmp = Xpetra::toXpetra<GO,NO>(epX);
155 template <
class Scalar,
156 class LocalOrdinal = int,
157 class GlobalOrdinal = LocalOrdinal,
162 #undef XPETRA_IO_SHORT
167 #ifdef HAVE_XPETRA_EPETRA
184 if (xeMap == Teuchos::null)
185 throw Exceptions::BadCast(
"Utils::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
186 return xeMap->getEpetra_Map();
191 #ifdef HAVE_XPETRA_TPETRA
213 if (tmp_TMap == Teuchos::null)
214 throw Exceptions::BadCast(
"Utils::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
215 return tmp_TMap->getTpetra_Map();
224 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > tmp_Map = rcpFromRef(M);
225 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
227 if (tmp_EMap != Teuchos::null) {
228 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
233 #endif // HAVE_XPETRA_EPETRAEXT
235 #ifdef HAVE_XPETRA_TPETRA
236 const RCP<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node> > &tmp_TMap =
238 if (tmp_TMap != Teuchos::null) {
239 RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > TMap = tmp_TMap->
getTpetra_Map();
240 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
243 #endif // HAVE_XPETRA_TPETRA
251 std::string mapfile =
"map_" + fileName;
254 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_Vec = Teuchos::rcpFromRef(vec);
255 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
257 if (tmp_EVec != Teuchos::null) {
258 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
263 #endif // HAVE_XPETRA_EPETRA
265 #ifdef HAVE_XPETRA_TPETRA
266 const RCP<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &tmp_TVec =
268 if (tmp_TVec != Teuchos::null) {
269 RCP<const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > TVec = tmp_TVec->
getTpetra_MultiVector();
270 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeDenseFile(fileName, TVec);
273 #endif // HAVE_XPETRA_TPETRA
275 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
293 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
294 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
296 if (tmp_ECrsMtx != Teuchos::null) {
298 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
305 #ifdef HAVE_XPETRA_TPETRA
306 const RCP<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& tmp_TCrsMtx =
308 if (tmp_TCrsMtx != Teuchos::null) {
309 RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A = tmp_TCrsMtx->
getTpetra_CrsMatrix();
310 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
313 #endif // HAVE_XPETRA_TPETRA
315 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
323 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
325 ArrayRCP<const size_t> rowptr_RCP;
326 ArrayRCP<LocalOrdinal> rowptr2_RCP;
327 ArrayRCP<const LocalOrdinal> colind_RCP;
328 ArrayRCP<const Scalar> vals_RCP;
329 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
331 ArrayView<const size_t> rowptr = rowptr_RCP();
332 ArrayView<const LocalOrdinal> colind = colind_RCP();
333 ArrayView<const Scalar> vals = vals_RCP();
335 rowptr2_RCP.resize(rowptr.size());
336 ArrayView<LocalOrdinal> rowptr2 = rowptr2_RCP();
337 for (
size_t j = 0; j<rowptr.size(); j++)
338 rowptr2[j] = rowptr[j];
340 Teuchos::MatrixMarket::Raw::Writer<Scalar,LocalOrdinal> writer;
341 writer.writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
343 rowptr.size()-1,Op.
getColMap()->getNodeNumElements());
357 for (
size_t r = 0; r < Op.
Rows(); ++r) {
358 for (
size_t c = 0; c < Op.
Cols(); ++c) {
360 if(m != Teuchos::null) {
362 "Sub block matrix (" << r <<
"," << c <<
") is not of type CrsMatrixWrap.");
372 for(
size_t r = 0; r < rangeMapExtractor->NumMaps(); ++r) {
373 RCP<const XpMap> map = rangeMapExtractor->getMap(r);
374 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", *map);
376 XpIO::Write(
"fullRangeMap_" + fileName +
".m",*(rangeMapExtractor->getFullMap()));
378 for(
size_t c = 0; c < domainMapExtractor->NumMaps(); ++c) {
379 RCP<const XpMap> map = domainMapExtractor->getMap(c);
380 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", *map);
382 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
386 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) {
387 if (binary ==
false) {
390 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
391 Epetra_CrsMatrix *eA;
393 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
397 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
399 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A =
400 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
406 #ifdef HAVE_XPETRA_TPETRA
407 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
409 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
411 bool callFillComplete =
true;
413 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(fileName, comm, callFillComplete);
431 std::ifstream ifs(fileName.c_str(), std::ios::binary);
434 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
435 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
436 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
438 int myRank = comm->getRank();
443 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A;
446 Teuchos::Array<GlobalOrdinal> inds;
447 Teuchos::Array<Scalar> vals;
449 Teuchos::ArrayRCP<size_t> numEntriesPerRow(m);
450 for (
int i = 0; i < m; i++) {
452 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
453 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
454 numEntriesPerRow[i] = rownnz;
455 for (
int j = 0; j < rownnz; j++) {
457 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
459 for (
int j = 0; j < rownnz; j++) {
461 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
468 ifs.seekg(0, ifs.beg);
470 ifs.read(reinterpret_cast<char*>(&m),
sizeof(junk));
471 ifs.read(reinterpret_cast<char*>(&n),
sizeof(junk));
472 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(junk));
473 for (
int i = 0; i < m; i++) {
475 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
476 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
479 for (
int j = 0; j < rownnz; j++) {
481 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
482 inds[j] = Teuchos::as<GlobalOrdinal>(index);
484 for (
int j = 0; j < rownnz; j++) {
486 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
487 vals[j] = Teuchos::as<Scalar>(value);
489 A->insertGlobalValues(row, inds, vals);
493 A->fillComplete(domainMap, rangeMap);
498 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
507 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
508 Read(
const std::string& filename,
513 const bool callFillComplete =
true,
514 const bool binary =
false,
515 const bool tolerant =
false,
516 const bool debug =
false) {
519 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domain = (domainMap.is_null() ? rowMap : domainMap);
520 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > range = (rangeMap .is_null() ? rowMap : rangeMap);
523 if (binary ==
false) {
525 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
526 Epetra_CrsMatrix *eA;
532 if (colMap.is_null()) {
533 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
537 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
543 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
544 RCP<Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A =
545 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
552 #ifdef HAVE_XPETRA_TPETRA
553 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
554 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
555 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
557 const RCP<const map_type> tpetraRowMap =
Map2TpetraMap(*rowMap);
558 RCP<const map_type> tpetraColMap = (colMap.is_null() ? Teuchos::null :
Map2TpetraMap(*colMap));
559 const RCP<const map_type> tpetraRangeMap = (rangeMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*rangeMap));
560 const RCP<const map_type> tpetraDomainMap = (domainMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*domainMap));
562 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
563 callFillComplete, tolerant, debug);
580 std::ifstream ifs(filename.c_str(), std::ios::binary);
583 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
584 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
585 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
593 Teuchos::ArrayView<const GlobalOrdinal> rowElements = rowMap->getNodeElementList();
594 Teuchos::ArrayView<const GlobalOrdinal> colElements = colMap->getNodeElementList();
596 Teuchos::Array<GlobalOrdinal> inds;
597 Teuchos::Array<Scalar> vals;
598 for (
int i = 0; i < m; i++) {
600 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
601 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
604 for (
int j = 0; j < rownnz; j++) {
606 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
607 inds[j] = colElements[Teuchos::as<LocalOrdinal>(index)];
609 for (
int j = 0; j < rownnz; j++) {
611 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
612 vals[j] = Teuchos::as<SC>(value);
615 A->insertGlobalValues(rowElements[row], inds, vals);
617 A->fillComplete(domainMap, rangeMap);
621 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
626 static RCP<MultiVector>
ReadMultiVector (
const std::string& fileName,
const RCP<const Map>& map) {
633 #ifdef HAVE_XPETRA_TPETRA
634 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
635 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
636 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
637 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
639 RCP<const map_type> temp =
toTpetra(map);
640 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),temp);
650 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
657 #ifdef HAVE_XPETRA_TPETRA
658 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
659 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
661 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > tMap = reader_type::readMapFile(fileName, comm);
673 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
687 size_t numBlocks = 2;
689 std::vector<RCP<const XpMap> > rgMapVec;
690 for(
size_t r = 0; r < numBlocks; ++r) {
691 RCP<const XpMap> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", lib, comm);
692 rgMapVec.push_back(map);
694 RCP<const XpMap> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
696 std::vector<RCP<const XpMap> > doMapVec;
697 for(
size_t c = 0; c < numBlocks; ++c) {
698 RCP<const XpMap> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", lib, comm);
699 doMapVec.push_back(map);
701 RCP<const XpMap> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
717 bool bRangeUseThyraStyleNumbering =
false;
724 RCP<const XpMapExtractor> rangeMapExtractor =
725 Teuchos::rcp(
new XpMapExtractor(fullRangeMap, rgMapVec, bRangeUseThyraStyleNumbering));
729 bool bDomainUseThyraStyleNumbering =
false;
736 RCP<const XpMapExtractor> domainMapExtractor =
737 Teuchos::rcp(
new XpMapExtractor(fullDomainMap, doMapVec, bDomainUseThyraStyleNumbering));
739 RCP<XpBlockedCrsMat> bOp = Teuchos::rcp(
new XpBlockedCrsMat(rangeMapExtractor,domainMapExtractor,33));
742 for (
size_t r = 0; r < numBlocks; ++r) {
743 for (
size_t c = 0; c < numBlocks; ++c) {
744 RCP<const XpMap> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
745 RCP<const XpMap> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
746 RCP<const XpMap> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
747 RCP<const XpMap> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
748 RCP<XpMat> mat = XpIO::Read(fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
750 bOp->setMatrix(r, c, mat);
763 std::ostringstream buf;
770 #ifdef HAVE_XPETRA_EPETRA
780 template <
class Scalar>
787 #ifdef HAVE_XPETRA_EPETRA
792 if (xeMap == Teuchos::null)
793 throw Exceptions::BadCast(
"IO::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
794 return xeMap->getEpetra_Map();
799 #ifdef HAVE_XPETRA_TPETRA
804 if (tmp_TMap == Teuchos::null)
805 throw Exceptions::BadCast(
"IO::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
806 return tmp_TMap->getTpetra_Map();
815 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > tmp_Map = rcpFromRef(M);
816 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
818 if (tmp_EMap != Teuchos::null) {
819 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
824 #endif // HAVE_XPETRA_EPETRA
826 #ifdef HAVE_XPETRA_TPETRA
827 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
828 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
831 const RCP<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node> > &tmp_TMap =
833 if (tmp_TMap != Teuchos::null) {
834 RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > TMap = tmp_TMap->
getTpetra_Map();
835 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
839 #endif // HAVE_XPETRA_TPETRA
845 std::string mapfile =
"map_" + fileName;
848 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_Vec = Teuchos::rcpFromRef(vec);
849 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
851 if (tmp_EVec != Teuchos::null) {
852 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
857 #endif // HAVE_XPETRA_EPETRAEXT
859 #ifdef HAVE_XPETRA_TPETRA
860 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
861 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
864 const RCP<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &tmp_TVec =
866 if (tmp_TVec != Teuchos::null) {
867 RCP<const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > TVec = tmp_TVec->
getTpetra_MultiVector();
868 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeDenseFile(fileName, TVec);
872 #endif // HAVE_XPETRA_TPETRA
874 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
893 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
894 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
896 if (tmp_ECrsMtx != Teuchos::null) {
898 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
903 #endif // endif HAVE_XPETRA_EPETRA
905 #ifdef HAVE_XPETRA_TPETRA
906 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
907 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
910 const RCP<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& tmp_TCrsMtx =
912 if (tmp_TCrsMtx != Teuchos::null) {
913 RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A = tmp_TCrsMtx->
getTpetra_CrsMatrix();
914 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
918 #endif // HAVE_XPETRA_TPETRA
920 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
928 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
930 ArrayRCP<const size_t> rowptr_RCP;
931 ArrayRCP<LocalOrdinal> rowptr2_RCP;
932 ArrayRCP<const LocalOrdinal> colind_RCP;
933 ArrayRCP<const Scalar> vals_RCP;
934 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
936 ArrayView<const size_t> rowptr = rowptr_RCP();
937 ArrayView<const LocalOrdinal> colind = colind_RCP();
938 ArrayView<const Scalar> vals = vals_RCP();
940 rowptr2_RCP.resize(rowptr.size());
941 ArrayView<LocalOrdinal> rowptr2 = rowptr2_RCP();
942 for (
size_t j = 0; j<rowptr.size(); j++)
943 rowptr2[j] = rowptr[j];
945 Teuchos::MatrixMarket::Raw::Writer<Scalar,LocalOrdinal> writer;
946 writer.writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
948 rowptr.size()-1,Op.
getColMap()->getNodeNumElements());
961 for (
size_t r = 0; r < Op.
Rows(); ++r) {
962 for (
size_t c = 0; c < Op.
Cols(); ++c) {
964 if(m != Teuchos::null) {
966 "Sub block matrix (" << r <<
"," << c <<
") is not of type CrsMatrixWrap.");
976 for(
size_t r = 0; r < rangeMapExtractor->NumMaps(); ++r) {
977 RCP<const XpMap> map = rangeMapExtractor->getMap(r);
978 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", *map);
980 XpIO::Write(
"fullRangeMap_" + fileName +
".m",*(rangeMapExtractor->getFullMap()));
982 for(
size_t c = 0; c < domainMapExtractor->NumMaps(); ++c) {
983 RCP<const XpMap> map = domainMapExtractor->getMap(c);
984 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", *map);
986 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
990 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) {
991 if (binary ==
false) {
994 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
995 Epetra_CrsMatrix *eA;
997 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
1001 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
1003 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A =
1004 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
1010 #ifdef HAVE_XPETRA_TPETRA
1011 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1012 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1015 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1017 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1019 bool callFillComplete =
true;
1021 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(fileName, comm, callFillComplete);
1040 std::ifstream ifs(fileName.c_str(), std::ios::binary);
1043 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
1044 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
1045 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
1047 int myRank = comm->getRank();
1053 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A;
1056 Teuchos::Array<GlobalOrdinal> inds;
1057 Teuchos::Array<Scalar> vals;
1059 Teuchos::ArrayRCP<size_t> numEntriesPerRow(m);
1060 for (
int i = 0; i < m; i++) {
1062 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1063 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1064 numEntriesPerRow[i] = rownnz;
1065 for (
int j = 0; j < rownnz; j++) {
1067 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1069 for (
int j = 0; j < rownnz; j++) {
1071 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1078 ifs.seekg(0, ifs.beg);
1080 ifs.read(reinterpret_cast<char*>(&m),
sizeof(junk));
1081 ifs.read(reinterpret_cast<char*>(&n),
sizeof(junk));
1082 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(junk));
1083 for (
int i = 0; i < m; i++) {
1085 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1086 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1087 inds.resize(rownnz);
1088 vals.resize(rownnz);
1089 for (
int j = 0; j < rownnz; j++) {
1091 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1092 inds[j] = Teuchos::as<GlobalOrdinal>(index);
1094 for (
int j = 0; j < rownnz; j++) {
1096 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1097 vals[j] = Teuchos::as<Scalar>(value);
1099 A->insertGlobalValues(row, inds, vals);
1103 A->fillComplete(domainMap, rangeMap);
1108 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1117 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
Read(
const std::string& filename,
1122 const bool callFillComplete =
true,
1123 const bool binary =
false,
1124 const bool tolerant =
false,
1125 const bool debug =
false) {
1128 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domain = (domainMap.is_null() ? rowMap : domainMap);
1129 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > range = (rangeMap .is_null() ? rowMap : rangeMap);
1132 if (binary ==
false) {
1134 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1135 Epetra_CrsMatrix *eA;
1141 if (colMap.is_null()) {
1142 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
1146 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
1152 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
1153 RCP<Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A =
1154 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
1161 #ifdef HAVE_XPETRA_TPETRA
1162 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1163 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1166 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1167 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1168 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1170 const RCP<const map_type> tpetraRowMap =
Map2TpetraMap(*rowMap);
1171 RCP<const map_type> tpetraColMap = (colMap.is_null() ? Teuchos::null :
Map2TpetraMap(*colMap));
1172 const RCP<const map_type> tpetraRangeMap = (rangeMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*rangeMap));
1173 const RCP<const map_type> tpetraDomainMap = (domainMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*domainMap));
1175 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
1176 callFillComplete, tolerant, debug);
1194 std::ifstream ifs(filename.c_str(), std::ios::binary);
1197 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
1198 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
1199 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
1207 Teuchos::ArrayView<const GlobalOrdinal> rowElements = rowMap->getNodeElementList();
1208 Teuchos::ArrayView<const GlobalOrdinal> colElements = colMap->getNodeElementList();
1210 Teuchos::Array<GlobalOrdinal> inds;
1211 Teuchos::Array<Scalar> vals;
1212 for (
int i = 0; i < m; i++) {
1214 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1215 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1216 inds.resize(rownnz);
1217 vals.resize(rownnz);
1218 for (
int j = 0; j < rownnz; j++) {
1220 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1221 inds[j] = colElements[Teuchos::as<LocalOrdinal>(index)];
1223 for (
int j = 0; j < rownnz; j++) {
1225 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1226 vals[j] = Teuchos::as<Scalar>(value);
1229 A->insertGlobalValues(rowElements[row], inds, vals);
1231 A->fillComplete(domainMap, rangeMap);
1235 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1246 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1247 Epetra_MultiVector * MV;
1248 EpetraExt::MatrixMarketFileToMultiVector(fileName.c_str(),
toEpetra(map), MV);
1249 RCP<Epetra_MultiVector> MVrcp = rcp(MV);
1250 return Convert_Epetra_MultiVector_ToXpetra_MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(MVrcp);
1255 #ifdef HAVE_XPETRA_TPETRA
1256 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1257 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1260 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1261 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1262 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1263 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
1265 RCP<const map_type> temp =
toTpetra(map);
1266 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),temp);
1267 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > rmv =
Xpetra::toXpetra(TMV);
1277 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1282 static RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
ReadMap (
const std::string& fileName,
Xpetra::UnderlyingLib lib,
const RCP<
const Teuchos::Comm<int> >& comm) {
1286 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1288 int rv = EpetraExt::MatrixMarketFileToMap(fileName.c_str(), *(
Xpetra::toEpetra(comm)), eMap);
1292 RCP<Epetra_Map> eMap1 = rcp(
new Epetra_Map(*eMap));
1293 return Xpetra::toXpetra<int,Node>(*eMap1);
1298 #ifdef HAVE_XPETRA_TPETRA
1299 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1300 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1303 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1304 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1306 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > tMap = reader_type::readMapFile(fileName, comm);
1319 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1334 size_t numBlocks = 2;
1336 std::vector<RCP<const XpMap> > rgMapVec;
1337 for(
size_t r = 0; r < numBlocks; ++r) {
1338 RCP<const XpMap> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", lib, comm);
1339 rgMapVec.push_back(map);
1341 RCP<const XpMap> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
1343 std::vector<RCP<const XpMap> > doMapVec;
1344 for(
size_t c = 0; c < numBlocks; ++c) {
1345 RCP<const XpMap> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", lib, comm);
1346 doMapVec.push_back(map);
1348 RCP<const XpMap> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
1364 bool bRangeUseThyraStyleNumbering =
false;
1371 RCP<const XpMapExtractor> rangeMapExtractor =
1372 Teuchos::rcp(
new XpMapExtractor(fullRangeMap, rgMapVec, bRangeUseThyraStyleNumbering));
1375 bool bDomainUseThyraStyleNumbering =
false;
1381 RCP<const XpMapExtractor> domainMapExtractor =
1382 Teuchos::rcp(
new XpMapExtractor(fullDomainMap, doMapVec, bDomainUseThyraStyleNumbering));
1384 RCP<XpBlockedCrsMat> bOp = Teuchos::rcp(
new XpBlockedCrsMat(rangeMapExtractor,domainMapExtractor,33));
1387 for (
size_t r = 0; r < numBlocks; ++r) {
1388 for (
size_t c = 0; c < numBlocks; ++c) {
1389 RCP<const XpMap> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1390 RCP<const XpMap> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1391 RCP<const XpMap> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1392 RCP<const XpMap> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1393 RCP<XpMat> mat = XpIO::Read(fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
1395 bOp->setMatrix(r, c, mat);
1399 bOp->fillComplete();
1407 std::ostringstream buf;
1412 #endif // HAVE_XPETRA_EPETRA
1417 #define XPETRA_IO_SHORT
RCP< CrsMatrix > getCrsMatrix() const
std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.
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< 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.
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 matrix to file 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.
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)
Teuchos::RCP< Matrix > getMatrix(size_t r, size_t c) const
return block (r,c)
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 size_t Cols() const
number of column blocks
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 matrix to file in Matrix Market format.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
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 matrix to file in Matrix Market format.
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.
RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetra_Map() const
Get the underlying Tpetra map.
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 MapExtractor > getDomainMapExtractor() const
Returns map extractor for domain map.
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
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.
RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrix() const
Get the underlying Tpetra matrix.
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.
virtual Teuchos::RCP< const Map > getRangeMap() const =0
The Map associated with the range of this operator, which must be compatible with Y...
virtual size_t Rows() const
number of row blocks
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_MultiVector() const
Get the underlying Tpetra multivector.
virtual const RCP< const Map > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
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.
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 matrix to file in Matrix Market format.
RCP< const MapExtractor > getRangeMapExtractor() const
Returns map extractor class for range map.
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.