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