]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/include/boost/mpi/exception.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / mpi / include / boost / mpi / exception.hpp
1 // Copyright (C) 2005-2006 Douglas Gregor <doug.gregor -at- gmail.com>.
2
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 /** @file exception.hpp
8 *
9 * This header provides exception classes that report MPI errors to
10 * the user and macros that translate MPI error codes into Boost.MPI
11 * exceptions.
12 */
13 #ifndef BOOST_MPI_EXCEPTION_HPP
14 #define BOOST_MPI_EXCEPTION_HPP
15
16 #include <boost/mpi/config.hpp>
17 #include <exception>
18 #include <string>
19 #include <boost/config.hpp>
20 #include <boost/throw_exception.hpp>
21
22 namespace boost { namespace mpi {
23
24 /** @brief Catch-all exception class for MPI errors.
25 *
26 * Instances of this class will be thrown when an MPI error
27 * occurs. MPI failures that trigger these exceptions may or may not
28 * be recoverable, depending on the underlying MPI
29 * implementation. Consult the documentation for your MPI
30 * implementation to determine the effect of MPI errors.
31 */
32 class BOOST_MPI_DECL exception : public std::exception
33 {
34 public:
35 /**
36 * Build a new @c exception exception.
37 *
38 * @param routine The MPI routine in which the error
39 * occurred. This should be a pointer to a string constant: it
40 * will not be copied.
41 *
42 * @param result_code The result code returned from the MPI
43 * routine that aborted with an error.
44 */
45 exception(const char* routine, int result_code);
46
47 virtual ~exception() throw();
48
49 /**
50 * A description of the error that occurred.
51 */
52 virtual const char * what () const throw ()
53 {
54 return this->message.c_str();
55 }
56
57 /** Retrieve the name of the MPI routine that reported the error. */
58 const char* routine() const { return routine_; }
59
60 /**
61 * @brief Retrieve the result code returned from the MPI routine
62 * that reported the error.
63 */
64 int result_code() const { return result_code_; }
65
66 /**
67 * @brief Returns the MPI error class associated with the error that
68 * triggered this exception.
69 */
70 int error_class() const
71 {
72 int result;
73 MPI_Error_class(result_code_, &result);
74 return result;
75 }
76
77 protected:
78 /// The MPI routine that triggered the error
79 const char* routine_;
80
81 /// The failed result code reported by the MPI implementation.
82 int result_code_;
83
84 /// The formatted error message
85 std::string message;
86 };
87
88 /**
89 * Call the MPI routine MPIFunc with arguments Args (surrounded by
90 * parentheses). If the result is not MPI_SUCCESS, use
91 * boost::throw_exception to throw an exception or abort, depending on
92 * BOOST_NO_EXCEPTIONS.
93 */
94 #define BOOST_MPI_CHECK_RESULT( MPIFunc, Args ) \
95 { \
96 int _check_result = MPIFunc Args; \
97 if (_check_result != MPI_SUCCESS) \
98 boost::throw_exception(boost::mpi::exception(#MPIFunc, \
99 _check_result)); \
100 }
101
102 } } // end namespace boost::mpi
103
104 #endif // BOOST_MPI_EXCEPTION_HPP