request.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 request.hpp
  6. *
  7. * This header defines the class @c request, which contains a request
  8. * for non-blocking communication.
  9. */
  10. #ifndef BOOST_MPI_REQUEST_HPP
  11. #define BOOST_MPI_REQUEST_HPP
  12. #include <boost/mpi/config.hpp>
  13. #include <boost/optional.hpp>
  14. #include <boost/shared_ptr.hpp>
  15. #include <boost/mpi/packed_iarchive.hpp>
  16. namespace boost { namespace mpi {
  17. class status;
  18. class communicator;
  19. /**
  20. * @brief A request for a non-blocking send or receive.
  21. *
  22. * This structure contains information about a non-blocking send or
  23. * receive and will be returned from @c isend or @c irecv,
  24. * respectively.
  25. */
  26. class BOOST_MPI_DECL request
  27. {
  28. public:
  29. /**
  30. * Constructs a NULL request.
  31. */
  32. request();
  33. /**
  34. * Wait until the communication associated with this request has
  35. * completed, then return a @c status object describing the
  36. * communication.
  37. */
  38. status wait();
  39. /**
  40. * Determine whether the communication associated with this request
  41. * has completed successfully. If so, returns the @c status object
  42. * describing the communication. Otherwise, returns an empty @c
  43. * optional<> to indicate that the communication has not completed
  44. * yet. Note that once @c test() returns a @c status object, the
  45. * request has completed and @c wait() should not be called.
  46. */
  47. optional<status> test();
  48. /**
  49. * Cancel a pending communication, assuming it has not already been
  50. * completed.
  51. */
  52. void cancel();
  53. private:
  54. enum request_action { ra_wait, ra_test, ra_cancel };
  55. typedef optional<status> (*handler_type)(request* self,
  56. request_action action);
  57. /**
  58. * INTERNAL ONLY
  59. *
  60. * Handles the non-blocking receive of a serialized value.
  61. */
  62. template<typename T>
  63. static optional<status>
  64. handle_serialized_irecv(request* self, request_action action);
  65. /**
  66. * INTERNAL ONLY
  67. *
  68. * Handles the non-blocking receive of an array of serialized values.
  69. */
  70. template<typename T>
  71. static optional<status>
  72. handle_serialized_array_irecv(request* self, request_action action);
  73. public: // template friends are not portable
  74. /// INTERNAL ONLY
  75. MPI_Request m_requests[2];
  76. /// INTERNAL ONLY
  77. handler_type m_handler;
  78. /// INTERNAL ONLY
  79. shared_ptr<void> m_data;
  80. friend class communicator;
  81. };
  82. } } // end namespace boost::mpi
  83. #endif // BOOST_MPI_REQUEST_HPP