Chris@16: // Copyright (C) 2005-2006 Douglas Gregor . Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: /** @file exception.hpp Chris@16: * Chris@16: * This header provides exception classes that report MPI errors to Chris@16: * the user and macros that translate MPI error codes into Boost.MPI Chris@16: * exceptions. Chris@16: */ Chris@16: #ifndef BOOST_MPI_EXCEPTION_HPP Chris@16: #define BOOST_MPI_EXCEPTION_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace mpi { Chris@16: Chris@16: /** @brief Catch-all exception class for MPI errors. Chris@16: * Chris@16: * Instances of this class will be thrown when an MPI error Chris@16: * occurs. MPI failures that trigger these exceptions may or may not Chris@16: * be recoverable, depending on the underlying MPI Chris@16: * implementation. Consult the documentation for your MPI Chris@16: * implementation to determine the effect of MPI errors. Chris@16: */ Chris@16: class BOOST_MPI_DECL exception : public std::exception Chris@16: { Chris@16: public: Chris@16: /** Chris@16: * Build a new @c exception exception. Chris@16: * Chris@16: * @param routine The MPI routine in which the error Chris@16: * occurred. This should be a pointer to a string constant: it Chris@16: * will not be copied. Chris@16: * Chris@16: * @param result_code The result code returned from the MPI Chris@16: * routine that aborted with an error. Chris@16: */ Chris@16: exception(const char* routine, int result_code); Chris@16: Chris@16: virtual ~exception() throw(); Chris@16: Chris@16: /** Chris@16: * A description of the error that occurred. Chris@16: */ Chris@16: virtual const char * what () const throw () Chris@16: { Chris@16: return this->message.c_str(); Chris@16: } Chris@16: Chris@16: /** Retrieve the name of the MPI routine that reported the error. */ Chris@16: const char* routine() const { return routine_; } Chris@16: Chris@16: /** Chris@16: * @brief Retrieve the result code returned from the MPI routine Chris@16: * that reported the error. Chris@16: */ Chris@16: int result_code() const { return result_code_; } Chris@16: Chris@16: /** Chris@16: * @brief Returns the MPI error class associated with the error that Chris@16: * triggered this exception. Chris@16: */ Chris@16: int error_class() const Chris@16: { Chris@16: int result; Chris@16: MPI_Error_class(result_code_, &result); Chris@16: return result; Chris@16: } Chris@16: Chris@16: protected: Chris@16: /// The MPI routine that triggered the error Chris@16: const char* routine_; Chris@16: Chris@16: /// The failed result code reported by the MPI implementation. Chris@16: int result_code_; Chris@16: Chris@16: /// The formatted error message Chris@16: std::string message; Chris@16: }; Chris@16: Chris@16: /** Chris@16: * Call the MPI routine MPIFunc with arguments Args (surrounded by Chris@16: * parentheses). If the result is not MPI_SUCCESS, use Chris@16: * boost::throw_exception to throw an exception or abort, depending on Chris@16: * BOOST_NO_EXCEPTIONS. Chris@16: */ Chris@16: #define BOOST_MPI_CHECK_RESULT( MPIFunc, Args ) \ Chris@16: { \ Chris@16: int _check_result = MPIFunc Args; \ Chris@16: if (_check_result != MPI_SUCCESS) \ Chris@16: boost::throw_exception(boost::mpi::exception(#MPIFunc, \ Chris@16: _check_result)); \ Chris@16: } Chris@16: Chris@16: } } // end namespace boost::mpi Chris@16: Chris@16: #endif // BOOST_MPI_EXCEPTION_HPP