42 #include "Tpetra_Details_PackTriples.hpp"
44 #ifdef HAVE_TPETRACORE_MPI
48 mpiErrorCodeToString (
const int errCode)
50 if (errCode == MPI_SUCCESS) {
54 char rawErrString[MPI_MAX_ERROR_STRING];
56 int err = MPI_Error_string (errCode, rawErrString, &len);
57 if (err != MPI_SUCCESS) {
61 if (MPI_MAX_ERROR_STRING > 0) {
62 rawErrString[0] =
'\0';
65 return std::string (rawErrString);
70 #endif // HAVE_TPETRACORE_MPI
75 #ifdef HAVE_TPETRACORE_MPI
78 countPackTriplesCountMpi (MPI_Comm comm,
80 std::ostream* errStrm)
85 const int errCode = MPI_Pack_size (1, MPI_INT, comm, &curSize);
86 if (errCode != MPI_SUCCESS) {
87 if (errStrm != NULL) {
88 *errStrm <<
"countPackTripleMpi: MPI_Pack_size failed on "
89 <<
"MPI_INT call. MPI reports: "
90 << mpiErrorCodeToString (errCode) << endl;
100 packTriplesCountMpi (
const int numEnt,
102 const int outBufSize,
105 std::ostream* errStrm)
112 int theNumEnt = numEnt;
113 const int errCode = MPI_Pack (&theNumEnt, 1, MPI_INT, outBuf,
114 outBufSize, &outBufCurPos, comm);
115 if (errCode != MPI_SUCCESS) {
116 if (errStrm != NULL) {
117 *errStrm <<
"packTriplesCountMpi: MPI_Pack failed with outBufSize="
118 << outBufSize <<
" and outBufCurPos=" << outBufCurPos
119 <<
". MPI reports: " << mpiErrorCodeToString (errCode)
128 unpackTriplesCountMpi (
const char inBuf[],
133 std::ostream* errStrm)
136 int errCode = MPI_SUCCESS;
142 errCode = MPI_Unpack (const_cast<char*> (inBuf), inBufSize, &inBufCurPos,
143 &theNumEnt, 1, MPI_INT, comm);
144 if (errCode != MPI_SUCCESS) {
145 if (errStrm != NULL) {
146 *errStrm <<
"unpackTriplesCountMpi: MPI_Unpack failed on gblRowInd: "
147 <<
"inBufSize=" << inBufSize
148 <<
", inBufCurPos=" << inBufCurPos
149 <<
". MPI reports: " << mpiErrorCodeToString (errCode)
155 if (errStrm != NULL) {
156 *errStrm <<
"unpackTriplesCountMpi: The unpacked number of entries "
157 << theNumEnt <<
" is negative." << endl;
165 #endif // HAVE_TPETRACORE_MPI
168 #ifdef HAVE_TPETRACORE_MPI
171 std::ostream* errStrm)
172 #else // NOT HAVE_TPETRACORE_MPI
175 std::ostream* errStrm)
176 #endif // HAVE_TPETRACORE_MPI
178 #ifdef HAVE_TPETRACORE_MPI
179 using ::Tpetra::Details::extractMpiCommFromTeuchos;
180 MPI_Comm mpiComm = extractMpiCommFromTeuchos (comm);
181 return countPackTriplesCountMpi (mpiComm, size, errStrm);
182 #else // NOT HAVE_TPETRACORE_MPI
184 if (errStrm != NULL) {
185 *errStrm <<
"countPackTriplesCount: Not implemented (no need; there's no "
186 "need to pack or unpack anything if there's only one process)." << endl;
189 #endif // HAVE_TPETRACORE_MPI
193 #ifdef HAVE_TPETRACORE_MPI
196 const int outBufSize,
198 const ::Teuchos::Comm<int>& comm,
199 std::ostream* errStrm)
200 #else // NOT HAVE_TPETRACORE_MPI
205 const ::Teuchos::Comm<int>& ,
206 std::ostream* errStrm)
207 #endif // HAVE_TPETRACORE_MPI
209 #ifdef HAVE_TPETRACORE_MPI
210 using ::Tpetra::Details::extractMpiCommFromTeuchos;
211 MPI_Comm mpiComm = extractMpiCommFromTeuchos (comm);
212 return packTriplesCountMpi (numEnt, outBuf, outBufSize,
213 outBufCurPos, mpiComm, errStrm);
214 #else // NOT HAVE_TPETRACORE_MPI
215 if (errStrm != NULL) {
216 *errStrm <<
"packTriplesCount: Not implemented (no need; there's no need "
217 "to pack or unpack anything if there's only one process)." << std::endl;
220 #endif // HAVE_TPETRACORE_MPI
224 #ifdef HAVE_TPETRACORE_MPI
229 const ::Teuchos::Comm<int>& comm,
230 std::ostream* errStrm)
231 #else // NOT HAVE_TPETRACORE_MPI
236 const ::Teuchos::Comm<int>& ,
237 std::ostream* errStrm)
238 #endif // HAVE_TPETRACORE_MPI
240 #ifdef HAVE_TPETRACORE_MPI
241 using ::Tpetra::Details::extractMpiCommFromTeuchos;
243 MPI_Comm mpiComm = extractMpiCommFromTeuchos (comm);
245 unpackTriplesCountMpi (inBuf, inBufSize, inBufCurPos,
246 numEnt, mpiComm, errStrm);
249 #else // NOT HAVE_TPETRACORE_MPI
250 if (errStrm != NULL) {
251 *errStrm <<
"unpackTriplesCount: Not implemented (no need; there's no need "
252 "to pack or unpack anything if there's only one process)." << std::endl;
255 #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")...