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> 81 #ifdef HAVE_XPETRA_EPETRA 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");
290 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
291 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 293 if (tmp_ECrsMtx != Teuchos::null) {
295 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
302 #ifdef HAVE_XPETRA_TPETRA 303 const RCP<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& tmp_TCrsMtx =
305 if (tmp_TCrsMtx != Teuchos::null) {
306 RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A = tmp_TCrsMtx->
getTpetra_CrsMatrix();
307 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
310 #endif // HAVE_XPETRA_TPETRA 312 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
320 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
322 ArrayRCP<const size_t> rowptr_RCP;
323 ArrayRCP<LocalOrdinal> rowptr2_RCP;
324 ArrayRCP<const LocalOrdinal> colind_RCP;
325 ArrayRCP<const Scalar> vals_RCP;
326 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
328 ArrayView<const size_t> rowptr = rowptr_RCP();
329 ArrayView<const LocalOrdinal> colind = colind_RCP();
330 ArrayView<const Scalar> vals = vals_RCP();
332 rowptr2_RCP.resize(rowptr.size());
333 ArrayView<LocalOrdinal> rowptr2 = rowptr2_RCP();
334 for (
size_t j = 0; j<rowptr.size(); j++)
335 rowptr2[j] = rowptr[j];
337 Teuchos::MatrixMarket::Raw::Writer<Scalar,LocalOrdinal> writer;
338 writer.writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
340 rowptr.size()-1,Op.
getColMap()->getNodeNumElements());
354 for (
size_t r = 0; r < Op.
Rows(); ++r) {
355 for (
size_t c = 0; c < Op.
Cols(); ++c) {
357 if(m != Teuchos::null) {
359 "Sub block matrix (" << r <<
"," << c <<
") is not of type CrsMatrixWrap.");
369 for(
size_t r = 0; r < rangeMapExtractor->NumMaps(); ++r) {
370 RCP<const XpMap> map = rangeMapExtractor->getMap(r);
371 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", *map);
373 XpIO::Write(
"fullRangeMap_" + fileName +
".m",*(rangeMapExtractor->getFullMap()));
375 for(
size_t c = 0; c < domainMapExtractor->NumMaps(); ++c) {
376 RCP<const XpMap> map = domainMapExtractor->getMap(c);
377 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", *map);
379 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
383 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) {
384 if (binary ==
false) {
387 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 390 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
394 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
396 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A =
397 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
403 #ifdef HAVE_XPETRA_TPETRA 404 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
406 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
409 Teuchos::ParameterList pl = Teuchos::ParameterList();
410 RCP<Node> node = rcp(
new Node(pl));
411 bool callFillComplete =
true;
413 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(fileName, comm, node, 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();
448 Teuchos::Array<GlobalOrdinal> inds;
449 Teuchos::Array<Scalar> vals;
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));
456 for (
int j = 0; j < rownnz; j++) {
458 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
459 inds[j] = Teuchos::as<GlobalOrdinal>(index);
461 for (
int j = 0; j < rownnz; j++) {
463 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
464 vals[j] = Teuchos::as<SC>(value);
466 A->insertGlobalValues(row, inds, vals);
470 A->fillComplete(domainMap, rangeMap);
475 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
484 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
485 Read(
const std::string& filename,
490 const bool callFillComplete =
true,
491 const bool binary =
false,
492 const bool tolerant =
false,
493 const bool debug =
false) {
496 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domain = (domainMap.is_null() ? rowMap : domainMap);
497 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > range = (rangeMap .is_null() ? rowMap : rangeMap);
500 if (binary ==
false) {
502 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 509 if (colMap.is_null()) {
510 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
514 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
520 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
521 RCP<Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A =
522 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
529 #ifdef HAVE_XPETRA_TPETRA 530 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
531 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
532 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
534 const RCP<const map_type> tpetraRowMap =
Map2TpetraMap(*rowMap);
535 RCP<const map_type> tpetraColMap = (colMap.is_null() ? Teuchos::null :
Map2TpetraMap(*colMap));
536 const RCP<const map_type> tpetraRangeMap = (rangeMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*rangeMap));
537 const RCP<const map_type> tpetraDomainMap = (domainMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*domainMap));
539 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
540 callFillComplete, tolerant, debug);
557 std::ifstream ifs(filename.c_str(), std::ios::binary);
560 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
561 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
562 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
568 Teuchos::ArrayView<const GlobalOrdinal> rowElements = rowMap->getNodeElementList();
569 Teuchos::ArrayView<const GlobalOrdinal> colElements = colMap->getNodeElementList();
571 Teuchos::Array<GlobalOrdinal> inds;
572 Teuchos::Array<Scalar> vals;
573 for (
int i = 0; i < m; i++) {
575 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
576 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
579 for (
int j = 0; j < rownnz; j++) {
581 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
582 inds[j] = colElements[Teuchos::as<LocalOrdinal>(index)];
584 for (
int j = 0; j < rownnz; j++) {
586 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
587 vals[j] = Teuchos::as<SC>(value);
589 A->insertGlobalValues(rowElements[row], inds, vals);
591 A->fillComplete(domainMap, rangeMap);
595 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
600 static RCP<MultiVector>
ReadMultiVector (
const std::string& fileName,
const RCP<const Map>& map) {
607 #ifdef HAVE_XPETRA_TPETRA 608 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
609 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
610 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
611 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
613 RCP<const map_type> temp =
toTpetra(map);
614 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),map->getNode(),temp);
624 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
631 #ifdef HAVE_XPETRA_TPETRA 632 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
633 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
635 RCP<Node> node = rcp(
new Node());
637 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > tMap = reader_type::readMapFile(fileName, comm, node);
649 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
663 size_t numBlocks = 2;
665 std::vector<RCP<const XpMap> > rgMapVec;
666 for(
size_t r = 0; r < numBlocks; ++r) {
667 RCP<const XpMap> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", lib, comm);
668 rgMapVec.push_back(map);
670 RCP<const XpMap> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
672 std::vector<RCP<const XpMap> > doMapVec;
673 for(
size_t c = 0; c < numBlocks; ++c) {
674 RCP<const XpMap> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", lib, comm);
675 doMapVec.push_back(map);
677 RCP<const XpMap> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
693 bool bRangeUseThyraStyleNumbering =
false;
700 RCP<const XpMapExtractor> rangeMapExtractor =
701 Teuchos::rcp(
new XpMapExtractor(fullRangeMap, rgMapVec, bRangeUseThyraStyleNumbering));
705 bool bDomainUseThyraStyleNumbering =
false;
712 RCP<const XpMapExtractor> domainMapExtractor =
713 Teuchos::rcp(
new XpMapExtractor(fullDomainMap, doMapVec, bDomainUseThyraStyleNumbering));
715 RCP<XpBlockedCrsMat> bOp = Teuchos::rcp(
new XpBlockedCrsMat(rangeMapExtractor,domainMapExtractor,33));
718 for (
size_t r = 0; r < numBlocks; ++r) {
719 for (
size_t c = 0; c < numBlocks; ++c) {
720 RCP<const XpMap> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
721 RCP<const XpMap> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
722 RCP<const XpMap> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
723 RCP<const XpMap> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
724 RCP<XpMat> mat = XpIO::Read(fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
726 bOp->setMatrix(r, c, mat);
739 std::ostringstream buf;
746 #ifdef HAVE_XPETRA_EPETRA 756 template <
class Scalar>
763 #ifdef HAVE_XPETRA_EPETRA 768 if (xeMap == Teuchos::null)
769 throw Exceptions::BadCast(
"IO::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
770 return xeMap->getEpetra_Map();
775 #ifdef HAVE_XPETRA_TPETRA 780 if (tmp_TMap == Teuchos::null)
781 throw Exceptions::BadCast(
"IO::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
782 return tmp_TMap->getTpetra_Map();
791 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > tmp_Map = rcpFromRef(M);
792 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 794 if (tmp_EMap != Teuchos::null) {
795 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
800 #endif // HAVE_XPETRA_EPETRA 802 #ifdef HAVE_XPETRA_TPETRA 803 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 804 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 807 const RCP<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node> > &tmp_TMap =
809 if (tmp_TMap != Teuchos::null) {
810 RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > TMap = tmp_TMap->
getTpetra_Map();
811 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
815 #endif // HAVE_XPETRA_TPETRA 821 std::string mapfile =
"map_" + fileName;
824 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_Vec = Teuchos::rcpFromRef(vec);
825 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 827 if (tmp_EVec != Teuchos::null) {
828 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
833 #endif // HAVE_XPETRA_EPETRAEXT 835 #ifdef HAVE_XPETRA_TPETRA 836 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 837 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 840 const RCP<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &tmp_TVec =
842 if (tmp_TVec != Teuchos::null) {
843 RCP<const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > TVec = tmp_TVec->
getTpetra_MultiVector();
844 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeDenseFile(fileName, TVec);
848 #endif // HAVE_XPETRA_TPETRA 850 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
866 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
867 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 869 if (tmp_ECrsMtx != Teuchos::null) {
871 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
876 #endif // endif HAVE_XPETRA_EPETRA 878 #ifdef HAVE_XPETRA_TPETRA 879 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 880 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 883 const RCP<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& tmp_TCrsMtx =
885 if (tmp_TCrsMtx != Teuchos::null) {
886 RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A = tmp_TCrsMtx->
getTpetra_CrsMatrix();
887 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
891 #endif // HAVE_XPETRA_TPETRA 893 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
901 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tmp_CrsMtx = crsOp.
getCrsMatrix();
903 ArrayRCP<const size_t> rowptr_RCP;
904 ArrayRCP<LocalOrdinal> rowptr2_RCP;
905 ArrayRCP<const LocalOrdinal> colind_RCP;
906 ArrayRCP<const Scalar> vals_RCP;
907 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
909 ArrayView<const size_t> rowptr = rowptr_RCP();
910 ArrayView<const LocalOrdinal> colind = colind_RCP();
911 ArrayView<const Scalar> vals = vals_RCP();
913 rowptr2_RCP.resize(rowptr.size());
914 ArrayView<LocalOrdinal> rowptr2 = rowptr2_RCP();
915 for (
size_t j = 0; j<rowptr.size(); j++)
916 rowptr2[j] = rowptr[j];
918 Teuchos::MatrixMarket::Raw::Writer<Scalar,LocalOrdinal> writer;
919 writer.writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
921 rowptr.size()-1,Op.
getColMap()->getNodeNumElements());
934 for (
size_t r = 0; r < Op.
Rows(); ++r) {
935 for (
size_t c = 0; c < Op.
Cols(); ++c) {
937 if(m != Teuchos::null) {
939 "Sub block matrix (" << r <<
"," << c <<
") is not of type CrsMatrixWrap.");
949 for(
size_t r = 0; r < rangeMapExtractor->NumMaps(); ++r) {
950 RCP<const XpMap> map = rangeMapExtractor->getMap(r);
951 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", *map);
953 XpIO::Write(
"fullRangeMap_" + fileName +
".m",*(rangeMapExtractor->getFullMap()));
955 for(
size_t c = 0; c < domainMapExtractor->NumMaps(); ++c) {
956 RCP<const XpMap> map = domainMapExtractor->getMap(c);
957 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", *map);
959 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
963 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) {
964 if (binary ==
false) {
967 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 970 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
974 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
976 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A =
977 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
983 #ifdef HAVE_XPETRA_TPETRA 984 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 985 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 988 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
990 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
993 Teuchos::ParameterList pl = Teuchos::ParameterList();
994 RCP<Node> node = rcp(
new Node(pl));
995 bool callFillComplete =
true;
997 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(fileName, comm, node, callFillComplete);
1016 std::ifstream ifs(fileName.c_str(), std::ios::binary);
1019 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
1020 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
1021 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
1023 int myRank = comm->getRank();
1033 Teuchos::Array<GlobalOrdinal> inds;
1034 Teuchos::Array<Scalar> vals;
1035 for (
int i = 0; i < m; i++) {
1037 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1038 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1039 inds.resize(rownnz);
1040 vals.resize(rownnz);
1041 for (
int j = 0; j < rownnz; j++) {
1043 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1044 inds[j] = Teuchos::as<GlobalOrdinal>(index);
1046 for (
int j = 0; j < rownnz; j++) {
1048 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1049 vals[j] = Teuchos::as<Scalar>(value);
1051 A->insertGlobalValues(row, inds, vals);
1055 A->fillComplete(domainMap, rangeMap);
1060 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1069 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
Read(
const std::string& filename,
1074 const bool callFillComplete =
true,
1075 const bool binary =
false,
1076 const bool tolerant =
false,
1077 const bool debug =
false) {
1080 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domain = (domainMap.is_null() ? rowMap : domainMap);
1081 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > range = (rangeMap .is_null() ? rowMap : rangeMap);
1084 if (binary ==
false) {
1086 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1093 if (colMap.is_null()) {
1094 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
1098 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
1104 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
1105 RCP<Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A =
1106 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
1113 #ifdef HAVE_XPETRA_TPETRA 1114 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 1115 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 1118 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1119 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1120 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1122 const RCP<const map_type> tpetraRowMap =
Map2TpetraMap(*rowMap);
1123 RCP<const map_type> tpetraColMap = (colMap.is_null() ? Teuchos::null :
Map2TpetraMap(*colMap));
1124 const RCP<const map_type> tpetraRangeMap = (rangeMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*rangeMap));
1125 const RCP<const map_type> tpetraDomainMap = (domainMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*domainMap));
1127 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
1128 callFillComplete, tolerant, debug);
1146 std::ifstream ifs(filename.c_str(), std::ios::binary);
1149 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
1150 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
1151 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
1157 Teuchos::ArrayView<const GlobalOrdinal> rowElements = rowMap->getNodeElementList();
1158 Teuchos::ArrayView<const GlobalOrdinal> colElements = colMap->getNodeElementList();
1160 Teuchos::Array<GlobalOrdinal> inds;
1161 Teuchos::Array<Scalar> vals;
1162 for (
int i = 0; i < m; i++) {
1164 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1165 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1166 inds.resize(rownnz);
1167 vals.resize(rownnz);
1168 for (
int j = 0; j < rownnz; j++) {
1170 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1171 inds[j] = colElements[Teuchos::as<LocalOrdinal>(index)];
1173 for (
int j = 0; j < rownnz; j++) {
1175 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1176 vals[j] = Teuchos::as<Scalar>(value);
1178 A->insertGlobalValues(rowElements[row], inds, vals);
1180 A->fillComplete(domainMap, rangeMap);
1184 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1195 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1197 EpetraExt::MatrixMarketFileToMultiVector(fileName.c_str(),
toEpetra(map), MV);
1198 RCP<Epetra_MultiVector> MVrcp = rcp(MV);
1199 return Convert_Epetra_MultiVector_ToXpetra_MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(MVrcp);
1204 #ifdef HAVE_XPETRA_TPETRA 1205 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 1206 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 1209 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1210 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1211 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1212 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
1214 RCP<const map_type> temp =
toTpetra(map);
1215 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),map->getNode(),temp);
1216 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > rmv =
Xpetra::toXpetra(TMV);
1226 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1231 static RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
ReadMap (
const std::string& fileName,
Xpetra::UnderlyingLib lib,
const RCP<
const Teuchos::Comm<int> >& comm) {
1235 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1237 int rv = EpetraExt::MatrixMarketFileToMap(fileName.c_str(), *(
Xpetra::toEpetra(comm)), eMap);
1241 RCP<Epetra_Map> eMap1 = rcp(
new Epetra_Map(*eMap));
1242 return Xpetra::toXpetra<int,Node>(*eMap1);
1247 #ifdef HAVE_XPETRA_TPETRA 1248 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ 1249 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) 1252 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1253 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1255 RCP<Node> node = rcp(
new Node());
1257 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > tMap = reader_type::readMapFile(fileName, comm, node);
1270 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1285 size_t numBlocks = 2;
1287 std::vector<RCP<const XpMap> > rgMapVec;
1288 for(
size_t r = 0; r < numBlocks; ++r) {
1289 RCP<const XpMap> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", lib, comm);
1290 rgMapVec.push_back(map);
1292 RCP<const XpMap> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
1294 std::vector<RCP<const XpMap> > doMapVec;
1295 for(
size_t c = 0; c < numBlocks; ++c) {
1296 RCP<const XpMap> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", lib, comm);
1297 doMapVec.push_back(map);
1299 RCP<const XpMap> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
1315 bool bRangeUseThyraStyleNumbering =
false;
1322 RCP<const XpMapExtractor> rangeMapExtractor =
1323 Teuchos::rcp(
new XpMapExtractor(fullRangeMap, rgMapVec, bRangeUseThyraStyleNumbering));
1326 bool bDomainUseThyraStyleNumbering =
false;
1332 RCP<const XpMapExtractor> domainMapExtractor =
1333 Teuchos::rcp(
new XpMapExtractor(fullDomainMap, doMapVec, bDomainUseThyraStyleNumbering));
1335 RCP<XpBlockedCrsMat> bOp = Teuchos::rcp(
new XpBlockedCrsMat(rangeMapExtractor,domainMapExtractor,33));
1338 for (
size_t r = 0; r < numBlocks; ++r) {
1339 for (
size_t c = 0; c < numBlocks; ++c) {
1340 RCP<const XpMap> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1341 RCP<const XpMap> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1342 RCP<const XpMap> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1343 RCP<const XpMap> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1344 RCP<XpMat> mat = XpIO::Read(fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
1346 bOp->setMatrix(r, c, mat);
1350 bOp->fillComplete();
1358 std::ostringstream buf;
1363 #endif // HAVE_XPETRA_EPETRA 1368 #define XPETRA_IO_SHORT
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< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetra_Map() const
Get the underlying Tpetra map.
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.
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::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
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.
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.
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 void WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Save matrix to file in Matrix Market format.
static RCP< const Map > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
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.
RCP< CrsMatrix > getCrsMatrix() const
RCP< Xpetra::MultiVector< SC, LO, GO, NO > > Convert_Epetra_MultiVector_ToXpetra_MultiVector(RCP< Epetra_MultiVector > &epX)
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.
RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrix() const
Get the underlying Tpetra matrix.
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
RCP< Xpetra::CrsMatrixWrap< SC, LO, GO, NO > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP< Epetra_CrsMatrix > &epAB)
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.
static RCP< Matrix > Build(const RCP< const Map > &rowMap, size_t maxNumEntriesPerRow, Xpetra::ProfileType pftype=Xpetra::DynamicProfile)
Constructor specifying the number of non-zeros for all rows.
static RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_MultiVector() const
Get the underlying Tpetra multivector.
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
static void Write(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Save matrix to file in Matrix Market format.
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 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, const Teuchos::RCP< Node > &=Teuchos::null)
Map constructor with Xpetra-defined contiguous uniform distribution.
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::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 void WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Save matrix to file in Matrix Market format.
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 std::string toString(const T &what)
Little helper function to convert non-string types to strings.