From 27d0fcff20481de8b0fdfa0fc0eb43a0ad25d2c5 Mon Sep 17 00:00:00 2001 From: Alain Miniussi Date: Tue, 21 Apr 2015 16:51:33 +0200 Subject: [PATCH] Deal with null communicator when testing topology. 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 or graph communicators. --- src/communicator.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/communicator.cpp b/src/communicator.cpp index b2e85e9..640feae 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