]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright 2005 Douglas Gregor. |
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 | // Message Passing Interface 1.1 -- Section 3. MPI Point-to-point | |
8 | ||
9 | /* There is the potential for optimization here. We could keep around | |
10 | a "small message" buffer of size N that we just receive into by | |
11 | default. If the message is N - sizeof(int) bytes or smaller, it can | |
12 | just be sent with that buffer. If it's larger, we send the first N | |
13 | - sizeof(int) bytes in the first packet followed by another | |
14 | packet. The size of the second packet will be stored in an integer | |
15 | at the end of the first packet. | |
16 | ||
17 | We will introduce this optimization later, when we have more | |
18 | performance test cases and have met our functionality goals. */ | |
19 | ||
20 | #include <boost/mpi/detail/point_to_point.hpp> | |
21 | #include <boost/mpi/datatype.hpp> | |
22 | #include <boost/mpi/exception.hpp> | |
92f5a8d4 TL |
23 | #include <boost/mpi/request.hpp> |
24 | #include <boost/mpi/communicator.hpp> | |
11fdf7f2 | 25 | #include <boost/mpi/detail/antiques.hpp> |
7c673cae FG |
26 | #include <cassert> |
27 | ||
28 | namespace boost { namespace mpi { namespace detail { | |
29 | ||
30 | void | |
92f5a8d4 | 31 | packed_archive_send(communicator const& comm, int dest, int tag, |
7c673cae FG |
32 | const packed_oarchive& ar) |
33 | { | |
92f5a8d4 TL |
34 | #if defined(BOOST_MPI_USE_IMPROBE) |
35 | { | |
36 | void *buf = detail::unconst(ar.address()); | |
37 | BOOST_MPI_CHECK_RESULT(MPI_Send, | |
38 | (buf, ar.size(), MPI_PACKED, | |
39 | dest, tag, comm)); | |
40 | } | |
41 | #else | |
42 | { | |
43 | std::size_t const& size = ar.size(); | |
44 | BOOST_MPI_CHECK_RESULT(MPI_Send, | |
45 | (detail::unconst(&size), 1, | |
46 | get_mpi_datatype(size), | |
47 | dest, tag, comm)); | |
48 | BOOST_MPI_CHECK_RESULT(MPI_Send, | |
49 | (detail::unconst(ar.address()), size, | |
50 | MPI_PACKED, | |
51 | dest, tag, comm)); | |
52 | } | |
53 | #endif | |
7c673cae FG |
54 | } |
55 | ||
92f5a8d4 TL |
56 | request |
57 | packed_archive_isend(communicator const& comm, int dest, int tag, | |
58 | const packed_oarchive& ar) | |
7c673cae | 59 | { |
92f5a8d4 TL |
60 | return request::make_packed_send(comm, dest, tag, |
61 | detail::unconst(ar.address()), ar.size()); | |
7c673cae FG |
62 | } |
63 | ||
92f5a8d4 TL |
64 | request |
65 | packed_archive_isend(communicator const& comm, int dest, int tag, | |
66 | const packed_iarchive& ar) | |
7c673cae | 67 | { |
92f5a8d4 TL |
68 | return request::make_packed_send(comm, dest, tag, |
69 | detail::unconst(ar.address()), ar.size()); | |
7c673cae FG |
70 | } |
71 | ||
72 | void | |
92f5a8d4 | 73 | packed_archive_recv(communicator const& comm, int source, int tag, packed_iarchive& ar, |
7c673cae FG |
74 | MPI_Status& status) |
75 | { | |
92f5a8d4 TL |
76 | #if defined(BOOST_MPI_USE_IMPROBE) |
77 | { | |
78 | MPI_Message msg; | |
79 | BOOST_MPI_CHECK_RESULT(MPI_Mprobe, (source, tag, comm, &msg, &status)); | |
80 | int count; | |
81 | BOOST_MPI_CHECK_RESULT(MPI_Get_count, (&status, MPI_PACKED, &count)); | |
82 | ar.resize(count); | |
83 | BOOST_MPI_CHECK_RESULT(MPI_Mrecv, (ar.address(), count, MPI_PACKED, &msg, &status)); | |
84 | } | |
85 | #else | |
86 | { | |
87 | std::size_t count; | |
88 | BOOST_MPI_CHECK_RESULT(MPI_Recv, | |
89 | (&count, 1, get_mpi_datatype(count), | |
90 | source, tag, comm, &status)); | |
91 | ||
92 | // Prepare input buffer and receive the message | |
93 | ar.resize(count); | |
94 | BOOST_MPI_CHECK_RESULT(MPI_Recv, | |
95 | (ar.address(), count, MPI_PACKED, | |
96 | status.MPI_SOURCE, status.MPI_TAG, | |
97 | comm, &status)); | |
98 | } | |
99 | #endif | |
7c673cae FG |
100 | } |
101 | ||
102 | } } } // end namespace boost::mpi::detail |