10#ifndef PACKAGES_XPETRA_SUP_UTILS_XPETRA_IO_HPP_
11#define PACKAGES_XPETRA_SUP_UTILS_XPETRA_IO_HPP_
16#ifdef HAVE_XPETRA_EPETRA
18#include "Epetra_MpiComm.h"
22#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
23#include <EpetraExt_MatrixMatrix.h>
24#include <EpetraExt_RowMatrixOut.h>
25#include <EpetraExt_MultiVectorOut.h>
26#include <EpetraExt_CrsMatrixIn.h>
27#include <EpetraExt_MultiVectorIn.h>
28#include <EpetraExt_BlockMapIn.h>
31#include <EpetraExt_BlockMapOut.h>
34#ifdef HAVE_XPETRA_TPETRA
35#include <MatrixMarket_Tpetra.hpp>
36#include <Tpetra_RowMatrixTransposer.hpp>
37#include <TpetraExt_MatrixMatrix.hpp>
38#include <Xpetra_TpetraMultiVector.hpp>
39#include <Xpetra_TpetraCrsGraph.hpp>
40#include <Xpetra_TpetraCrsMatrix.hpp>
41#include <Xpetra_TpetraBlockCrsMatrix.hpp>
42#include "Tpetra_Util.hpp"
45#ifdef HAVE_XPETRA_EPETRA
49#include "Xpetra_Matrix.hpp"
50#include "Xpetra_MatrixMatrix.hpp"
51#include "Xpetra_Helpers.hpp"
53#include "Xpetra_CrsMatrixWrap.hpp"
54#include "Xpetra_BlockedCrsMatrix.hpp"
56#include "Xpetra_Map.hpp"
57#include "Xpetra_StridedMap.hpp"
58#include "Xpetra_StridedMapFactory.hpp"
59#include "Xpetra_MapExtractor.hpp"
60#include "Xpetra_MatrixFactory.hpp"
63#include <Teuchos_MatrixMarket_Raw_Writer.hpp>
64#include <Teuchos_MatrixMarket_Raw_Reader.hpp>
69#ifdef HAVE_XPETRA_EPETRA
71template <
class SC,
class LO,
class GO,
class NO>
72RCP<Xpetra::CrsMatrixWrap<SC, LO, GO, NO>>
75 "Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
88 RCP<Xpetra::CrsMatrix<SC, LO, GO, NO>> tmpC2 = Teuchos::rcp_implicit_cast<Xpetra::CrsMatrix<SC, LO, GO, NO>>(tmpC1);
94template <
class SC,
class LO,
class GO,
class NO>
95RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
98 "Convert_Epetra_MultiVector_ToXpetra_MultiVector cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
110 RCP<Xpetra::MultiVector<SC, LO, GO, NO>> tmp = Xpetra::toXpetra<GO, NO>(epX);
120template <
class Scalar,
121 class LocalOrdinal = int,
122 class GlobalOrdinal = LocalOrdinal,
123 class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
126#undef XPETRA_IO_SHORT
130#ifdef HAVE_XPETRA_EPETRA
149#ifdef HAVE_XPETRA_TPETRA
219 Read(
const std::string& filename,
224 const bool callFillComplete =
true,
225 const bool binary =
false,
226 const bool tolerant =
false,
227 const bool debug =
false);
242 const bool callFillComplete =
true,
243 const bool binary =
false,
244 const bool tolerant =
false,
245 const bool debug =
false);
251 const bool binary =
false);
256 const bool binary =
false);
261 const bool binary =
false);
280 static std::string
toString(
const T& what);
283#ifdef HAVE_XPETRA_EPETRA
293template <
class Scalar>
300#ifdef HAVE_XPETRA_EPETRA
305 if (xeMap == Teuchos::null)
306 throw Exceptions::BadCast(
"IO::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
307 return xeMap->getEpetra_Map();
312#ifdef HAVE_XPETRA_TPETRA
317 if (tmp_TMap == Teuchos::null)
318 throw Exceptions::BadCast(
"IO::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
319 return tmp_TMap->getTpetra_Map();
328#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
330 if (tmp_EMap != Teuchos::null) {
331 int rv = EpetraExt::BlockMapToMatrixMarketFile(fileName.c_str(), tmp_EMap->getEpetra_Map());
338#ifdef HAVE_XPETRA_TPETRA
339#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
340 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
344 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node>>(tmp_Map);
345 if (tmp_TMap != Teuchos::null) {
347 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>::writeMapFile(fileName, *TMap);
356 std::string mapfile =
"map_" + fileName;
360#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
362 if (tmp_EVec != Teuchos::null) {
363 int rv = EpetraExt::MultiVectorToMatrixMarketFile(fileName.c_str(), *(tmp_EVec->getEpetra_MultiVector()));
370#ifdef HAVE_XPETRA_TPETRA
371#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
372 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
376 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(tmp_Vec);
377 if (tmp_TVec != Teuchos::null) {
379 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>::writeDenseFile(fileName, TVec);
385 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
389 std::string mapfile =
"map_" + fileName;
393#ifdef HAVE_XPETRA_TPETRA
395 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraMultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>(tmp_Vec);
396 if (tmp_TVec != Teuchos::null) {
398 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>::writeDenseFile(fileName, TVec);
403 throw Exceptions::RuntimeError(
"Xpetra cannot write MV<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node> when the underlying library is Epetra.");
406 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
410 std::string mapfile =
"map_" + fileName;
414#ifdef HAVE_XPETRA_TPETRA
416 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraMultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>(tmp_Vec);
417 if (tmp_TVec != Teuchos::null) {
419 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>::writeDenseFile(fileName, TVec);
424 throw Exceptions::RuntimeError(
"Xpetra cannot write MV<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node> when the underlying library is Epetra.");
427 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
442#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
444 if (tmp_ECrsMtx != Teuchos::null) {
446 int rv = EpetraExt::RowMatrixToMatrixMarketFile(fileName.c_str(), *A);
453#ifdef HAVE_XPETRA_TPETRA
454#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
455 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
459 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(tmp_CrsMtx);
460 if (tmp_TCrsMtx != Teuchos::null) {
462 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>::writeSparseFile(fileName, A);
466 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(tmp_CrsMtx);
467 if (tmp_BlockCrs != Teuchos::null) {
468 std::ofstream outstream(fileName, std::ofstream::out);
477 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
491#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
493 if (tmp_ECrsGraph != Teuchos::null) {
498#ifdef HAVE_XPETRA_TPETRA
499#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
500 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
504 Teuchos::rcp_dynamic_cast<const Xpetra::TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>>(tmp_Graph);
505 if (tmp_TCrsGraph != Teuchos::null) {
507 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>::writeSparseGraphFile(fileName, G);
513 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
525 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
533 for (
size_t j = 0; j < Teuchos::as<size_t>(rowptr.
size()); j++)
534 rowptr2[j] = rowptr[j];
537 writer.
writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
538 rowptr2, colind, vals,
544 for (
size_t row = 0; row < Op.
Rows(); ++row) {
545 for (
size_t col = 0; col < Op.
Cols(); ++col) {
547 if (m != Teuchos::null) {
548 const bool cond = Teuchos::rcp_dynamic_cast<const Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(m) == Teuchos::null;
551 "Sub block matrix (" << row <<
"," << col <<
") is not of type CrsMatrixWrap.");
561 for (
size_t row = 0; row < rangeMapExtractor->NumMaps(); ++row) {
562 auto map = rangeMapExtractor->getMap(row);
563 Write(
"subRangeMap_" + fileName +
toString(row) +
".m", *map);
565 Write(
"fullRangeMap_" + fileName +
".m", *(rangeMapExtractor->getFullMap()));
567 for (
size_t col = 0; col < domainMapExtractor->NumMaps(); ++col) {
568 auto map = domainMapExtractor->getMap(col);
569 Write(
"subDomainMap_" + fileName +
toString(col) +
".m", *map);
571 Write(
"fullDomainMap_" + fileName +
".m", *(domainMapExtractor->getFullMap()));
578#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
581 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
588 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
594#ifdef HAVE_XPETRA_TPETRA
595#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
596 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
599 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
601 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
603 bool callFillComplete =
true;
624 std::ifstream ifs(fileName.c_str(), std::ios::binary);
627 ifs.read(
reinterpret_cast<char*
>(&m),
sizeof(m));
628 ifs.read(
reinterpret_cast<char*
>(&n),
sizeof(n));
629 ifs.read(
reinterpret_cast<char*
>(&nnz),
sizeof(nnz));
631 int myRank = comm->getRank();
644 for (
int i = 0; i < m; i++) {
646 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
647 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
648 numEntriesPerRow[i] = rownnz;
649 for (
int j = 0; j < rownnz; j++) {
651 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
653 for (
int j = 0; j < rownnz; j++) {
655 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
662 ifs.seekg(0, ifs.beg);
664 ifs.read(
reinterpret_cast<char*
>(&m),
sizeof(junk));
665 ifs.read(
reinterpret_cast<char*
>(&n),
sizeof(junk));
666 ifs.read(
reinterpret_cast<char*
>(&nnz),
sizeof(junk));
667 for (
int i = 0; i < m; i++) {
669 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
670 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
673 for (
int j = 0; j < rownnz; j++) {
675 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
676 inds[j] = Teuchos::as<GlobalOrdinal>(index);
678 for (
int j = 0; j < rownnz; j++) {
680 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
681 vals[j] = Teuchos::as<Scalar>(value);
683 A->insertGlobalValues(row, inds, vals);
691 A->fillComplete(domainMap, rangeMap);
704 const bool callFillComplete =
true,
705 const bool binary =
false,
706 const bool tolerant =
false,
707 const bool debug =
false) {
714 if (binary ==
false) {
716#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
723 if (colMap.is_null()) {
724 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraRangeMap, epetraDomainMap, eA);
728 rv = EpetraExt::MatrixMarketFileToCrsMatrix(filename.c_str(), epetraRowMap, epetraColMap, epetraRangeMap, epetraDomainMap, eA);
736 Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tmpA);
743#ifdef HAVE_XPETRA_TPETRA
744#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
745 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
748 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
749 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
750 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
757 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(filename, tpetraRowMap, tpetraColMap, tpetraDomainMap, tpetraRangeMap,
758 callFillComplete, tolerant, debug);
776 auto tempA =
Read(filename, lib, rowMap->getComm(), binary);
781 if (callFillComplete)
782 A->fillComplete(domainMap, rangeMap);
795 const bool callFillComplete =
true,
796 const bool binary =
false,
797 const bool tolerant =
false,
798 const bool debug =
false) {
809 std::string rankFilename = filename +
"." + std::to_string(rowMap->getComm()->getSize()) +
"." + std::to_string(rowMap->getComm()->getRank());
812 if (binary ==
false) {
814 params->set(
"Parse tolerantly", tolerant);
815 params->set(
"Debug mode", debug);
825 reader.
readFile(rowptr2_RCP, colind2_RCP, vals2_RCP,
829 RCP<crs_type> ACrs = Teuchos::rcp_dynamic_cast<crs_wrap_type>(A)->getCrsMatrix();
834 ACrs->allocateAllValues(colind2_RCP.
size(), rowptr_RCP, colind_RCP, vals_RCP);
837 colind_RCP = colind2_RCP;
838 vals_RCP = vals2_RCP;
840 ACrs->setAllValues(rowptr_RCP, colind_RCP, vals_RCP);
843 std::ifstream ifs = std::ifstream(rankFilename.c_str(), std::ios::binary);
847 ifs.read(
reinterpret_cast<char*
>(&m),
sizeof(m));
848 ifs.read(
reinterpret_cast<char*
>(&n),
sizeof(n));
849 ifs.read(
reinterpret_cast<char*
>(&nnz),
sizeof(nnz));
857 RCP<crs_type> ACrs = Teuchos::rcp_dynamic_cast<crs_wrap_type>(A)->getCrsMatrix();
859 ACrs->allocateAllValues(nnz, rowptrRCP, indicesRCP, valuesRCP);
868 for (
int i = 0; i < m; i++) {
870 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
871 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
873 rowptr[row + 1] += rownnz;
874 ifs.seekg(
sizeof(
int) * rownnz +
sizeof(
double) * rownnz, ifs.cur);
876 for (
int i = 0; i < m; i++)
877 rowptr[i + 1] += rowptr[i];
881 ifs.seekg(
sizeof(
int) * 3, ifs.beg);
884 for (
int i = 0; i < m; i++) {
886 ifs.read(
reinterpret_cast<char*
>(&row),
sizeof(row));
887 ifs.read(
reinterpret_cast<char*
>(&rownnz),
sizeof(rownnz));
888 size_t ptr = rowptr[row];
889 for (
int j = 0; j < rownnz; j++) {
891 ifs.read(
reinterpret_cast<char*
>(&index),
sizeof(index));
892 indices[ptr] = Teuchos::as<LocalOrdinal>(index);
894 sorted = sorted & (indices[ptr - 1] < indices[ptr]);
898 for (
int j = 0; j < rownnz; j++) {
900 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(value));
901 values[ptr] = Teuchos::as<Scalar>(value);
904 rowptr[row] += rownnz;
906 for (
int i = m; i > 0; i--)
907 rowptr[i] = rowptr[i - 1];
910#ifdef HAVE_XPETRA_TPETRA
913 size_t rowBegin = rowptr[lclRow];
914 size_t rowEnd = rowptr[lclRow + 1];
915 Tpetra::sort2(&indices[rowBegin], &indices[rowEnd], &values[rowBegin]);
922 ACrs->setAllValues(rowptrRCP, indicesRCP, valuesRCP);
925 if (callFillComplete)
926 A->fillComplete(domainMap, rangeMap);
932 const bool binary =
false) {
938#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
941 int rv = EpetraExt::MatrixMarketFileToMultiVector(fileName.c_str(),
toEpetra(map), MV);
944 return Convert_Epetra_MultiVector_ToXpetra_MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(MVrcp);
949#ifdef HAVE_XPETRA_TPETRA
950#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
951 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
954 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
955 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
956 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
957 typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
960 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName, map->getComm(), temp,
false,
false, binary);
976 const bool binary =
false) {
980#ifdef HAVE_XPETRA_TPETRA
981 typedef Tpetra::CrsMatrix<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
982 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
983 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
984 typedef Tpetra::MultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node> multivector_type;
987 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName, map->getComm(), temp,
false,
false, binary);
1003 const bool binary =
false) {
1007#if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1010 int rv = EpetraExt::MatrixMarketFileToMap(fileName.c_str(), *(
Xpetra::toEpetra(comm)), eMap);
1015 return Xpetra::toXpetra<int, Node>(*eMap1);
1020#ifdef HAVE_XPETRA_TPETRA
1021#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
1022 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
1025 typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> sparse_matrix_type;
1026 typedef Tpetra::MatrixMarket::Reader<sparse_matrix_type> reader_type;
1045 size_t numBlocks = 2;
1047 std::vector<RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>> rangeMapVec;
1048 for (
size_t row = 0; row < numBlocks; ++row) {
1049 auto map =
ReadMap(
"subRangeMap_" + fileName +
toString(row) +
".m", lib, comm);
1050 rangeMapVec.push_back(map);
1052 auto fullRangeMap =
ReadMap(
"fullRangeMap_" + fileName +
".m", lib, comm);
1054 std::vector<RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>> domainMapVec;
1055 for (
size_t col = 0; col < numBlocks; ++col) {
1056 auto map =
ReadMap(
"subDomainMap_" + fileName +
toString(col) +
".m", lib, comm);
1057 domainMapVec.push_back(map);
1059 auto fullDomainMap =
ReadMap(
"fullDomainMap_" + fileName +
".m", lib, comm);
1075 bool bRangeUseThyraStyleNumbering =
false;
1086 bool bDomainUseThyraStyleNumbering =
false;
1098 for (
size_t row = 0; row < numBlocks; ++row) {
1099 for (
size_t col = 0; col < numBlocks; ++col) {
1104 auto mat =
Read(fileName +
toString(row) +
toString(col) +
".m", rowSubMap, colSubMap, domSubMap, ranSubMap);
1105 bOp->setMatrix(row, col, mat);
1109 bOp->fillComplete();
1117 std::ostringstream buf;
1127#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)
virtual size_t Cols() const
number of column blocks
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 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)
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)
static void WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
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)
static void Write(const std::string &fileName, const Xpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, const bool &writeAllMaps=false)
static void Write(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
static RCP< const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadBlockedCrsMatrix(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.
static void WriteGOMV(const std::string &fileName, const Xpetra::MultiVector< GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &vec)
static RCP< Xpetra::MultiVector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > > ReadMultiVectorLO(const std::string &fileName, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const bool binary=false)
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 void WriteLOMV(const std::string &fileName, const Xpetra::MultiVector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &vec)
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)
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)
Xpetra utility class containing IO routines to read/write vectors, matrices etc...
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< const Map > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, const bool binary=false)
static RCP< MultiVector > ReadMultiVector(const std::string &fileName, const RCP< const Map > &map, const bool binary=false)
Read a MultiVector from file in Matrix Matrix or binary 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 void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
Read/Write methods.
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 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 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 void WriteGOMV(const std::string &fileName, const Xpetra::MultiVector< GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &vec)
Save multivector with Scalar=GlobalOrdinal to file 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 RCP< Xpetra::MultiVector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > > ReadMultiVectorLO(const std::string &fileName, const RCP< const Map > &map, const bool binary=false)
Read a MultiVector with Scalar=LocalOrdinal from file in Matrix Matrix or binary format.
static void WriteLOMV(const std::string &fileName, const Xpetra::MultiVector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &vec)
Save multivector with Scalar=LocalOrdinal to file in Matrix Market format.
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.
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 > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
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 Teuchos::RCP< const map_type > getDomainMap() const =0
The Map associated with the domain of this operator, which must be compatible with X....
virtual const Teuchos::RCP< const map_type > getRangeMap() const =0
The Map associated with the range of this operator, which must be compatible with Y....
#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)
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
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 > &)