summaryrefslogtreecommitdiff
path: root/libs/mpi/src/point_to_point.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-06-25 22:59:01 +0000
committer <>2013-09-27 11:49:28 +0000
commit8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch)
treec09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/mpi/src/point_to_point.cpp
downloadboost-tarball-baserock/morph.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/mpi/src/point_to_point.cpp')
-rw-r--r--libs/mpi/src/point_to_point.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/libs/mpi/src/point_to_point.cpp b/libs/mpi/src/point_to_point.cpp
new file mode 100644
index 000000000..dd0d9bcf0
--- /dev/null
+++ b/libs/mpi/src/point_to_point.cpp
@@ -0,0 +1,98 @@
+// Copyright 2005 Douglas Gregor.
+
+// Use, modification and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Message Passing Interface 1.1 -- Section 3. MPI Point-to-point
+
+/* There is the potential for optimization here. We could keep around
+ a "small message" buffer of size N that we just receive into by
+ default. If the message is N - sizeof(int) bytes or smaller, it can
+ just be sent with that buffer. If it's larger, we send the first N
+ - sizeof(int) bytes in the first packet followed by another
+ packet. The size of the second packet will be stored in an integer
+ at the end of the first packet.
+
+ We will introduce this optimization later, when we have more
+ performance test cases and have met our functionality goals. */
+
+#include <boost/mpi/detail/point_to_point.hpp>
+#include <boost/mpi/datatype.hpp>
+#include <boost/mpi/exception.hpp>
+#include <cassert>
+
+namespace boost { namespace mpi { namespace detail {
+
+void
+packed_archive_send(MPI_Comm comm, int dest, int tag,
+ const packed_oarchive& ar)
+{
+ const void* size = &ar.size();
+ BOOST_MPI_CHECK_RESULT(MPI_Send,
+ (const_cast<void*>(size), 1,
+ get_mpi_datatype<std::size_t>(ar.size()),
+ dest, tag, comm));
+ BOOST_MPI_CHECK_RESULT(MPI_Send,
+ (const_cast<void*>(ar.address()), ar.size(),
+ MPI_PACKED,
+ dest, tag, comm));
+}
+
+int
+packed_archive_isend(MPI_Comm comm, int dest, int tag,
+ const packed_oarchive& ar,
+ MPI_Request* out_requests, int num_out_requests)
+{
+ assert(num_out_requests >= 2);
+ const void* size = &ar.size();
+ BOOST_MPI_CHECK_RESULT(MPI_Isend,
+ (const_cast<void*>(size), 1,
+ get_mpi_datatype<std::size_t>(ar.size()),
+ dest, tag, comm, out_requests));
+ BOOST_MPI_CHECK_RESULT(MPI_Isend,
+ (const_cast<void*>(ar.address()), ar.size(),
+ MPI_PACKED,
+ dest, tag, comm, out_requests + 1));
+
+ return 2;
+}
+
+int
+packed_archive_isend(MPI_Comm comm, int dest, int tag,
+ const packed_iarchive& ar,
+ MPI_Request* out_requests, int num_out_requests)
+{
+ assert(num_out_requests >= 2);
+
+ const void* size = &ar.size();
+ BOOST_MPI_CHECK_RESULT(MPI_Isend,
+ (const_cast<void*>(size), 1,
+ get_mpi_datatype<std::size_t>(ar.size()),
+ dest, tag, comm, out_requests));
+ BOOST_MPI_CHECK_RESULT(MPI_Isend,
+ (const_cast<void*>(ar.address()), ar.size(),
+ MPI_PACKED,
+ dest, tag, comm, out_requests + 1));
+
+ return 2;
+}
+
+void
+packed_archive_recv(MPI_Comm comm, int source, int tag, packed_iarchive& ar,
+ MPI_Status& status)
+{
+ std::size_t count;
+ BOOST_MPI_CHECK_RESULT(MPI_Recv,
+ (&count, 1, get_mpi_datatype<std::size_t>(count),
+ source, tag, comm, &status));
+
+ // Prepare input buffer and receive the message
+ ar.resize(count);
+ BOOST_MPI_CHECK_RESULT(MPI_Recv,
+ (ar.address(), ar.size(), MPI_PACKED,
+ status.MPI_SOURCE, status.MPI_TAG,
+ comm, &status));
+}
+
+} } } // end namespace boost::mpi::detail