Skip to content

Commit 7b9095d

Browse files
committed
mpi: workaround uninitialized MPI_Status
Some MPI implementations (i.e. MPICH) do not initialize the members of the `MPI_Status` struct/object. This may lead to undefined behaviour in our error-checking and logging. Signed-off-by: Torbjörn Klatt <[email protected]>
1 parent 3a8c942 commit 7b9095d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

include/pfasst/mpi_communicator.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ using namespace std;
1111
#include "pfasst/logging.hpp"
1212

1313

14+
/**
15+
* creates and initializes a new _empty_ `MPI_Status` object
16+
*
17+
* An _empty_ `MPI_Status` is defined as an `MPI_Status` object with `MPI_ERROR` as `MPI_SUCCESS`,
18+
* `MPI_SOURCE` as `MPI_ANY_SOURCE` and `MPI_TAG` as `MPI_ANY_TAG`
19+
* (cf. MPI Standard v3; section 3.7.3).
20+
*
21+
* rationale: some MPI implementations don't initialize the members of `MPI_Status` correctly
22+
*
23+
* @returns _empty_ `MPI_Status` object
24+
*
25+
* @ingroup Utilities
26+
*/
27+
inline static MPI_Status MPI_Status_factory()
28+
{
29+
MPI_Status stat;
30+
stat.MPI_ERROR = MPI_SUCCESS;
31+
stat.MPI_SOURCE = MPI_ANY_SOURCE;
32+
stat.MPI_TAG = MPI_ANY_TAG;
33+
return stat;
34+
}
35+
36+
1437
namespace pfasst
1538
{
1639
namespace mpi

src/pfasst/encap/vector_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace pfasst
207207
if (mpi.size() == 1) { return; }
208208
if (mpi.rank() == 0) { return; }
209209

210-
MPI_Status stat;
210+
MPI_Status stat = MPI_Status_factory();
211211
int err = MPI_SUCCESS;
212212

213213
if (blocking) {
@@ -231,7 +231,7 @@ namespace pfasst
231231
if (mpi.size() == 1) { return; }
232232
if (mpi.rank() == mpi.size() - 1) { return; }
233233

234-
MPI_Status stat;
234+
MPI_Status stat = MPI_Status_factory();
235235
int err = MPI_SUCCESS;
236236
int dest = (mpi.rank() + 1) % mpi.size();
237237

0 commit comments

Comments
 (0)