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>
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;
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();
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