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_TpetraCrsGraph.hpp>
78#include <Xpetra_TpetraCrsMatrix.hpp>
79#include <Xpetra_TpetraBlockCrsMatrix.hpp>
80#include "Tpetra_Util.hpp"
83#ifdef HAVE_XPETRA_EPETRA
90#include "Xpetra_CrsMatrixWrap.hpp"
93#include "Xpetra_Map.hpp"
94#include "Xpetra_StridedMap.hpp"
95#include "Xpetra_StridedMapFactory.hpp"
96#include "Xpetra_MapExtractor.hpp"
99#include <Teuchos_MatrixMarket_Raw_Writer.hpp>
100#include <Teuchos_MatrixMarket_Raw_Reader.hpp>
107#ifdef HAVE_XPETRA_EPETRA
109 template<
class SC,
class LO,
class GO,
class NO>
110 RCP<Xpetra::CrsMatrixWrap<SC,LO,GO,NO> >
113 "Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
126 RCP<Xpetra::CrsMatrix<SC,LO,GO,NO> > tmpC2 = Teuchos::rcp_implicit_cast<Xpetra::CrsMatrix<SC,LO,GO,NO> >(tmpC1);
133 template<
class SC,
class LO,
class GO,
class NO>
134 RCP<Xpetra::MultiVector<SC,LO,GO,NO> >
137 "Convert_Epetra_MultiVector_ToXpetra_MultiVector cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
149 RCP<Xpetra::MultiVector<SC,LO,GO,NO >> tmp = Xpetra::toXpetra<GO,NO>(epX);
159 template <
class Scalar,
160 class LocalOrdinal = int,
161 class GlobalOrdinal = LocalOrdinal,
166#undef XPETRA_IO_SHORT
171#ifdef HAVE_XPETRA_EPETRA
188 if (xeMap == Teuchos::null)
189 throw Exceptions::BadCast(
"Utils::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
190 return xeMap->getEpetra_Map();
195#ifdef HAVE_XPETRA_TPETRA
217 if (tmp_TMap == Teuchos::null)
218 throw Exceptions::BadCast(
"Utils::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
219 return tmp_TMap->getTpetra_Map();
229#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
231 if (tmp_EMap != Teuchos::null) {
232 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
239#ifdef HAVE_XPETRA_TPETRA
241 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node> >(tmp_Map);
242 if (tmp_TMap != Teuchos::null) {
244 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
255 std::string mapfile =
"map_" + fileName;
259#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
261 if (tmp_EVec != Teuchos::null) {
262 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
269#ifdef HAVE_XPETRA_TPETRA
271 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tmp_Vec);
272 if (tmp_TVec != Teuchos::null) {
274 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeDenseFile(fileName, TVec);
279 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
298#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
300 if (tmp_ECrsMtx != Teuchos::null) {
302 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
309#ifdef HAVE_XPETRA_TPETRA
311 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tmp_CrsMtx);
312 if (tmp_TCrsMtx != Teuchos::null) {
314 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
318 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tmp_CrsMtx);
319 if(tmp_BlockCrs != Teuchos::null) {
320 std::ofstream outstream (fileName,std::ofstream::out);
328 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
342 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
350 for (
size_t j = 0; j<rowptr.
size(); j++)
351 rowptr2[j] = rowptr[j];
354 writer.
writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
378 for (
size_t row = 0; row < Op.
Rows(); ++row) {
379 for (
size_t col = 0; col < Op.
Cols(); ++col) {
381 if(m != Teuchos::null) {
383 "Sub block matrix (" << row <<
"," << col <<
") is not of type CrsMatrixWrap.");
384 XpIO::Write(fileName +
toString(row) +
toString(col) +
".m", *m, writeAllMaps);
393 for(
size_t row = 0; row < rangeMapExtractor->NumMaps(); ++row) {
395 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(row) +
".m", *map);
397 XpIO::Write(
"fullRangeMap_" + fileName +
".m",*(rangeMapExtractor->getFullMap()));
399 for(
size_t col = 0; col < domainMapExtractor->NumMaps(); ++col) {
401 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(col) +
".m", *map);
403 XpIO::Write(
"fullDomainMap_" + fileName+
".m",*(domainMapExtractor->getFullMap()));
408 if (binary ==
false) {
411#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
414 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
421 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
427#ifdef HAVE_XPETRA_TPETRA
428 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
430 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
432 bool callFillComplete =
true;
452 std::ifstream ifs(fileName.c_str(), std::ios::binary);
455 ifs.read(
reinterpret_cast<char*
>(&m),
sizeof(m));
456 ifs.read(
reinterpret_cast<char*
>(&n),
sizeof(n));
457 ifs.read(
reinterpret_cast<char*
>(&nnz),
sizeof(nnz));
459 int myRank = comm->getRank();
471 for (
int i = 0; i < m; i++) {
473 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
474 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
475 numEntriesPerRow[row] = rownnz;
476 for (
int j = 0; j < rownnz; j++) {
478 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
480 for (
int j = 0; j < rownnz; j++) {
482 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
489 ifs.seekg(0, ifs.beg);
491 ifs.read(
reinterpret_cast<char*
>(&junk),
sizeof(junk));
492 ifs.read(
reinterpret_cast<char*
>(&junk),
sizeof(junk));
493 ifs.read(
reinterpret_cast<char*
>(&junk),
sizeof(junk));
494 for (
int i = 0; i < m; i++) {
496 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
497 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
500 for (
int j = 0; j < rownnz; j++) {
502 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
503 inds[j] = Teuchos::as<GlobalOrdinal>(index);
505 for (
int j = 0; j < rownnz; j++) {
507 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
508 vals[j] = Teuchos::as<Scalar>(value);
510 A->insertGlobalValues(row, inds, vals);
518 A->fillComplete(domainMap, rangeMap);
533 Read(
const std::string& filename,
538 const bool callFillComplete =
true,
539 const bool binary =
false,
540 const bool tolerant =
false,
541 const bool debug =
false) {
548 if (binary ==
false) {
550#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
557 if (colMap.is_null()) {
558 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
562 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
570 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
577#ifdef HAVE_XPETRA_TPETRA
578 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
579 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
580 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
587 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
588 callFillComplete, tolerant, debug);
606 auto tempA =
Read(filename, lib, rowMap->getComm(), binary);
611 if (callFillComplete)
612 A->fillComplete(domainMap, rangeMap);
633 const bool callFillComplete =
true,
634 const bool binary =
false,
635 const bool tolerant =
false,
636 const bool debug =
false) {
647 std::string rankFilename = filename +
"." + std::to_string(rowMap->getComm()->getSize()) +
"." + std::to_string(rowMap->getComm()->getRank());
650 if (binary ==
false) {
653 params->set(
"Parse tolerantly", tolerant);
654 params->set(
"Debug mode", debug);
656 LocalOrdinal numRows = rowMap->getLocalNumElements();
657 LocalOrdinal numCols = colMap->getLocalNumElements();
664 reader.
readFile(rowptr2_RCP,colind2_RCP,vals2_RCP,
669 RCP<crs_type> ACrs = Teuchos::rcp_dynamic_cast<crs_wrap_type>(A)->getCrsMatrix();
674 ACrs->allocateAllValues(colind2_RCP.
size(), rowptr_RCP, colind_RCP, vals_RCP);
677 colind_RCP = colind2_RCP;
678 vals_RCP = vals2_RCP;
680 ACrs->setAllValues(rowptr_RCP, colind_RCP, vals_RCP);
683 std::ifstream ifs = std::ifstream(rankFilename.c_str(), std::ios::binary);
687 ifs.read(
reinterpret_cast<char*
>(&m),
sizeof(m));
688 ifs.read(
reinterpret_cast<char*
>(&n),
sizeof(n));
689 ifs.read(
reinterpret_cast<char*
>(&nnz),
sizeof(nnz));
697 RCP<crs_type> ACrs = Teuchos::rcp_dynamic_cast<crs_wrap_type>(A)->getCrsMatrix();
699 ACrs->allocateAllValues(nnz, rowptrRCP, indicesRCP, valuesRCP);
708 for (
int i = 0; i < m; i++) {
710 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
711 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
713 rowptr[row+1] += rownnz;
714 ifs.seekg(
sizeof(
int)*rownnz +
sizeof(
double)*rownnz, ifs.cur);
716 for (
int i = 0; i < m; i++)
717 rowptr[i+1] += rowptr[i];
721 ifs.seekg(
sizeof(
int)*3, ifs.beg);
724 for (
int i = 0; i < m; i++) {
726 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
727 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
728 size_t ptr = rowptr[row];
729 for (
int j = 0; j < rownnz; j++) {
731 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
732 indices[ptr] = Teuchos::as<LocalOrdinal>(index);
734 sorted = sorted & (indices[ptr-1] < indices[ptr]);
738 for (
int j = 0; j < rownnz; j++) {
740 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
741 values[ptr] = Teuchos::as<Scalar>(value);
744 rowptr[row] += rownnz;
746 for (
int i = m; i > 0; i--)
747 rowptr[i] = rowptr[i-1];
750#ifdef HAVE_XPETRA_TPETRA
752 for (LocalOrdinal lclRow = 0; lclRow < m; lclRow++) {
753 size_t rowBegin = rowptr[lclRow];
754 size_t rowEnd = rowptr[lclRow+1];
755 Tpetra::sort2(&indices[rowBegin], &indices[rowEnd], &values[rowBegin]);
762 ACrs->setAllValues(rowptrRCP, indicesRCP, valuesRCP);
766 if (callFillComplete)
767 A->fillComplete(domainMap, rangeMap);
776 const bool binary=
false) {
783#ifdef HAVE_XPETRA_TPETRA
784 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
785 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
786 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
787 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
790 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),temp,
false,
false,binary);
806 const bool binary=
false) {
810#ifdef HAVE_XPETRA_TPETRA
811 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
812 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
846 size_t numBlocks = 2;
848 std::vector<RCP<const Map> > rangeMapVec;
849 for(
size_t row = 0; row < numBlocks; ++row) {
850 RCP<const Map> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(row) +
".m", lib, comm);
851 rangeMapVec.push_back(map);
853 RCP<const Map> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
855 std::vector<RCP<const Map> > domainMapVec;
856 for(
size_t col = 0; col < numBlocks; ++col) {
857 RCP<const Map> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(col) +
".m", lib, comm);
858 domainMapVec.push_back(map);
860 RCP<const Map> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
876 bool bRangeUseThyraStyleNumbering =
false;
888 bool bDomainUseThyraStyleNumbering =
false;
901 for (
size_t row = 0; row < numBlocks; ++row) {
902 for (
size_t col = 0; col < numBlocks; ++col) {
903 RCP<const Map> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
904 RCP<const Map> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
905 RCP<const Map> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
906 RCP<const Map> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
907 RCP<Matrix> mat = XpIO::Read(fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
908 bOp->setMatrix(row, col, mat);
921 std::ostringstream buf;
928#ifdef HAVE_XPETRA_EPETRA
938 template <
class Scalar>
945#ifdef HAVE_XPETRA_EPETRA
950 if (xeMap == Teuchos::null)
951 throw Exceptions::BadCast(
"IO::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
952 return xeMap->getEpetra_Map();
957#ifdef HAVE_XPETRA_TPETRA
962 if (tmp_TMap == Teuchos::null)
963 throw Exceptions::BadCast(
"IO::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
964 return tmp_TMap->getTpetra_Map();
974#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
976 if (tmp_EMap != Teuchos::null) {
977 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
984#ifdef HAVE_XPETRA_TPETRA
985# if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
986 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
990 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node> >(tmp_Map);
991 if (tmp_TMap != Teuchos::null) {
993 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeMapFile(fileName, *TMap);
1003 std::string mapfile =
"map_" + fileName;
1007#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1009 if (tmp_EVec != Teuchos::null) {
1010 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
1017#ifdef HAVE_XPETRA_TPETRA
1018# if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1019 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1023 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tmp_Vec);
1024 if (tmp_TVec != Teuchos::null) {
1026 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeDenseFile(fileName, TVec);
1032 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
1052#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1054 if (tmp_ECrsMtx != Teuchos::null) {
1056 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
1063#ifdef HAVE_XPETRA_TPETRA
1064# if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1065 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1069 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tmp_CrsMtx);
1070 if (tmp_TCrsMtx != Teuchos::null) {
1072 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseFile(fileName, A);
1076 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tmp_CrsMtx);
1077 if(tmp_BlockCrs != Teuchos::null) {
1078 std::ofstream outstream (fileName,std::ofstream::out);
1087 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
1104#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1106 if (tmp_ECrsGraph != Teuchos::null) {
1111#ifdef HAVE_XPETRA_TPETRA
1112# if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1113 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1117 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node> >(tmp_Graph);
1118 if (tmp_TCrsGraph != Teuchos::null) {
1120 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >::writeSparseGraphFile(fileName, G);
1126 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
1140 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
1148 for (
size_t j = 0; j<Teuchos::as<size_t>(rowptr.
size()); j++)
1149 rowptr2[j] = rowptr[j];
1152 writer.
writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
1153 rowptr2,colind,vals,
1178 for (
size_t row = 0; row < Op.
Rows(); ++row) {
1179 for (
size_t col = 0; col < Op.
Cols(); ++col) {
1181 if(m != Teuchos::null) {
1183 "Sub block matrix (" << row <<
"," << col <<
") is not of type CrsMatrixWrap.");
1184 XpIO::Write(fileName +
toString(row) +
toString(col) +
".m", *m, writeAllMaps);
1193 for(
size_t row = 0; row < rangeMapExtractor->NumMaps(); ++row) {
1195 XpIO::Write(
"subRangeMap_" + fileName + XpIO::toString<size_t>(row) +
".m", *map);
1197 XpIO::Write(
"fullRangeMap_" + fileName +
".m", *(rangeMapExtractor->getFullMap()));
1199 for(
size_t col = 0; col < domainMapExtractor->NumMaps(); ++col) {
1201 XpIO::Write(
"subDomainMap_" + fileName + XpIO::toString<size_t>(col) +
".m", *map);
1203 XpIO::Write(
"fullDomainMap_" + fileName+
".m", *(domainMapExtractor->getFullMap()));
1208 if (binary ==
false) {
1211#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1214 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
1221 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
1227#ifdef HAVE_XPETRA_TPETRA
1228# if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1229 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1232 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1234 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1236 bool callFillComplete =
true;
1257 std::ifstream ifs(fileName.c_str(), std::ios::binary);
1260 ifs.read(
reinterpret_cast<char*
>(&m),
sizeof(m));
1261 ifs.read(
reinterpret_cast<char*
>(&n),
sizeof(n));
1262 ifs.read(
reinterpret_cast<char*
>(&nnz),
sizeof(nnz));
1264 int myRank = comm->getRank();
1277 for (
int i = 0; i < m; i++) {
1279 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
1280 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
1281 numEntriesPerRow[i] = rownnz;
1282 for (
int j = 0; j < rownnz; j++) {
1284 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
1286 for (
int j = 0; j < rownnz; j++) {
1288 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
1295 ifs.seekg(0, ifs.beg);
1297 ifs.read(
reinterpret_cast<char*
>(&m),
sizeof(junk));
1298 ifs.read(
reinterpret_cast<char*
>(&n),
sizeof(junk));
1299 ifs.read(
reinterpret_cast<char*
>(&nnz),
sizeof(junk));
1300 for (
int i = 0; i < m; i++) {
1302 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
1303 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
1306 for (
int j = 0; j < rownnz; j++) {
1308 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
1309 inds[j] = Teuchos::as<GlobalOrdinal>(index);
1311 for (
int j = 0; j < rownnz; j++) {
1313 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
1314 vals[j] = Teuchos::as<Scalar>(value);
1316 A->insertGlobalValues(row, inds, vals);
1324 A->fillComplete(domainMap, rangeMap);
1343 const bool callFillComplete =
true,
1344 const bool binary =
false,
1345 const bool tolerant =
false,
1346 const bool debug =
false) {
1353 if (binary ==
false) {
1355#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1362 if (colMap.is_null()) {
1363 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
1367 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
1375 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
1382#ifdef HAVE_XPETRA_TPETRA
1383# if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1384 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1387 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1388 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1389 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1396 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
1397 callFillComplete, tolerant, debug);
1416 auto tempA =
Read(filename, lib, rowMap->getComm(), binary);
1421 if (callFillComplete)
1422 A->fillComplete(domainMap, rangeMap);
1443 const bool callFillComplete =
true,
1444 const bool binary =
false,
1445 const bool tolerant =
false,
1446 const bool debug =
false) {
1457 std::string rankFilename = filename +
"." + std::to_string(rowMap->getComm()->getSize()) +
"." + std::to_string(rowMap->getComm()->getRank());
1460 if (binary ==
false) {
1463 params->set(
"Parse tolerantly", tolerant);
1464 params->set(
"Debug mode", debug);
1474 reader.
readFile(rowptr2_RCP,colind2_RCP,vals2_RCP,
1479 RCP<crs_type> ACrs = Teuchos::rcp_dynamic_cast<crs_wrap_type>(A)->getCrsMatrix();
1484 ACrs->allocateAllValues(colind2_RCP.
size(), rowptr_RCP, colind_RCP, vals_RCP);
1487 colind_RCP = colind2_RCP;
1488 vals_RCP = vals2_RCP;
1490 ACrs->setAllValues(rowptr_RCP, colind_RCP, vals_RCP);
1493 std::ifstream ifs = std::ifstream(rankFilename.c_str(), std::ios::binary);
1497 ifs.read(
reinterpret_cast<char*
>(&m),
sizeof(m));
1498 ifs.read(
reinterpret_cast<char*
>(&n),
sizeof(n));
1499 ifs.read(
reinterpret_cast<char*
>(&nnz),
sizeof(nnz));
1507 RCP<crs_type> ACrs = Teuchos::rcp_dynamic_cast<crs_wrap_type>(A)->getCrsMatrix();
1509 ACrs->allocateAllValues(nnz, rowptrRCP, indicesRCP, valuesRCP);
1518 for (
int i = 0; i < m; i++) {
1520 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
1521 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
1523 rowptr[row+1] += rownnz;
1524 ifs.seekg(
sizeof(
int)*rownnz +
sizeof(
double)*rownnz, ifs.cur);
1526 for (
int i = 0; i < m; i++)
1527 rowptr[i+1] += rowptr[i];
1531 ifs.seekg(
sizeof(
int)*3, ifs.beg);
1534 for (
int i = 0; i < m; i++) {
1536 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
1537 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
1538 size_t ptr = rowptr[row];
1539 for (
int j = 0; j < rownnz; j++) {
1541 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
1542 indices[ptr] = Teuchos::as<LocalOrdinal>(index);
1544 sorted = sorted & (indices[ptr-1] < indices[ptr]);
1548 for (
int j = 0; j < rownnz; j++) {
1550 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
1551 values[ptr] = Teuchos::as<Scalar>(value);
1554 rowptr[row] += rownnz;
1556 for (
int i = m; i > 0; i--)
1557 rowptr[i] = rowptr[i-1];
1560#ifdef HAVE_XPETRA_TPETRA
1563 size_t rowBegin = rowptr[lclRow];
1564 size_t rowEnd = rowptr[lclRow+1];
1565 Tpetra::sort2(&indices[rowBegin], &indices[rowEnd], &values[rowBegin]);
1572 ACrs->setAllValues(rowptrRCP, indicesRCP, valuesRCP);
1576 if (callFillComplete)
1577 A->fillComplete(domainMap, rangeMap);
1586 const bool binary=
false) {
1592#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1595 int rv = EpetraExt::MatrixMarketFileToMultiVector(fileName.c_str(),
toEpetra(map), MV);
1598 return Convert_Epetra_MultiVector_ToXpetra_MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(MVrcp);
1603#ifdef HAVE_XPETRA_TPETRA
1604# if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1605 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1608 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1609 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1610 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
1611 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
1614 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName,map->getComm(),temp,
false,
false,binary);
1633 const bool binary=
false) {
1637#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1640 int rv = EpetraExt::MatrixMarketFileToMap(fileName.c_str(), *(
Xpetra::toEpetra(comm)), eMap);
1645 return Xpetra::toXpetra<int,Node>(*eMap1);
1650#ifdef HAVE_XPETRA_TPETRA
1651# if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1652 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1655 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1656 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1694 size_t numBlocks = 2;
1696 std::vector<RCP<const Map> > rangeMapVec;
1697 for(
size_t row = 0; row < numBlocks; ++row) {
1698 RCP<const Map> map = XpIO::ReadMap(
"subRangeMap_" + fileName + XpIO::toString<size_t>(row) +
".m", lib, comm);
1699 rangeMapVec.push_back(map);
1701 RCP<const Map> fullRangeMap = XpIO::ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
1703 std::vector<RCP<const Map> > domainMapVec;
1704 for(
size_t col = 0; col < numBlocks; ++col) {
1705 RCP<const Map> map = XpIO::ReadMap(
"subDomainMap_" + fileName + XpIO::toString<size_t>(col) +
".m", lib, comm);
1706 domainMapVec.push_back(map);
1708 RCP<const Map> fullDomainMap = XpIO::ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
1724 bool bRangeUseThyraStyleNumbering =
false;
1732 rcp(
new MapExtractor(fullRangeMap, rangeMapVec, bRangeUseThyraStyleNumbering));
1735 bool bDomainUseThyraStyleNumbering =
false;
1742 rcp(
new MapExtractor(fullDomainMap, domainMapVec, bDomainUseThyraStyleNumbering));
1747 for (
size_t row = 0; row < numBlocks; ++row) {
1748 for (
size_t col = 0; col < numBlocks; ++col) {
1749 RCP<const Map> rowSubMap = XpIO::ReadMap(
"rowmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
1750 RCP<const Map> colSubMap = XpIO::ReadMap(
"colmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
1751 RCP<const Map> domSubMap = XpIO::ReadMap(
"domainmap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
1752 RCP<const Map> ranSubMap = XpIO::ReadMap(
"rangemap_" + fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", lib, comm);
1753 RCP<Matrix> mat = XpIO::Read(fileName + XpIO::toString<size_t>(row) + XpIO::toString<size_t>(col) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
1754 bOp->setMatrix(row, col, mat);
1758 bOp->fillComplete();
1766 std::ostringstream buf;
1776#define XPETRA_IO_SHORT
void resize(const size_type n, const T &val=T())
void assign(size_type n, const T &val)
void resize(size_type new_size, const value_type &x=value_type())
bool readFile(ArrayRCP< Ordinal > &rowptr, ArrayRCP< Ordinal > &colind, ArrayRCP< Scalar > &values, Ordinal &numRows, Ordinal &numCols, const std::string &filename)
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)
Teuchos::RCP< Matrix > getMatrix(size_t r, size_t c) const
return block (r,c)
virtual size_t Rows() const
number of row blocks
RCP< const MapExtractor > getRangeMapExtractor() const
Returns map extractor class for range map.
RCP< const MapExtractor > getDomainMapExtractor() const
Returns map extractor for domain map.
virtual size_t Cols() const
number of column blocks
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const =0
Returns the Map associated with the domain of this graph.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const =0
Returns the Map that describes the row distribution in this graph.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const =0
Returns the Map associated with the domain of this graph.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const =0
Returns the Map that describes the column distribution in this graph.
Concrete implementation of Xpetra::Matrix.
RCP< CrsMatrix > getCrsMatrix() const
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
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 RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadMultiVector(const std::string &fileName, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const bool binary=false)
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 void WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
Save block matrix to one file per block in Matrix Market 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.
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 void Write(const std::string &fileName, const Xpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, const bool &writeAllMaps=false)
Save CrsGraph to file in Matrix Market format.
static void Write(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
Save matrix to file in Matrix Market format.
static RCP< const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadBlockedCrsMatrix(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
Read block matrix from one file per block in Matrix Market format.
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.
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 void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
Read/Write methods.
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadLocal(const std::string &filename, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > rowMap, RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > colMap, 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 local files in Matrix Market or binary format.
static RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, const bool binary=false)
static void Write(const std::string &fileName, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec)
Save vector to file in Matrix Market format.
Xpetra utility class containing IO routines to read/write vectors, matrices etc...
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 RCP< MultiVector > ReadMultiVector(const std::string &fileName, const RCP< const Map > &map, const bool binary=false)
static RCP< const Map > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, const bool binary=false)
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 std::string toString(const T &what)
Little helper function to convert non-string types to strings.
static void Write(const std::string &fileName, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec)
Save vector to file in Matrix Market format.
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadLocal(const std::string &filename, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > rowMap, RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > colMap, 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 local files in Matrix Market or binary format.
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, const bool &writeAllMaps=false)
Save matrix to file in Matrix Market format.
static void WriteLocal(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Save local parts of matrix to files in Matrix Market format.
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 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 WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
Save block matrix to one file per block 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 block matrix from one file per block in Matrix Market format.
static RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &source, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &target, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying the number of non-zeros for all rows.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
static RCP< Matrix > Build(const RCP< const Map > &rowMap)
Xpetra-specific matrix class.
virtual const RCP< const Map > & getColMap() const
Returns the Map that describes the column distribution in this matrix. This might be null until fillC...
virtual const RCP< const Map > & getRowMap() const
Returns the Map that describes the row distribution in this 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 Teuchos::RCP< const Map > getDomainMap() const =0
The Map associated with the domain of this operator, which must be compatible with X....
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
std::string toString(const T &t)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< Xpetra::MultiVector< SC, LO, GO, NO > > Convert_Epetra_MultiVector_ToXpetra_MultiVector(RCP< Epetra_MultiVector > &epX)
RCP< Xpetra::MultiVector< double, int, int, Xpetra::EpetraNode > > Convert_Epetra_MultiVector_ToXpetra_MultiVector< double, int, int, Xpetra::EpetraNode >(RCP< Epetra_MultiVector > &epX)
RCP< Xpetra::CrsMatrixWrap< double, int, int, Xpetra::EpetraNode > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap< double, int, int, Xpetra::EpetraNode >(RCP< Epetra_CrsMatrix > &epAB)
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
RCP< Xpetra::CrsMatrixWrap< SC, LO, GO, NO > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP< Epetra_CrsMatrix > &)