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");
129 template<
class SC,
class LO,
class GO,
class 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;
411 bool callFillComplete =
true;
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();
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);
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) {
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);
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;
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));
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);
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;
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;
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;
701 Teuchos::rcp(
new XpMapExtractor(fullRangeMap, rgMapVec, bRangeUseThyraStyleNumbering));
705 bool bDomainUseThyraStyleNumbering =
false;
713 Teuchos::rcp(
new XpMapExtractor(fullDomainMap, doMapVec, bDomainUseThyraStyleNumbering));
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();
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)))) 809 if (tmp_TMap != Teuchos::null) {
811 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
815 #endif // HAVE_XPETRA_TPETRA 821 std::string mapfile =
"map_" + fileName;
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)))) 842 if (tmp_TVec != Teuchos::null) {
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");
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)))) 885 if (tmp_TCrsMtx != Teuchos::null) {
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");
907 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
915 for (
size_t j = 0; j<rowptr.
size(); j++)
916 rowptr2[j] = rowptr[j];
919 writer.
writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
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) {
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) {
957 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(c) +
".m", *map);
959 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
964 if (binary ==
false) {
967 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 970 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
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;
995 bool callFillComplete =
true;
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();
1025 GlobalOrdinal indexBase = 0;
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));
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);
1074 const bool callFillComplete =
true,
1075 const bool binary =
false,
1076 const bool tolerant =
false,
1077 const bool debug =
false) {
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);
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;
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));
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));
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);
1195 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1197 EpetraExt::MatrixMarketFileToMultiVector(fileName.c_str(),
toEpetra(map), 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;
1215 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),map->getNode(),temp);
1235 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT) 1237 int rv = EpetraExt::MatrixMarketFileToMap(fileName.c_str(), *(
Xpetra::toEpetra(comm)), 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;
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;
1323 Teuchos::rcp(
new XpMapExtractor(fullRangeMap, rgMapVec, bRangeUseThyraStyleNumbering));
1326 bool bDomainUseThyraStyleNumbering =
false;
1333 Teuchos::rcp(
new XpMapExtractor(fullDomainMap, doMapVec, bDomainUseThyraStyleNumbering));
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
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 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.
#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.
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.
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)
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)
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 CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
RCP< Xpetra::CrsMatrixWrap< SC, LO, GO, NO > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP< Epetra_CrsMatrix > &epAB)
#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.
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)
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.
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.
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.