10#ifndef TPETRA_DETAILS_READTRIPLES_HPP
11#define TPETRA_DETAILS_READTRIPLES_HPP
22#include "TpetraCore_config.h"
23#include "Tpetra_Details_PackTriples.hpp"
24#include "Kokkos_ArithTraits.hpp"
25#include "Teuchos_MatrixMarket_generic.hpp"
26#include "Teuchos_CommHelpers.hpp"
78template<
class OrdinalType,
class RealType>
88 using ::Teuchos::MatrixMarket::readRealData;
96 std::ostringstream
os;
97 os <<
"Failed to read pattern data and/or real value from line "
99 throw std::invalid_argument(
os.str());
107 std::ostringstream
os;
108 os <<
"No more data after real value on line "
110 throw std::invalid_argument (
os.str ());
119 std::ostringstream
os;
120 os <<
"Failed to get imaginary value from line "
122 throw std::invalid_argument (
os.str ());
142 const bool isComplex = ::Kokkos::ArithTraits<SC>::is_complex>
166 const std::string&
line,
170 const bool debug =
false);
180template<
class SC,
class GO>
204 const std::string&
line,
208 const bool debug =
false)
210 using ::Teuchos::MatrixMarket::checkCommentLine;
211 typedef typename ::Kokkos::ArithTraits<SC>::mag_type
real_type;
225 catch (std::exception&
e) {
228 std::ostringstream
os;
229 os <<
"readLine: readComplexData threw an exception: " <<
e.what ()
247 std::ostringstream
os;
248 os <<
"readLine: processTriple returned " <<
errCode <<
" != 0."
267template<
class SC,
class GO>
291 const std::string&
line,
295 const bool debug =
false)
297 using ::Teuchos::MatrixMarket::checkCommentLine;
298 using ::Teuchos::MatrixMarket::readRealData;
309 catch (std::exception&
e) {
312 std::ostringstream
os;
313 os <<
"readLine: readRealData threw an exception: " <<
e.what ()
321 std::ostringstream
os;
323 <<
", val=" <<
val << std::endl;
329 std::ostringstream
os;
330 os <<
"readLine: processTriple returned " <<
errCode <<
" != 0."
367template<
class SC,
class GO>
370 const std::string&
line,
374 const bool debug =
false)
410template<
class SC,
class GO>
419 const bool debug =
false)
421 using Teuchos::MatrixMarket::checkCommentLine;
431 *
errStrm <<
"Input stream reports a failure (not the same as "
432 "end-of-file)." <<
endl;
496 *
errStrm <<
"The input stream is not at end-of-file, "
497 "but is in a bad state." <<
endl;
528template<
class SC,
class GO>
533 ::Teuchos::ArrayRCP<int>&
sizeBuf,
534 ::Teuchos::ArrayRCP<char>&
msgBuf,
537 std::vector<SC>&
vals,
540 const ::Teuchos::Comm<int>& comm,
543 const bool debug =
false)
545 using ::Tpetra::Details::countPackTriplesCount;
546 using ::Tpetra::Details::countPackTriples;
547 using ::Tpetra::Details::packTriplesCount;
548 using ::Tpetra::Details::packTriples;
549 using ::Teuchos::isend;
552 using ::Kokkos::ArithTraits;
556 constexpr int msgTag = 43;
583 std::ostringstream
os;
584 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
585 <<
", GO=" <<
typeid (GO).name () <<
": "
586 <<
"readAndSendOneBatchOfTriples: readTriples read "
587 <<
numEntRead <<
" matrix entries, and returned errCode="
588 <<
errCode <<
"." << std::endl;
595 *
errStrm <<
"readTriples size results are not consistent. "
597 <<
", rowInds.size() = " <<
rowInds.size ()
598 <<
", colInds.size() = " <<
colInds.size ()
599 <<
", and vals.size() = " <<
vals.size () <<
"."
620 std::ostringstream
os;
621 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
622 <<
", GO=" <<
typeid (GO).name () <<
": "
623 <<
"Post send (size=0, errCode=" <<
errCode <<
") "
646 std::ostringstream
os;
647 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
648 <<
", GO=" <<
typeid (GO).name () <<
": "
649 <<
"Post send (size=0, error case) to " <<
destRank
663 std::ostringstream
os;
664 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
665 <<
", GO=" <<
typeid (GO).name () <<
": "
666 <<
"Post send (size=0, error case) to " <<
destRank
679 std::ostringstream
os;
680 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
681 <<
", GO=" <<
typeid (GO).name () <<
": "
703 std::ostringstream
os;
704 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
705 <<
", GO=" <<
typeid (GO).name () <<
": "
706 <<
"Post isend (packed data) to " <<
destRank
717 std::ostringstream
os;
718 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
719 <<
", GO=" <<
typeid (GO).name () <<
": "
720 <<
"Wait on isend (size)" <<
endl;
725 std::ostringstream
os;
726 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
727 <<
", GO=" <<
typeid (GO).name () <<
": "
728 <<
"Wait on isend (packed data)" <<
endl;
778template<
class SC,
class GO,
class CommRequestPtr>
782 std::vector<SC>&
vals,
784 ::Teuchos::ArrayRCP<int>&
sizeBuf,
785 ::Teuchos::ArrayRCP<char>&
msgBuf,
788 const ::Teuchos::Comm<int>& comm,
791 const bool debug =
false)
793 using ::Tpetra::Details::unpackTriplesCount;
794 using ::Tpetra::Details::unpackTriples;
795 using ::Kokkos::ArithTraits;
800 constexpr int msgTag = 43;
806 std::ostringstream
os;
807 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
808 <<
", GO=" <<
typeid (GO).name () <<
": "
809 <<
"Wait on irecv (size)" << std::endl;
816 std::ostringstream
os;
817 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
818 <<
", GO=" <<
typeid (GO).name () <<
": "
819 <<
"Received size: sizeBuf[0]=" <<
sizeBuf[0] << std::endl;
834 std::ostringstream
os;
835 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
836 <<
", GO=" <<
typeid (GO).name () <<
": "
837 <<
"Post irecv (packed data) " <<
"from " <<
srcRank
838 <<
" with tag " <<
msgTag << std::endl;
843 std::ostringstream
os;
844 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
845 <<
", GO=" <<
typeid (GO).name () <<
": "
846 <<
"Wait on irecv (packed data)" << std::endl;
905template<
class SC,
class GO>
912 const ::Teuchos::Comm<int>& comm,
915 const bool debug =
false)
917 using Kokkos::ArithTraits;
926 const int myRank = comm.getRank ();
927 const int numProcs = comm.getSize ();
930 ::Teuchos::ArrayRCP<int>
sizeBuf (1);
931 ::Teuchos::ArrayRCP<char>
msgBuf;
937 std::vector<SC>
vals;
962 std::ostringstream
os;
963 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
964 <<
", GO=" <<
typeid (GO).name () <<
": "
965 <<
"(dest=src) readTriples returned curNumEntRead="
973 std::ostringstream
os;
974 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
975 <<
", GO=" <<
typeid (GO).name () <<
": "
976 <<
"Calling readAndSend... with destRank=" <<
destRank <<
endl;
990 std::ostringstream
os;
991 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
992 <<
", GO=" <<
typeid (GO).name () <<
": "
993 <<
"readAndSend... with destRank=" <<
destRank
1002 std::ostringstream
os;
1003 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1004 <<
", GO=" <<
typeid (GO).name () <<
": "
1006 <<
" was legit zero, counts as termination" <<
endl;
1028 std::ostringstream
os;
1029 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1030 <<
", GO=" <<
typeid (GO).name () <<
": "
1031 <<
"Post send (size, termination msg) to " <<
outRank
1032 <<
" with tag " <<
sizeTag <<
"(was last message legit zero? "
1047 std::ostringstream
os;
1048 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1049 <<
", GO=" <<
typeid (GO).name () <<
": "
1050 <<
"Post irecv (size) from " <<
srcRank
1051 <<
" with tag " <<
sizeTag << std::endl;
1062 std::ostringstream
os;
1063 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1064 <<
", GO=" <<
typeid (GO).name () <<
": "
1065 <<
"recvOneBatchOfTriples returned numEnt=" <<
numEnt
1076 *
errStrm <<
"recvOneBatchOfTriples produced inconsistent data sizes. "
1078 <<
", rowInds.size() = " <<
rowInds.size ()
1079 <<
", colInds.size() = " <<
colInds.size ()
1080 <<
", vals.size() = " <<
vals.size () <<
"."
1099 std::ostringstream
os;
1100 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1101 <<
", GO=" <<
typeid (GO).name () <<
": "
1102 <<
"Done with send/recv loop" <<
endl;
1107 using ::Teuchos::outArg;
1108 using ::Teuchos::REDUCE_BOR;
1109 using ::Teuchos::reduceAll;
bool readComplexData(std::istream &istr, OrdinalType &rowIndex, OrdinalType &colIndex, RealType &realPart, RealType &imagPart, const std::size_t lineNumber, const bool tolerant)
Read "<rowIndex> <colIndex> <realPart> <imagPart>" from a line.
int readTriples(std::istream &inputStream, std::size_t &curLineNum, std::size_t &numTriplesRead, std::function< int(const GO, const GO, const SC &)> processTriple, const std::size_t maxNumTriplesToRead, const bool tolerant=false, std::ostream *errStrm=NULL, const bool debug=false)
Read at most numTriplesToRead triples from the given Matrix Market input stream, and pass along any r...
int recvOneBatchOfTriples(std::vector< GO > &rowInds, std::vector< GO > &colInds, std::vector< SC > &vals, int &numEnt, ::Teuchos::ArrayRCP< int > &sizeBuf, ::Teuchos::ArrayRCP< char > &msgBuf, CommRequestPtr &sizeReq, const int srcRank, const ::Teuchos::Comm< int > &comm, const bool tolerant=false, std::ostream *errStrm=NULL, const bool debug=false)
Read at most maxNumEntPerMsg sparse matrix entries from the input stream, and send them to the proces...
int readAndSendOneBatchOfTriples(std::istream &inputStream, std::size_t &curLineNum, std::size_t &numEntRead, ::Teuchos::ArrayRCP< int > &sizeBuf, ::Teuchos::ArrayRCP< char > &msgBuf, std::vector< GO > &rowInds, std::vector< GO > &colInds, std::vector< SC > &vals, const std::size_t maxNumEntPerMsg, const int destRank, const ::Teuchos::Comm< int > &comm, const bool tolerant=false, std::ostream *errStrm=NULL, const bool debug=false)
Read at most maxNumEntPerMsg sparse matrix entries from the input stream, and send them to the proces...
int readLine(std::function< int(const GO, const GO, const SC &)> processTriple, const std::string &line, const std::size_t lineNumber, const bool tolerant=false, std::ostream *errStrm=NULL, const bool debug=false)
Take a line from the Matrix Market file or input stream, and process the sparse matrix entry in that ...
Struct that holds views of the contents of a CrsMatrix.
Implementation details of Tpetra.
int packTriplesCount(const int, char[], const int, int &, const ::Teuchos::Comm< int > &, std::ostream *errStrm)
Pack the count (number) of matrix triples.
int countPackTriplesCount(const ::Teuchos::Comm< int > &, int &size, std::ostream *errStrm)
Compute the buffer size required by packTriples for packing the number of matrix entries ("triples").
int unpackTriplesCount(const char[], const int, int &, int &, const ::Teuchos::Comm< int > &, std::ostream *errStrm)
Unpack just the count of triples from the given input buffer.
int readAndDealOutTriples(std::istream &inputStream, std::size_t &curLineNum, std::size_t &totalNumEntRead, std::function< int(const GO, const GO, const SC &)> processTriple, const std::size_t maxNumEntPerMsg, const ::Teuchos::Comm< int > &comm, const bool tolerant=false, std::ostream *errStrm=NULL, const bool debug=false)
On Process 0 in the given communicator, read sparse matrix entries (in chunks of at most maxNumEntPer...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
static int readLine(std::function< int(const GO, const GO, const SC &)> processTriple, const std::string &line, const std::size_t lineNumber, const bool tolerant=false, std::ostream *errStrm=NULL, const bool debug=false)
Take a line from the Matrix Market file or input stream, and process the sparse matrix entry in that ...
static int readLine(std::function< int(const GO, const GO, const SC &)> processTriple, const std::string &line, const std::size_t lineNumber, const bool tolerant=false, std::ostream *errStrm=NULL, const bool debug=false)
Take a line from the Matrix Market file or input stream, and process the sparse matrix entry in that ...
Implementation of the readLine stand-alone function in this namespace (see below).
static int readLine(std::function< int(const GO, const GO, const SC &)> processTriple, const std::string &line, const std::size_t lineNumber, const bool tolerant=false, std::ostream *errStrm=NULL, const bool debug=false)
Take a line from the Matrix Market file or input stream, and process the sparse matrix entry in that ...