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>
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");
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");
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();
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
238 if (tmp_TMap != Teuchos::null) {
240 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
243 #endif // HAVE_XPETRA_TPETRA
251 std::string mapfile =
"map_" + fileName;
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
268 if (tmp_TVec != Teuchos::null) {
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");
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
305 if (tmp_TCrsMtx != Teuchos::null) {
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");
326 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
334 for (
size_t j = 0; j<rowptr.
size(); j++)
335 rowptr2[j] = rowptr[j];
338 writer.
writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
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) {
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) {
377 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", *map);
379 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
384 if (binary ==
false) {
387 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
390 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
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;
408 bool callFillComplete =
true;
428 std::ifstream ifs(fileName.c_str(), std::ios::binary);
431 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
432 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
433 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
435 int myRank = comm->getRank();
447 for (
int i = 0; i < m; i++) {
449 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
450 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
453 for (
int j = 0; j < rownnz; j++) {
455 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
456 inds[j] = Teuchos::as<GlobalOrdinal>(index);
458 for (
int j = 0; j < rownnz; j++) {
460 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
461 vals[j] = Teuchos::as<SC>(value);
463 A->insertGlobalValues(row, inds, vals);
467 A->fillComplete(domainMap, rangeMap);
482 Read(
const std::string& filename,
487 const bool callFillComplete =
true,
488 const bool binary =
false,
489 const bool tolerant =
false,
490 const bool debug =
false) {
497 if (binary ==
false) {
499 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
506 if (colMap.is_null()) {
507 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
511 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
519 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
526 #ifdef HAVE_XPETRA_TPETRA
527 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
528 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
529 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
536 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
537 callFillComplete, tolerant, debug);
554 std::ifstream ifs(filename.c_str(), std::ios::binary);
557 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
558 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
559 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
570 for (
int i = 0; i < m; i++) {
572 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
573 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
576 for (
int j = 0; j < rownnz; j++) {
578 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
579 inds[j] = colElements[Teuchos::as<LocalOrdinal>(index)];
581 for (
int j = 0; j < rownnz; j++) {
583 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
584 vals[j] = Teuchos::as<SC>(value);
586 A->insertGlobalValues(rowElements[row], inds, vals);
588 A->fillComplete(domainMap, rangeMap);
604 #ifdef HAVE_XPETRA_TPETRA
605 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
606 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
607 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
608 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
628 #ifdef HAVE_XPETRA_TPETRA
629 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
630 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
658 size_t numBlocks = 2;
660 std::vector<RCP<const XpMap> > rgMapVec;
661 for(
size_t r = 0; r < numBlocks; ++r) {
662 RCP<const XpMap> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", lib, comm);
663 rgMapVec.push_back(map);
665 RCP<const XpMap> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
667 std::vector<RCP<const XpMap> > doMapVec;
668 for(
size_t c = 0; c < numBlocks; ++c) {
669 RCP<const XpMap> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", lib, comm);
670 doMapVec.push_back(map);
672 RCP<const XpMap> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
688 bool bRangeUseThyraStyleNumbering =
false;
696 Teuchos::rcp(
new XpMapExtractor(fullRangeMap, rgMapVec, bRangeUseThyraStyleNumbering));
700 bool bDomainUseThyraStyleNumbering =
false;
708 Teuchos::rcp(
new XpMapExtractor(fullDomainMap, doMapVec, bDomainUseThyraStyleNumbering));
713 for (
size_t r = 0; r < numBlocks; ++r) {
714 for (
size_t c = 0; c < numBlocks; ++c) {
715 RCP<const XpMap> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
716 RCP<const XpMap> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
717 RCP<const XpMap> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
718 RCP<const XpMap> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
719 RCP<XpMat> mat = XpIO::Read(fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
721 bOp->setMatrix(r, c, mat);
734 std::ostringstream buf;
741 #ifdef HAVE_XPETRA_EPETRA
751 template <
class Scalar>
758 #ifdef HAVE_XPETRA_EPETRA
763 if (xeMap == Teuchos::null)
764 throw Exceptions::BadCast(
"IO::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
765 return xeMap->getEpetra_Map();
770 #ifdef HAVE_XPETRA_TPETRA
775 if (tmp_TMap == Teuchos::null)
776 throw Exceptions::BadCast(
"IO::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
777 return tmp_TMap->getTpetra_Map();
787 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
789 if (tmp_EMap != Teuchos::null) {
790 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
795 #endif // HAVE_XPETRA_EPETRA
797 #ifdef HAVE_XPETRA_TPETRA
798 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
799 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
804 if (tmp_TMap != Teuchos::null) {
806 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
810 #endif // HAVE_XPETRA_TPETRA
816 std::string mapfile =
"map_" + fileName;
820 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
822 if (tmp_EVec != Teuchos::null) {
823 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
828 #endif // HAVE_XPETRA_EPETRAEXT
830 #ifdef HAVE_XPETRA_TPETRA
831 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
832 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
837 if (tmp_TVec != Teuchos::null) {
839 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeDenseFile(fileName, TVec);
843 #endif // HAVE_XPETRA_TPETRA
845 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
862 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
864 if (tmp_ECrsMtx != Teuchos::null) {
866 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
871 #endif // endif HAVE_XPETRA_EPETRA
873 #ifdef HAVE_XPETRA_TPETRA
874 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
875 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
880 if (tmp_TCrsMtx != Teuchos::null) {
882 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
886 #endif // HAVE_XPETRA_TPETRA
888 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
902 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
910 for (
size_t j = 0; j<rowptr.
size(); j++)
911 rowptr2[j] = rowptr[j];
914 writer.
writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
929 for (
size_t r = 0; r < Op.
Rows(); ++r) {
930 for (
size_t c = 0; c < Op.
Cols(); ++c) {
932 if(m != Teuchos::null) {
934 "Sub block matrix (" << r <<
"," << c <<
") is not of type CrsMatrixWrap.");
944 for(
size_t r = 0; r < rangeMapExtractor->NumMaps(); ++r) {
946 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", *map);
948 XpIO::Write(
"fullRangeMap_" + fileName +
".m",*(rangeMapExtractor->getFullMap()));
950 for(
size_t c = 0; c < domainMapExtractor->NumMaps(); ++c) {
952 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", *map);
954 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
959 if (binary ==
false) {
962 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
965 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
972 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
978 #ifdef HAVE_XPETRA_TPETRA
979 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
980 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
983 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
985 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
987 bool callFillComplete =
true;
1008 std::ifstream ifs(fileName.c_str(), std::ios::binary);
1011 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
1012 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
1013 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
1015 int myRank = comm->getRank();
1027 for (
int i = 0; i < m; i++) {
1029 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1030 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1033 for (
int j = 0; j < rownnz; j++) {
1035 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1036 inds[j] = Teuchos::as<GlobalOrdinal>(index);
1038 for (
int j = 0; j < rownnz; j++) {
1040 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1041 vals[j] = Teuchos::as<Scalar>(value);
1043 A->insertGlobalValues(row, inds, vals);
1047 A->fillComplete(domainMap, rangeMap);
1066 const bool callFillComplete =
true,
1067 const bool binary =
false,
1068 const bool tolerant =
false,
1069 const bool debug =
false) {
1076 if (binary ==
false) {
1078 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1085 if (colMap.is_null()) {
1086 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
1090 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
1098 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
1105 #ifdef HAVE_XPETRA_TPETRA
1106 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1107 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1110 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1111 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1112 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1119 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
1120 callFillComplete, tolerant, debug);
1138 std::ifstream ifs(filename.c_str(), std::ios::binary);
1141 ifs.read(reinterpret_cast<char*>(&m),
sizeof(m));
1142 ifs.read(reinterpret_cast<char*>(&n),
sizeof(n));
1143 ifs.read(reinterpret_cast<char*>(&nnz),
sizeof(nnz));
1154 for (
int i = 0; i < m; i++) {
1156 ifs.read(reinterpret_cast<char*>(&row),
sizeof(row));
1157 ifs.read(reinterpret_cast<char*>(&rownnz),
sizeof(rownnz));
1160 for (
int j = 0; j < rownnz; j++) {
1162 ifs.read(reinterpret_cast<char*>(&index),
sizeof(index));
1163 inds[j] = colElements[Teuchos::as<LocalOrdinal>(index)];
1165 for (
int j = 0; j < rownnz; j++) {
1167 ifs.read(reinterpret_cast<char*>(&value),
sizeof(value));
1168 vals[j] = Teuchos::as<Scalar>(value);
1170 A->insertGlobalValues(rowElements[row], inds, vals);
1172 A->fillComplete(domainMap, rangeMap);
1187 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1189 EpetraExt::MatrixMarketFileToMultiVector(fileName.c_str(),
toEpetra(map), MV);
1191 return Convert_Epetra_MultiVector_ToXpetra_MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(MVrcp);
1196 #ifdef HAVE_XPETRA_TPETRA
1197 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1198 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1201 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1202 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1203 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1204 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
1227 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1229 int rv = EpetraExt::MatrixMarketFileToMap(fileName.c_str(), *(
Xpetra::toEpetra(comm)), eMap);
1234 return Xpetra::toXpetra<int,Node>(*eMap1);
1239 #ifdef HAVE_XPETRA_TPETRA
1240 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1241 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1244 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1245 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1275 size_t numBlocks = 2;
1277 std::vector<RCP<const XpMap> > rgMapVec;
1278 for(
size_t r = 0; r < numBlocks; ++r) {
1279 RCP<const XpMap> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(r) +
".m", lib, comm);
1280 rgMapVec.push_back(map);
1282 RCP<const XpMap> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
1284 std::vector<RCP<const XpMap> > doMapVec;
1285 for(
size_t c = 0; c < numBlocks; ++c) {
1286 RCP<const XpMap> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", lib, comm);
1287 doMapVec.push_back(map);
1289 RCP<const XpMap> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
1305 bool bRangeUseThyraStyleNumbering =
false;
1313 Teuchos::rcp(
new XpMapExtractor(fullRangeMap, rgMapVec, bRangeUseThyraStyleNumbering));
1316 bool bDomainUseThyraStyleNumbering =
false;
1323 Teuchos::rcp(
new XpMapExtractor(fullDomainMap, doMapVec, bDomainUseThyraStyleNumbering));
1328 for (
size_t r = 0; r < numBlocks; ++r) {
1329 for (
size_t c = 0; c < numBlocks; ++c) {
1330 RCP<const XpMap> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1331 RCP<const XpMap> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1332 RCP<const XpMap> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1333 RCP<const XpMap> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", lib, comm);
1334 RCP<XpMat> mat = XpIO::Read(fileName + XpIO::toString<size_t>(r) + XpIO::toString<size_t>(c) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
1336 bOp->setMatrix(r, c, mat);
1340 bOp->fillComplete();
1348 std::ostringstream buf;
1353 #endif // HAVE_XPETRA_EPETRA
1358 #define XPETRA_IO_SHORT
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< CrsMatrix > getCrsMatrix() const
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.
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.
void resize(const size_type n, const T &val=T())
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
RCP< Xpetra::MultiVector< SC, LO, GO, NO > > Convert_Epetra_MultiVector_ToXpetra_MultiVector(RCP< Epetra_MultiVector > &epX)
void resize(size_type new_size, const value_type &x=value_type())
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)
void writeFile(const std::string &filename, const ArrayView< const OrdinalType > &rowptr, const ArrayView< const OrdinalType > &colind, const ArrayView< const ScalarType > &values, const OrdinalType numRows, const OrdinalType numCols)
RCP< const MapExtractor > getDomainMapExtractor() const
Returns map extractor for domain map.
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
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.
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
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.
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 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 const Epetra_Map & Map2EpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
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 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.
std::string toString(const T &t)
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.
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.