Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:46:55

0001 // Copyright (C) 2005-2006 Douglas Gregor <doug.gregor -at- gmail.com>.
0002 
0003 // Use, modification and distribution is subject to the Boost Software
0004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 /** @file exception.hpp
0008  *
0009  *  This header provides exception classes that report MPI errors to
0010  *  the user and macros that translate MPI error codes into Boost.MPI
0011  *  exceptions.
0012  */
0013 #ifndef BOOST_MPI_EXCEPTION_HPP
0014 #define BOOST_MPI_EXCEPTION_HPP
0015 
0016 #include <boost/mpi/config.hpp>
0017 #include <exception>
0018 #include <cassert>
0019 #include <string>
0020 #include <boost/config.hpp>
0021 #include <boost/throw_exception.hpp>
0022 
0023 namespace boost { namespace mpi {
0024 
0025 /** @brief Catch-all exception class for MPI errors.
0026  *
0027  * Instances of this class will be thrown when an MPI error
0028  * occurs. MPI failures that trigger these exceptions may or may not
0029  * be recoverable, depending on the underlying MPI
0030  * implementation. Consult the documentation for your MPI
0031  * implementation to determine the effect of MPI errors.
0032  */
0033 class BOOST_MPI_DECL exception : public std::exception
0034 {
0035  public:
0036   /**
0037    * Build a new @c exception exception.
0038    *
0039    *   @param routine The MPI routine in which the error
0040    *   occurred. This should be a pointer to a string constant: it
0041    *   will not be copied.
0042    *
0043    *   @param result_code The result code returned from the MPI
0044    *   routine that aborted with an error.
0045    */
0046   exception(const char* routine, int result_code);
0047 
0048   virtual ~exception() throw();
0049 
0050   /**
0051    * A description of the error that occurred. 
0052    */
0053   virtual const char * what () const throw ()
0054   {
0055     return this->message.c_str();
0056   }
0057 
0058   /** Retrieve the name of the MPI routine that reported the error. */
0059   const char* routine() const { return routine_; }
0060 
0061   /**
0062    * @brief Retrieve the result code returned from the MPI routine
0063    * that reported the error.
0064    */
0065   int result_code() const { return result_code_; }
0066 
0067   /**
0068    * @brief Returns the MPI error class associated with the error that
0069    * triggered this exception.
0070    */
0071   int error_class() const 
0072   { 
0073     int result;
0074     MPI_Error_class(result_code_, &result);
0075     return result;
0076   }
0077 
0078  protected:
0079   /// The MPI routine that triggered the error
0080   const char* routine_;
0081 
0082   /// The failed result code reported by the MPI implementation.
0083   int result_code_;
0084 
0085   /// The formatted error message
0086   std::string message;
0087 };
0088 
0089 /**
0090  * Call the MPI routine MPIFunc with arguments Args (surrounded by
0091  * parentheses). If the result is not MPI_SUCCESS, use
0092  * boost::throw_exception to throw an exception or abort, depending on
0093  * BOOST_NO_EXCEPTIONS.
0094  */
0095 #define BOOST_MPI_CHECK_RESULT( MPIFunc, Args )                         \
0096  {                                                                      \
0097    int _check_result = MPIFunc Args;                                    \
0098    assert(_check_result == MPI_SUCCESS);                                \
0099    if (_check_result != MPI_SUCCESS)                                    \
0100      boost::throw_exception(boost::mpi::exception(#MPIFunc,   \
0101                                                              _check_result)); \
0102  }
0103 
0104 } } // end namespace boost::mpi
0105 
0106 #endif // BOOST_MPI_EXCEPTION_HPP
0107