42#ifndef TPETRA_DETAILS_READTRIPLES_HPP
43#define TPETRA_DETAILS_READTRIPLES_HPP
54#include "TpetraCore_config.h"
55#include "Tpetra_Details_PackTriples.hpp"
56#include "Kokkos_ArithTraits.hpp"
57#include "Teuchos_MatrixMarket_generic.hpp"
58#include "Teuchos_CommHelpers.hpp"
110template<
class OrdinalType,
class RealType>
120 using ::Teuchos::MatrixMarket::readRealData;
128 std::ostringstream
os;
129 os <<
"Failed to read pattern data and/or real value from line "
131 throw std::invalid_argument(
os.str());
139 std::ostringstream
os;
140 os <<
"No more data after real value on line "
142 throw std::invalid_argument (
os.str ());
151 std::ostringstream
os;
152 os <<
"Failed to get imaginary value from line "
154 throw std::invalid_argument (
os.str ());
174 const bool isComplex = ::Kokkos::Details::ArithTraits<SC>::is_complex>
198 const std::string&
line,
202 const bool debug =
false);
212template<
class SC,
class GO>
236 const std::string&
line,
240 const bool debug =
false)
242 using ::Teuchos::MatrixMarket::checkCommentLine;
243 typedef typename ::Kokkos::Details::ArithTraits<SC>::mag_type
real_type;
257 catch (std::exception&
e) {
260 std::ostringstream
os;
261 os <<
"readLine: readComplexData threw an exception: " <<
e.what ()
279 std::ostringstream
os;
280 os <<
"readLine: processTriple returned " <<
errCode <<
" != 0."
299template<
class SC,
class GO>
323 const std::string&
line,
327 const bool debug =
false)
329 using ::Teuchos::MatrixMarket::checkCommentLine;
330 using ::Teuchos::MatrixMarket::readRealData;
341 catch (std::exception&
e) {
344 std::ostringstream
os;
345 os <<
"readLine: readRealData threw an exception: " <<
e.what ()
353 std::ostringstream
os;
355 <<
", val=" <<
val << std::endl;
361 std::ostringstream
os;
362 os <<
"readLine: processTriple returned " <<
errCode <<
" != 0."
399template<
class SC,
class GO>
402 const std::string&
line,
406 const bool debug =
false)
442template<
class SC,
class GO>
451 const bool debug =
false)
453 using Teuchos::MatrixMarket::checkCommentLine;
463 *
errStrm <<
"Input stream reports a failure (not the same as "
464 "end-of-file)." <<
endl;
528 *
errStrm <<
"The input stream is not at end-of-file, "
529 "but is in a bad state." <<
endl;
560template<
class SC,
class GO>
565 ::Teuchos::ArrayRCP<int>&
sizeBuf,
566 ::Teuchos::ArrayRCP<char>&
msgBuf,
569 std::vector<SC>&
vals,
572 const ::Teuchos::Comm<int>& comm,
575 const bool debug =
false)
577 using ::Tpetra::Details::countPackTriplesCount;
578 using ::Tpetra::Details::countPackTriples;
579 using ::Tpetra::Details::packTriplesCount;
580 using ::Tpetra::Details::packTriples;
581 using ::Teuchos::isend;
584 using ::Kokkos::ArithTraits;
588 constexpr int msgTag = 43;
615 std::ostringstream
os;
616 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
617 <<
", GO=" <<
typeid (GO).name () <<
": "
618 <<
"readAndSendOneBatchOfTriples: readTriples read "
619 <<
numEntRead <<
" matrix entries, and returned errCode="
620 <<
errCode <<
"." << std::endl;
627 *
errStrm <<
"readTriples size results are not consistent. "
629 <<
", rowInds.size() = " <<
rowInds.size ()
630 <<
", colInds.size() = " <<
colInds.size ()
631 <<
", and vals.size() = " <<
vals.size () <<
"."
652 std::ostringstream
os;
653 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
654 <<
", GO=" <<
typeid (GO).name () <<
": "
655 <<
"Post send (size=0, errCode=" <<
errCode <<
") "
678 std::ostringstream
os;
679 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
680 <<
", GO=" <<
typeid (GO).name () <<
": "
681 <<
"Post send (size=0, error case) to " <<
destRank
695 std::ostringstream
os;
696 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
697 <<
", GO=" <<
typeid (GO).name () <<
": "
698 <<
"Post send (size=0, error case) to " <<
destRank
711 std::ostringstream
os;
712 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
713 <<
", GO=" <<
typeid (GO).name () <<
": "
735 std::ostringstream
os;
736 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
737 <<
", GO=" <<
typeid (GO).name () <<
": "
738 <<
"Post isend (packed data) to " <<
destRank
749 std::ostringstream
os;
750 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
751 <<
", GO=" <<
typeid (GO).name () <<
": "
752 <<
"Wait on isend (size)" <<
endl;
757 std::ostringstream
os;
758 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
759 <<
", GO=" <<
typeid (GO).name () <<
": "
760 <<
"Wait on isend (packed data)" <<
endl;
810template<
class SC,
class GO,
class CommRequestPtr>
814 std::vector<SC>&
vals,
816 ::Teuchos::ArrayRCP<int>&
sizeBuf,
817 ::Teuchos::ArrayRCP<char>&
msgBuf,
820 const ::Teuchos::Comm<int>& comm,
823 const bool debug =
false)
825 using ::Tpetra::Details::unpackTriplesCount;
826 using ::Tpetra::Details::unpackTriples;
827 using ::Kokkos::ArithTraits;
832 constexpr int msgTag = 43;
838 std::ostringstream
os;
839 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
840 <<
", GO=" <<
typeid (GO).name () <<
": "
841 <<
"Wait on irecv (size)" << std::endl;
848 std::ostringstream
os;
849 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
850 <<
", GO=" <<
typeid (GO).name () <<
": "
851 <<
"Received size: sizeBuf[0]=" <<
sizeBuf[0] << std::endl;
866 std::ostringstream
os;
867 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
868 <<
", GO=" <<
typeid (GO).name () <<
": "
869 <<
"Post irecv (packed data) " <<
"from " <<
srcRank
870 <<
" with tag " <<
msgTag << std::endl;
875 std::ostringstream
os;
876 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
877 <<
", GO=" <<
typeid (GO).name () <<
": "
878 <<
"Wait on irecv (packed data)" << std::endl;
937template<
class SC,
class GO>
944 const ::Teuchos::Comm<int>& comm,
947 const bool debug =
false)
949 using Kokkos::ArithTraits;
958 const int myRank = comm.getRank ();
959 const int numProcs = comm.getSize ();
962 ::Teuchos::ArrayRCP<int>
sizeBuf (1);
963 ::Teuchos::ArrayRCP<char>
msgBuf;
969 std::vector<SC>
vals;
994 std::ostringstream
os;
995 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
996 <<
", GO=" <<
typeid (GO).name () <<
": "
997 <<
"(dest=src) readTriples returned curNumEntRead="
1005 std::ostringstream
os;
1006 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1007 <<
", GO=" <<
typeid (GO).name () <<
": "
1008 <<
"Calling readAndSend... with destRank=" <<
destRank <<
endl;
1022 std::ostringstream
os;
1023 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1024 <<
", GO=" <<
typeid (GO).name () <<
": "
1025 <<
"readAndSend... with destRank=" <<
destRank
1034 std::ostringstream
os;
1035 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1036 <<
", GO=" <<
typeid (GO).name () <<
": "
1038 <<
" was legit zero, counts as termination" <<
endl;
1060 std::ostringstream
os;
1061 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1062 <<
", GO=" <<
typeid (GO).name () <<
": "
1063 <<
"Post send (size, termination msg) to " <<
outRank
1064 <<
" with tag " <<
sizeTag <<
"(was last message legit zero? "
1079 std::ostringstream
os;
1080 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1081 <<
", GO=" <<
typeid (GO).name () <<
": "
1082 <<
"Post irecv (size) from " <<
srcRank
1083 <<
" with tag " <<
sizeTag << std::endl;
1094 std::ostringstream
os;
1095 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1096 <<
", GO=" <<
typeid (GO).name () <<
": "
1097 <<
"recvOneBatchOfTriples returned numEnt=" <<
numEnt
1108 *
errStrm <<
"recvOneBatchOfTriples produced inconsistent data sizes. "
1110 <<
", rowInds.size() = " <<
rowInds.size ()
1111 <<
", colInds.size() = " <<
colInds.size ()
1112 <<
", vals.size() = " <<
vals.size () <<
"."
1131 std::ostringstream
os;
1132 os <<
"Proc " << comm.getRank () <<
", SC=" <<
typeid (
SC).name ()
1133 <<
", GO=" <<
typeid (GO).name () <<
": "
1134 <<
"Done with send/recv loop" <<
endl;
1139 using ::Teuchos::outArg;
1140 using ::Teuchos::REDUCE_BOR;
1141 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 ...