10 #include "Tpetra_Details_PackTriples.hpp"
12 #ifdef HAVE_TPETRACORE_MPI
16 mpiErrorCodeToString(
const int errCode) {
17 if (errCode == MPI_SUCCESS) {
20 char rawErrString[MPI_MAX_ERROR_STRING];
22 int err = MPI_Error_string(errCode, rawErrString, &len);
23 if (err != MPI_SUCCESS) {
27 if (MPI_MAX_ERROR_STRING > 0) {
28 rawErrString[0] =
'\0';
31 return std::string(rawErrString);
36 #endif // HAVE_TPETRACORE_MPI
41 #ifdef HAVE_TPETRACORE_MPI
43 int countPackTriplesCountMpi(MPI_Comm comm,
45 std::ostream* errStrm) {
49 const int errCode = MPI_Pack_size(1, MPI_INT, comm, &curSize);
50 if (errCode != MPI_SUCCESS) {
51 if (errStrm != NULL) {
52 *errStrm <<
"countPackTripleMpi: MPI_Pack_size failed on "
53 <<
"MPI_INT call. MPI reports: "
54 << mpiErrorCodeToString(errCode) << endl;
63 int packTriplesCountMpi(
const int numEnt,
68 std::ostream* errStrm) {
74 int theNumEnt = numEnt;
75 const int errCode = MPI_Pack(&theNumEnt, 1, MPI_INT, outBuf,
76 outBufSize, &outBufCurPos, comm);
77 if (errCode != MPI_SUCCESS) {
78 if (errStrm != NULL) {
79 *errStrm <<
"packTriplesCountMpi: MPI_Pack failed with outBufSize="
80 << outBufSize <<
" and outBufCurPos=" << outBufCurPos
81 <<
". MPI reports: " << mpiErrorCodeToString(errCode)
89 int unpackTriplesCountMpi(
const char inBuf[],
94 std::ostream* errStrm) {
96 int errCode = MPI_SUCCESS;
102 errCode = MPI_Unpack(const_cast<char*>(inBuf), inBufSize, &inBufCurPos,
103 &theNumEnt, 1, MPI_INT, comm);
104 if (errCode != MPI_SUCCESS) {
105 if (errStrm != NULL) {
106 *errStrm <<
"unpackTriplesCountMpi: MPI_Unpack failed on gblRowInd: "
107 <<
"inBufSize=" << inBufSize
108 <<
", inBufCurPos=" << inBufCurPos
109 <<
". MPI reports: " << mpiErrorCodeToString(errCode)
115 if (errStrm != NULL) {
116 *errStrm <<
"unpackTriplesCountMpi: The unpacked number of entries "
117 << theNumEnt <<
" is negative." << endl;
125 #endif // HAVE_TPETRACORE_MPI
128 #ifdef HAVE_TPETRACORE_MPI
131 std::ostream* errStrm)
132 #else // NOT HAVE_TPETRACORE_MPI
135 std::ostream* errStrm)
136 #endif // HAVE_TPETRACORE_MPI
138 #ifdef HAVE_TPETRACORE_MPI
139 using ::Tpetra::Details::extractMpiCommFromTeuchos;
140 MPI_Comm mpiComm = extractMpiCommFromTeuchos(comm);
141 return countPackTriplesCountMpi(mpiComm, size, errStrm);
142 #else // NOT HAVE_TPETRACORE_MPI
144 if (errStrm != NULL) {
145 *errStrm <<
"countPackTriplesCount: Not implemented (no need; there's no "
146 "need to pack or unpack anything if there's only one process)."
150 #endif // HAVE_TPETRACORE_MPI
154 #ifdef HAVE_TPETRACORE_MPI
157 const int outBufSize,
159 const ::Teuchos::Comm<int>& comm,
160 std::ostream* errStrm)
161 #else // NOT HAVE_TPETRACORE_MPI
166 const ::Teuchos::Comm<int>& ,
167 std::ostream* errStrm)
168 #endif // HAVE_TPETRACORE_MPI
170 #ifdef HAVE_TPETRACORE_MPI
171 using ::Tpetra::Details::extractMpiCommFromTeuchos;
172 MPI_Comm mpiComm = extractMpiCommFromTeuchos(comm);
173 return packTriplesCountMpi(numEnt, outBuf, outBufSize,
174 outBufCurPos, mpiComm, errStrm);
175 #else // NOT HAVE_TPETRACORE_MPI
176 if (errStrm != NULL) {
177 *errStrm <<
"packTriplesCount: Not implemented (no need; there's no need "
178 "to pack or unpack anything if there's only one process)."
182 #endif // HAVE_TPETRACORE_MPI
186 #ifdef HAVE_TPETRACORE_MPI
191 const ::Teuchos::Comm<int>& comm,
192 std::ostream* errStrm)
193 #else // NOT HAVE_TPETRACORE_MPI
198 const ::Teuchos::Comm<int>& ,
199 std::ostream* errStrm)
200 #endif // HAVE_TPETRACORE_MPI
202 #ifdef HAVE_TPETRACORE_MPI
203 using ::Tpetra::Details::extractMpiCommFromTeuchos;
205 MPI_Comm mpiComm = extractMpiCommFromTeuchos(comm);
207 unpackTriplesCountMpi(inBuf, inBufSize, inBufCurPos,
208 numEnt, mpiComm, errStrm);
211 #else // NOT HAVE_TPETRACORE_MPI
212 if (errStrm != NULL) {
213 *errStrm <<
"unpackTriplesCount: Not implemented (no need; there's no need "
214 "to pack or unpack anything if there's only one process)."
218 #endif // HAVE_TPETRACORE_MPI
int packTriplesCount(const int, char[], const int, int &, const ::Teuchos::Comm< int > &, std::ostream *errStrm)
Pack the count (number) of matrix 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 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")...