diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 8cc2ca8..b107a15 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -25,6 +25,7 @@ lib boost_mpi computation_tree.cpp content_oarchive.cpp environment.cpp + exception.cpp group.cpp mpi_datatype_cache.cpp mpi_datatype_oarchive.cpp @@ -68,7 +69,7 @@ lib boost_mpi python/datatypes.cpp python/documentation.cpp python/py_environment.cpp - python/exception.cpp + python/py_exception.cpp python/module.cpp python/py_request.cpp python/skeleton_and_content.cpp diff --git a/doc/mpi.qbk b/doc/mpi.qbk index e92b7d3..20d1d4b 100644 --- a/doc/mpi.qbk +++ b/doc/mpi.qbk @@ -1571,7 +1571,7 @@ Boost.MPI translates MPI errors into exceptions, reported via the [[[@http://www.mpi-forum.org/docs/mpi-11-html/node148.html#Node148 `MPI_Error_string`]] [used internally by Boost.MPI]] [[[@http://www.mpi-forum.org/docs/mpi-11-html/node149.html#Node149 - `MPI_Error_class`]] [unsupported]] + `MPI_Error_class`]] [[memberref boost::mpi::exception::error_class `exception::error_class`]]] ] The MPI timing facilities are exposed via the Boost.MPI [classref diff --git a/include/boost/mpi/exception.hpp b/include/boost/mpi/exception.hpp index cf25b67..4ba4d11 100644 --- a/include/boost/mpi/exception.hpp +++ b/include/boost/mpi/exception.hpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -41,33 +42,47 @@ class exception : public std::exception * @param result_code The result code returned from the MPI * routine that aborted with an error. */ - exception(const char* routine, int result_code) - : routine_(routine), result_code_(result_code) { } + exception(const char* routine, int result_code); + + virtual ~exception() throw(); /** - * A description of the error that occured. At present, this refers - * only to the name of the MPI routine that failed. + * A description of the error that occurred. */ virtual const char * what () const throw () { - return routine_; + return this->message.c_str(); } /** Retrieve the name of the MPI routine that reported the error. */ const char* routine() const { return routine_; } /** - * Retrieve the result code returned from the MPI routine that - * reported the error. + * @brief Retrieve the result code returned from the MPI routine + * that reported the error. */ int result_code() const { return result_code_; } + /** + * @brief Returns the MPI error class associated with the error that + * triggered this exception. + */ + int error_class() const + { + int result; + MPI_Error_class(result_code_, &result); + return result; + } + protected: /// The MPI routine that triggered the error const char* routine_; /// The failed result code reported by the MPI implementation. int result_code_; + + /// The formatted error message + std::string message; }; /** diff --git a/src/exception.cpp b/src/exception.cpp new file mode 100644 index 0000000..9cb4c25 --- /dev/null +++ b/src/exception.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2007 Trustees of Indiana University + +// Authors: Douglas Gregor +// Andrew Lumsdaine + +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +#include + +namespace boost { namespace mpi { + +exception::exception(const char* routine, int result_code) + : routine_(routine), result_code_(result_code) +{ + // Query the MPI implementation for its reason for failure + char buffer[MPI_MAX_ERROR_STRING]; + int len; + MPI_Error_string(result_code, buffer, &len); + + // Construct the complete error message + message.append(routine_); + message.append(": "); + message.append(buffer, len); +} + +exception::~exception() throw() { } + +} } // end namespace boost::mpi diff --git a/src/python/Attic/exception.cpp b/src/python/py_exception.cpp similarity index 100% rename from src/python/Attic/exception.cpp rename to src/python/py_exception.cpp