From 33aa0744d1b78ed83db3d2746dd0dce4db5e232f Mon Sep 17 00:00:00 2001 From: Alain Miniussi Date: Mon, 6 Oct 2014 18:54:29 +0200 Subject: [PATCH] When calling MPI_Topo_test, explicitly deal with MPI_COMM_NULL as it is not a legal value. Although it is what is return for leftovers process when creating cartesian grid or graphs. --- src/communicator.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/communicator.cpp b/src/communicator.cpp index 82caac6..0a5f0d1 100644 --- a/src/communicator.cpp +++ b/src/communicator.cpp @@ -162,20 +162,27 @@ optional communicator::as_intercommunicator() const optional communicator::as_graph_communicator() const { - int status; - BOOST_MPI_CHECK_RESULT(MPI_Topo_test, ((MPI_Comm)*this, &status)); - if (status == MPI_GRAPH) - return graph_communicator(comm_ptr); - else - return optional(); + optional graph; + // topology test not allowed on MPI_NULL_COMM + if (bool(*this)) { + int status; + BOOST_MPI_CHECK_RESULT(MPI_Topo_test, ((MPI_Comm)*this, &status)); + if (status == MPI_GRAPH) + graph = graph_communicator(comm_ptr); + } + return graph; } bool communicator::has_cartesian_topology() const { - int status; - BOOST_MPI_CHECK_RESULT(MPI_Topo_test, ((MPI_Comm)*this, &status)); - - return status == MPI_CART; + // topology test not allowed on MPI_NULL_COM + if (!bool(*this)) { + return false; + } else { + int status; + BOOST_MPI_CHECK_RESULT(MPI_Topo_test, ((MPI_Comm)*this, &status)); + return status == MPI_CART; + } } void communicator::abort(int errcode) const