]>
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> | |
11fdf7f2 | 23 | #include <boost/mpi/detail/antiques.hpp> |
7c673cae FG |
24 | #include <cassert> |
25 | ||
26 | namespace boost { namespace mpi { namespace detail { | |
27 | ||
28 | void | |
29 | packed_archive_send(MPI_Comm comm, int dest, int tag, | |
30 | const packed_oarchive& ar) | |
31 | { | |
11fdf7f2 | 32 | std::size_t const& size = ar.size(); |
7c673cae | 33 | BOOST_MPI_CHECK_RESULT(MPI_Send, |
11fdf7f2 TL |
34 | (detail::unconst(&size), 1, |
35 | get_mpi_datatype(size), | |
7c673cae FG |
36 | dest, tag, comm)); |
37 | BOOST_MPI_CHECK_RESULT(MPI_Send, | |
11fdf7f2 | 38 | (detail::unconst(ar.address()), size, |
7c673cae FG |
39 | MPI_PACKED, |
40 | dest, tag, comm)); | |
41 | } | |
42 | ||
43 | int | |
44 | packed_archive_isend(MPI_Comm comm, int dest, int tag, | |
45 | const packed_oarchive& ar, | |
46 | MPI_Request* out_requests, int num_out_requests) | |
47 | { | |
48 | assert(num_out_requests >= 2); | |
11fdf7f2 | 49 | std::size_t const& size = ar.size(); |
7c673cae | 50 | BOOST_MPI_CHECK_RESULT(MPI_Isend, |
11fdf7f2 TL |
51 | (detail::unconst(&size), 1, |
52 | get_mpi_datatype(size), | |
7c673cae FG |
53 | dest, tag, comm, out_requests)); |
54 | BOOST_MPI_CHECK_RESULT(MPI_Isend, | |
11fdf7f2 | 55 | (detail::unconst(ar.address()), size, |
7c673cae FG |
56 | MPI_PACKED, |
57 | dest, tag, comm, out_requests + 1)); | |
58 | ||
59 | return 2; | |
60 | } | |
61 | ||
62 | int | |
63 | packed_archive_isend(MPI_Comm comm, int dest, int tag, | |
64 | const packed_iarchive& ar, | |
65 | MPI_Request* out_requests, int num_out_requests) | |
66 | { | |
67 | assert(num_out_requests >= 2); | |
68 | ||
11fdf7f2 | 69 | std::size_t const& size = ar.size(); |
7c673cae | 70 | BOOST_MPI_CHECK_RESULT(MPI_Isend, |
11fdf7f2 TL |
71 | (detail::unconst(&size), 1, |
72 | get_mpi_datatype(size), | |
7c673cae FG |
73 | dest, tag, comm, out_requests)); |
74 | BOOST_MPI_CHECK_RESULT(MPI_Isend, | |
11fdf7f2 | 75 | (detail::unconst(ar.address()), size, |
7c673cae FG |
76 | MPI_PACKED, |
77 | dest, tag, comm, out_requests + 1)); | |
78 | ||
79 | return 2; | |
80 | } | |
81 | ||
82 | void | |
83 | packed_archive_recv(MPI_Comm comm, int source, int tag, packed_iarchive& ar, | |
84 | MPI_Status& status) | |
85 | { | |
86 | std::size_t count; | |
87 | BOOST_MPI_CHECK_RESULT(MPI_Recv, | |
11fdf7f2 | 88 | (&count, 1, get_mpi_datatype(count), |
7c673cae FG |
89 | source, tag, comm, &status)); |
90 | ||
91 | // Prepare input buffer and receive the message | |
92 | ar.resize(count); | |
93 | BOOST_MPI_CHECK_RESULT(MPI_Recv, | |
11fdf7f2 | 94 | (ar.address(), count, MPI_PACKED, |
7c673cae FG |
95 | status.MPI_SOURCE, status.MPI_TAG, |
96 | comm, &status)); | |
97 | } | |
98 | ||
99 | } } } // end namespace boost::mpi::detail |