status.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. /** @file status.hpp
  6. *
  7. * This header defines the class @c status, which reports on the
  8. * results of point-to-point communication.
  9. */
  10. #ifndef BOOST_MPI_STATUS_HPP
  11. #define BOOST_MPI_STATUS_HPP
  12. #include <boost/mpi/config.hpp>
  13. #include <boost/optional.hpp>
  14. #include <boost/mpl/bool.hpp>
  15. namespace boost { namespace mpi {
  16. class request;
  17. class communicator;
  18. /** @brief Contains information about a message that has been or can
  19. * be received.
  20. *
  21. * This structure contains status information about messages that
  22. * have been received (with @c communicator::recv) or can be received
  23. * (returned from @c communicator::probe or @c
  24. * communicator::iprobe). It permits access to the source of the
  25. * message, message tag, error code (rarely used), or the number of
  26. * elements that have been transmitted.
  27. */
  28. class BOOST_MPI_DECL status
  29. {
  30. public:
  31. status() : m_count(-1) { }
  32. status(MPI_Status const& s) : m_status(s), m_count(-1) {}
  33. /**
  34. * Retrieve the source of the message.
  35. */
  36. int source() const { return m_status.MPI_SOURCE; }
  37. /**
  38. * Retrieve the message tag.
  39. */
  40. int tag() const { return m_status.MPI_TAG; }
  41. /**
  42. * Retrieve the error code.
  43. */
  44. int error() const { return m_status.MPI_ERROR; }
  45. /**
  46. * Determine whether the communication associated with this object
  47. * has been successfully cancelled.
  48. */
  49. bool cancelled() const;
  50. /**
  51. * Determines the number of elements of type @c T contained in the
  52. * message. The type @c T must have an associated data type, i.e.,
  53. * @c is_mpi_datatype<T> must derive @c mpl::true_. In cases where
  54. * the type @c T does not match the transmitted type, this routine
  55. * will return an empty @c optional<int>.
  56. *
  57. * @returns the number of @c T elements in the message, if it can be
  58. * determined.
  59. */
  60. template<typename T> optional<int> count() const;
  61. /**
  62. * References the underlying @c MPI_Status
  63. */
  64. operator MPI_Status&() { return m_status; }
  65. /**
  66. * References the underlying @c MPI_Status
  67. */
  68. operator const MPI_Status&() const { return m_status; }
  69. private:
  70. /**
  71. * INTERNAL ONLY
  72. */
  73. template<typename T> optional<int> count_impl(mpl::true_) const;
  74. /**
  75. * INTERNAL ONLY
  76. */
  77. template<typename T> optional<int> count_impl(mpl::false_) const;
  78. public: // friend templates are not portable
  79. /// INTERNAL ONLY
  80. mutable MPI_Status m_status;
  81. mutable int m_count;
  82. friend class communicator;
  83. friend class request;
  84. };
  85. } } // end namespace boost::mpi
  86. #endif // BOOST_MPI_STATUS_HPP