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"
62 #include <Teuchos_TestForException.hpp>
63 #include <Teuchos_MatrixMarket_Raw_Writer.hpp>
64 #include <Teuchos_MatrixMarket_Raw_Reader.hpp>
69 #ifdef HAVE_XPETRA_EPETRA
71 template <
class SC,
class LO,
class GO,
class NO>
72 RCP<Xpetra::CrsMatrixWrap<SC, LO, GO, NO>>
75 "Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
76 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
81 inline RCP<Xpetra::CrsMatrixWrap<double, int, int, Xpetra::EpetraNode>> Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<double, int, int, Xpetra::EpetraNode>(RCP<Epetra_CrsMatrix>& epAB) {
94 template <
class SC,
class LO,
class GO,
class NO>
95 RCP<Xpetra::MultiVector<SC, LO, GO, NO>>
98 "Convert_Epetra_MultiVector_ToXpetra_MultiVector cannot be used with Scalar != double, LocalOrdinal != int, GlobalOrdinal != int");
99 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
104 inline RCP<Xpetra::MultiVector<double, int, int, Xpetra::EpetraNode>> Convert_Epetra_MultiVector_ToXpetra_MultiVector<double, int, int, Xpetra::EpetraNode>(RCP<Epetra_MultiVector>& epX) {
110 RCP<Xpetra::MultiVector<SC, LO, GO, NO>> tmp = Xpetra::toXpetra<GO, NO>(epX);
120 template <
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
212 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);
218 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
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);
237 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
ReadLocal(
const std::string& filename,
242 const bool callFillComplete =
true,
243 const bool binary =
false,
244 const bool tolerant =
false,
245 const bool debug =
false);
250 const RCP<const Map>& map,
251 const bool binary =
false);
254 static RCP<Xpetra::MultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>
ReadMultiVectorLO(
const std::string& fileName,
255 const RCP<const Map>& map,
256 const bool binary =
false);
258 static RCP<const Map>
ReadMap(
const std::string& fileName,
260 const RCP<
const Teuchos::Comm<int>>& comm,
261 const bool binary =
false);
276 static RCP<const Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
ReadBlockedCrsMatrix(
const std::string& fileName,
Xpetra::UnderlyingLib lib,
const RCP<
const Teuchos::Comm<int>>& comm);
280 static std::string
toString(
const T& what);
283 #ifdef HAVE_XPETRA_EPETRA
293 template <
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();
327 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> tmp_Map = rcpFromRef(M);
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());
336 #endif // HAVE_XPETRA_EPETRA
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))))
343 const RCP<const Xpetra::TpetraMap<LocalOrdinal, GlobalOrdinal, Node>>& tmp_TMap =
345 if (tmp_TMap != Teuchos::null) {
346 RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> TMap = tmp_TMap->
getTpetra_Map();
347 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>::writeMapFile(fileName, *TMap);
351 #endif // HAVE_XPETRA_TPETRA
356 std::string mapfile =
"map_" + fileName;
359 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> tmp_Vec = Teuchos::rcpFromRef(vec);
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()));
368 #endif // HAVE_XPETRA_EPETRAEXT
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))))
375 const RCP<const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& tmp_TVec =
377 if (tmp_TVec != Teuchos::null) {
378 RCP<const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> TVec = tmp_TVec->
getTpetra_MultiVector();
379 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>::writeDenseFile(fileName, TVec);
383 #endif // HAVE_XPETRA_TPETRA
385 throw Exceptions::BadCast(
"Could not cast to EpetraMultiVector or TpetraMultiVector in multivector writing");
389 std::string mapfile =
"map_" + fileName;
392 RCP<const Xpetra::MultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> tmp_Vec = Teuchos::rcpFromRef(vec);
393 #ifdef HAVE_XPETRA_TPETRA
394 const RCP<const Xpetra::TpetraMultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>& tmp_TVec =
396 if (tmp_TVec != Teuchos::null) {
397 RCP<const Tpetra::MultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> TVec = tmp_TVec->
getTpetra_MultiVector();
398 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>::writeDenseFile(fileName, TVec);
401 #endif // HAVE_XPETRA_TPETRA
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;
413 RCP<const Xpetra::MultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> tmp_Vec = Teuchos::rcpFromRef(vec);
414 #ifdef HAVE_XPETRA_TPETRA
415 const RCP<const Xpetra::TpetraMultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>& tmp_TVec =
417 if (tmp_TVec != Teuchos::null) {
418 RCP<const Tpetra::MultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> TVec = tmp_TVec->
getTpetra_MultiVector();
419 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>::writeDenseFile(fileName, TVec);
422 #endif // HAVE_XPETRA_TPETRA
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");
441 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> tmp_CrsMtx = crsOp.
getCrsMatrix();
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);
451 #endif // endif HAVE_XPETRA_EPETRA
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))))
458 const RCP<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& tmp_TCrsMtx =
460 if (tmp_TCrsMtx != Teuchos::null) {
461 RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> A = tmp_TCrsMtx->
getTpetra_CrsMatrix();
462 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>::writeSparseFile(fileName, A);
465 const RCP<const Xpetra::TpetraBlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& tmp_BlockCrs =
467 if (tmp_BlockCrs != Teuchos::null) {
468 std::ofstream outstream(fileName, std::ofstream::out);
469 Teuchos::FancyOStream ofs(Teuchos::rcpFromRef(outstream));
470 tmp_BlockCrs->getTpetra_BlockCrsMatrix()->describe(ofs, Teuchos::VERB_EXTREME);
475 #endif // HAVE_XPETRA_TPETRA
477 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
489 RCP<const Xpetra::CrsGraph<LocalOrdinal, GlobalOrdinal, Node>> tmp_Graph = rcpFromRef(graph);
491 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
493 if (tmp_ECrsGraph != Teuchos::null) {
496 #endif // endif HAVE_XPETRA_EPETRA
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))))
503 RCP<const Xpetra::TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>> tmp_TCrsGraph =
505 if (tmp_TCrsGraph != Teuchos::null) {
506 RCP<const Tpetra::CrsGraph<LocalOrdinal, GlobalOrdinal, Node>> G = tmp_TCrsGraph->
getTpetra_CrsGraph();
507 Tpetra::MatrixMarket::Writer<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>::writeSparseGraphFile(fileName, G);
511 #endif // HAVE_XPETRA_TPETRA
513 throw Exceptions::BadCast(
"Could not cast to EpetraCrsMatrix or TpetraCrsMatrix in matrix writing");
519 RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> tmp_CrsMtx = crsOp.
getCrsMatrix();
521 ArrayRCP<const size_t> rowptr_RCP;
522 ArrayRCP<LocalOrdinal> rowptr2_RCP;
523 ArrayRCP<const LocalOrdinal> colind_RCP;
524 ArrayRCP<const Scalar> vals_RCP;
525 tmp_CrsMtx->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
527 ArrayView<const size_t> rowptr = rowptr_RCP();
528 ArrayView<const LocalOrdinal> colind = colind_RCP();
529 ArrayView<const Scalar> vals = vals_RCP();
531 rowptr2_RCP.resize(rowptr.size());
532 ArrayView<LocalOrdinal> rowptr2 = rowptr2_RCP();
533 for (
size_t j = 0; j < Teuchos::as<size_t>(rowptr.size()); j++)
534 rowptr2[j] = rowptr[j];
536 Teuchos::MatrixMarket::Raw::Writer<Scalar, LocalOrdinal> writer;
537 writer.writeFile(fileName +
"." + std::to_string(Op.
getRowMap()->getComm()->getSize()) +
"." + std::to_string(Op.
getRowMap()->getComm()->getRank()),
538 rowptr2, colind, vals,
539 rowptr.size() - 1, Op.
getColMap()->getLocalNumElements());
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) {
549 TEUCHOS_TEST_FOR_EXCEPTION(cond,
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()));
574 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) {
578 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
579 Epetra_CrsMatrix* eA;
581 int rv = EpetraExt::MatrixMarketFileToCrsMatrix(fileName.c_str(), *epcomm, eA);
585 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
587 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> A =
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;
605 RCP<sparse_matrix_type> tA = reader_type::readSparseFile(fileName, comm, callFillComplete);
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();
637 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> A;
640 Teuchos::Array<GlobalOrdinal> inds;
641 Teuchos::Array<Scalar> vals;
643 Teuchos::ArrayRCP<size_t> numEntriesPerRow(m);
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);
687 Teuchos::ArrayRCP<size_t> numEntriesPerRow(0);
691 A->fillComplete(domainMap, rangeMap);
696 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
699 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
Read(
const std::string& filename,
704 const bool callFillComplete =
true,
705 const bool binary =
false,
706 const bool tolerant =
false,
707 const bool debug =
false) {
710 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> domain = (domainMap.is_null() ? rowMap : domainMap);
711 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> range = (rangeMap.is_null() ? rowMap : rangeMap);
714 if (binary ==
false) {
716 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
717 Epetra_CrsMatrix* eA;
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);
734 RCP<Epetra_CrsMatrix> tmpA = rcp(eA);
735 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> A =
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;
752 const RCP<const map_type> tpetraRowMap =
Map2TpetraMap(*rowMap);
753 RCP<const map_type> tpetraColMap = (colMap.is_null() ? Teuchos::null :
Map2TpetraMap(*colMap));
754 const RCP<const map_type> tpetraRangeMap = (rangeMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*rangeMap));
755 const RCP<const map_type> tpetraDomainMap = (domainMap.is_null() ? tpetraRowMap :
Map2TpetraMap(*domainMap));
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);
787 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
790 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
ReadLocal(
const std::string& filename,
795 const bool callFillComplete =
true,
796 const bool binary =
false,
797 const bool tolerant =
false,
798 const bool debug =
false) {
799 TEUCHOS_TEST_FOR_EXCEPTION(rowMap.is_null(),
Exceptions::RuntimeError,
"Utils::ReadLocal() : rowMap cannot be null");
800 TEUCHOS_TEST_FOR_EXCEPTION(colMap.is_null(),
Exceptions::RuntimeError,
"Utils::ReadLocal() : colMap cannot be null");
806 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> domain = (domainMap.is_null() ? rowMap : domainMap);
807 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> range = (rangeMap.is_null() ? rowMap : rangeMap);
809 std::string rankFilename = filename +
"." + std::to_string(rowMap->getComm()->getSize()) +
"." + std::to_string(rowMap->getComm()->getRank());
810 RCP<matrix_type> A = rcp(
new crs_wrap_type(rowMap, colMap, 0));
812 if (binary ==
false) {
813 RCP<Teuchos::ParameterList> params = rcp(
new Teuchos::ParameterList());
814 params->set(
"Parse tolerantly", tolerant);
815 params->set(
"Debug mode", debug);
820 ArrayRCP<LocalOrdinal> rowptr2_RCP;
821 ArrayRCP<LocalOrdinal> colind2_RCP;
822 ArrayRCP<Scalar> vals2_RCP;
824 Teuchos::MatrixMarket::Raw::Reader<Scalar, LocalOrdinal> reader;
825 reader.readFile(rowptr2_RCP, colind2_RCP, vals2_RCP,
829 RCP<crs_type> ACrs = Teuchos::rcp_dynamic_cast<crs_wrap_type>(A)->getCrsMatrix();
831 ArrayRCP<size_t> rowptr_RCP;
832 ArrayRCP<LocalOrdinal> colind_RCP;
833 ArrayRCP<Scalar> vals_RCP;
834 ACrs->allocateAllValues(colind2_RCP.size(), rowptr_RCP, colind_RCP, vals_RCP);
836 rowptr_RCP.assign(rowptr2_RCP.begin(), rowptr2_RCP.end());
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));
851 TEUCHOS_ASSERT_EQUALITY(Teuchos::as<int>(rowMap->getLocalNumElements()), m);
853 Teuchos::ArrayRCP<size_t> rowptrRCP;
854 Teuchos::ArrayRCP<LocalOrdinal> indicesRCP;
855 Teuchos::ArrayRCP<Scalar> valuesRCP;
857 RCP<crs_type> ACrs = Teuchos::rcp_dynamic_cast<crs_wrap_type>(A)->getCrsMatrix();
859 ACrs->allocateAllValues(nnz, rowptrRCP, indicesRCP, valuesRCP);
861 Teuchos::ArrayView<size_t> rowptr = rowptrRCP();
862 Teuchos::ArrayView<LocalOrdinal> indices = indicesRCP();
863 Teuchos::ArrayView<Scalar> values = 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];
878 TEUCHOS_ASSERT(Teuchos::as<int>(rowptr[m]) == nnz);
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]);
919 TEUCHOS_ASSERT(sorted);
922 ACrs->setAllValues(rowptrRCP, indicesRCP, valuesRCP);
925 if (callFillComplete)
926 A->fillComplete(domainMap, rangeMap);
930 static RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
ReadMultiVector(
const std::string& fileName,
932 const bool binary =
false) {
938 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
939 TEUCHOS_ASSERT(!binary);
940 Epetra_MultiVector* MV;
941 int rv = EpetraExt::MatrixMarketFileToMultiVector(fileName.c_str(),
toEpetra(map), MV);
943 RCP<Epetra_MultiVector> MVrcp = rcp(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;
959 RCP<const map_type> temp =
toTpetra(map);
960 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName, map->getComm(), temp,
false,
false, binary);
961 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> rmv =
Xpetra::toXpetra(TMV);
971 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
974 static RCP<Xpetra::MultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>
ReadMultiVectorLO(
const std::string& fileName,
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;
986 RCP<const map_type> temp =
toTpetra(map);
987 RCP<multivector_type> TMV = reader_type::readDenseFile(fileName, map->getComm(), temp,
false,
false, binary);
988 RCP<Xpetra::MultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> rmv =
Xpetra::toXpetra(TMV);
997 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
1000 static RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
ReadMap(
const std::string& fileName,
1002 const RCP<
const Teuchos::Comm<int>>& comm,
1003 const bool binary =
false) {
1007 #if defined(HAVE_XPETRA_EPETRA) && defined(HAVE_XPETRA_EPETRAEXT)
1008 TEUCHOS_ASSERT(!binary);
1010 int rv = EpetraExt::MatrixMarketFileToMap(fileName.c_str(), *(
Xpetra::toEpetra(comm)), eMap);
1014 RCP<Epetra_Map> eMap1 = rcp(
new Epetra_Map(*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;
1028 RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> tMap = reader_type::readMapFile(fileName, comm,
false,
false, binary);
1041 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
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;
1082 RCP<const Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node>> rangeMapExtractor =
1086 bool bDomainUseThyraStyleNumbering =
false;
1092 RCP<const Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node>> domainMapExtractor =
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;
1123 #endif // HAVE_XPETRA_EPETRA
1127 #define XPETRA_IO_SHORT
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.
RCP< CrsMatrix > getCrsMatrix() const
std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.
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 void Write(const std::string &fileName, const Xpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, const bool &writeAllMaps=false)
virtual const RCP< const Map > & getColMap() const
Returns the Map that describes the column distribution in this matrix. This might be null until fillC...
RCP< const MapExtractor > getDomainMapExtractor() const
Returns map extractor for domain map.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const =0
Returns the Map that describes the column distribution in this graph.
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 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)
virtual const RCP< const Map > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
static void WriteLocal(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Exception throws to report errors in the internal logical of the program.
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.
virtual size_t Cols() const
number of column blocks
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsGraph() const
Get the underlying Tpetra graph.
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.
Exception indicating invalid cast attempted.
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 Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
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.
RCP< Xpetra::CrsMatrixWrap< SC, LO, GO, NO > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP< Epetra_CrsMatrix > &)
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, 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)
static void WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
virtual size_t Rows() const
number of row blocks
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...
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const =0
Returns the Map associated with the domain of this graph.
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 std::string toString(const T &what)
Little helper function to convert non-string types to strings.
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)
RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetra_Map() const
Get the underlying Tpetra map.
RCP< const MapExtractor > getRangeMapExtractor() const
Returns map extractor class for range map.
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.
Teuchos::RCP< Matrix > getMatrix(size_t r, size_t c) const
return block (r,c)
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
static RCP< Matrix > Build(const RCP< const Map > &rowMap)
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)
RCP< Xpetra::MultiVector< SC, LO, GO, NO > > Convert_Epetra_MultiVector_ToXpetra_MultiVector(RCP< Epetra_MultiVector > &epX)
RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrix() const
Get the underlying Tpetra matrix.
Concrete implementation of Xpetra::Matrix.
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.
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...
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_MultiVector() const
Get the underlying Tpetra multivector.
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 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::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
Read/Write methods.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const =0
Returns the Map associated with the domain of this graph.
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 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< const Map > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int >> &comm, const bool binary=false)
Xpetra utility class containing IO routines to read/write vectors, matrices etc...
static void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
Read/Write methods.
static void WriteLOMV(const std::string &fileName, const Xpetra::MultiVector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &vec)
static void Write(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
static void Write(const std::string &fileName, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec)
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< 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.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
Xpetra-specific matrix class.
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.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const =0
Returns the Map that describes the row distribution in this graph.
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.
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
static void WriteGOMV(const std::string &fileName, const Xpetra::MultiVector< GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &vec)