File indexing completed on 2025-01-30 09:46:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_MPI_STATUS_HPP
0013 #define BOOST_MPI_STATUS_HPP
0014
0015 #include <boost/mpi/config.hpp>
0016 #include <boost/mpi/datatype.hpp>
0017 #include <boost/optional.hpp>
0018 #include <boost/mpl/bool.hpp>
0019
0020 namespace boost { namespace mpi {
0021
0022 class request;
0023 class communicator;
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 class BOOST_MPI_DECL status
0036 {
0037 public:
0038 status() : m_count(-1) { }
0039
0040 status(MPI_Status const& s) : m_status(s), m_count(-1) {}
0041
0042
0043
0044
0045 int source() const { return m_status.MPI_SOURCE; }
0046
0047
0048
0049
0050 int tag() const { return m_status.MPI_TAG; }
0051
0052
0053
0054
0055 int error() const { return m_status.MPI_ERROR; }
0056
0057
0058
0059
0060
0061 bool cancelled() const;
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 template<typename T> optional<int> count() const { return count_impl<T>(is_mpi_datatype<T>()); }
0074
0075
0076
0077
0078 operator MPI_Status&() { return m_status; }
0079
0080
0081
0082
0083 operator const MPI_Status&() const { return m_status; }
0084
0085 private:
0086
0087
0088
0089 template<typename T> optional<int> count_impl(mpl::true_) const;
0090
0091
0092
0093
0094 template<typename T> optional<int> count_impl(mpl::false_) const;
0095
0096 public:
0097
0098
0099 mutable MPI_Status m_status;
0100 mutable int m_count;
0101
0102 friend class communicator;
0103 friend class request;
0104 };
0105
0106 template<typename T>
0107 inline optional<int> status::count_impl(mpl::true_) const
0108 {
0109 if (m_count != -1)
0110 return m_count;
0111
0112 int return_value;
0113 BOOST_MPI_CHECK_RESULT(MPI_Get_count,
0114 (&m_status, get_mpi_datatype<T>(T()), &return_value));
0115 if (return_value == MPI_UNDEFINED)
0116 return optional<int>();
0117 else
0118
0119 return m_count = return_value;
0120 }
0121
0122 template<typename T>
0123 inline optional<int> status::count_impl(mpl::false_) const
0124 {
0125 if (m_count == -1)
0126 return optional<int>();
0127 else
0128 return m_count;
0129 }
0130
0131
0132 } }
0133
0134 #endif