summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/mpi/test/block_nonblock_test.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/mpi/test/block_nonblock_test.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/mpi/test/block_nonblock_test.cpp')
-rw-r--r--src/boost/libs/mpi/test/block_nonblock_test.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/boost/libs/mpi/test/block_nonblock_test.cpp b/src/boost/libs/mpi/test/block_nonblock_test.cpp
new file mode 100644
index 00000000..3088b655
--- /dev/null
+++ b/src/boost/libs/mpi/test/block_nonblock_test.cpp
@@ -0,0 +1,95 @@
+#include <vector>
+#include <iostream>
+#include <iterator>
+#include <typeinfo>
+
+#include <boost/mpi.hpp>
+#include <boost/serialization/vector.hpp>
+#include <boost/core/demangle.hpp>
+
+//#include "debugger.cpp"
+
+#define BOOST_TEST_MODULE mpi_nonblocking
+#include <boost/test/included/unit_test.hpp>
+
+namespace mpi = boost::mpi;
+
+template<typename T>
+bool test(mpi::communicator const& comm, std::vector<T> const& ref, bool iswap, bool alloc)
+{
+
+ int rank = comm.rank();
+ if (rank == 0) {
+ std::cout << "Testing with type " << boost::core::demangle(typeid(T).name()) << '\n';
+ if (iswap) {
+ std::cout << "Blockin send, non blocking receive.\n";
+ } else {
+ std::cout << "Non blockin send, blocking receive.\n";
+ }
+ if (alloc) {
+ std::cout << "Explicitly allocate space for the receiver.\n";
+ } else {
+ std::cout << "Do not explicitly allocate space for the receiver.\n";
+ }
+ }
+ if (rank == 0) {
+ std::vector<T> data;
+ if (alloc) {
+ data.resize(ref.size());
+ }
+ if (iswap) {
+ mpi::request req = comm.irecv(1, 0, data);
+ req.wait();
+ } else {
+ comm.recv(1, 0, data);
+ }
+ std::cout << "Process 0 received " << data.size() << " elements :" << std::endl;
+ std::copy(data.begin(), data.end(), std::ostream_iterator<T>(std::cout, " "));
+ std::cout << std::endl;
+ std::cout << "While expecting " << ref.size() << " elements :" << std::endl;
+ std::copy(ref.begin(), ref.end(), std::ostream_iterator<T>(std::cout, " "));
+ std::cout << std::endl;
+ return (data == ref);
+ } else {
+ if (rank == 1) {
+ std::vector<T> vec = ref;
+ if (iswap) {
+ comm.send(0, 0, vec);
+ } else {
+ mpi::request req = comm.isend(0, 0, vec);
+ req.wait();
+ }
+ }
+ return true;
+ }
+}
+
+BOOST_AUTO_TEST_CASE(non_blocking)
+{
+ mpi::environment env;
+ mpi::communicator world;
+
+ BOOST_TEST_REQUIRE(world.size() > 1);
+
+ std::vector<int> integers(13); // don't assume we're lucky
+ for(int i = 0; i < int(integers.size()); ++i) {
+ integers[i] = i;
+ }
+
+ std::vector<std::string> strings(13); // don't assume we're lucky
+ for(int i = 0; i < int(strings.size()); ++i) {
+ std::ostringstream fmt;
+ fmt << "S" << i;
+ strings[i] = fmt.str();
+ }
+
+ BOOST_CHECK(test(world, integers, true, true));
+ BOOST_CHECK(test(world, integers, true, false));
+ BOOST_CHECK(test(world, strings, true, true));
+ BOOST_CHECK(test(world, strings, true, false));
+
+ BOOST_CHECK(test(world, integers, false, true));
+ BOOST_CHECK(test(world, integers, false, false));
+ BOOST_CHECK(test(world, strings, false, true));
+ BOOST_CHECK(test(world, strings, false, false));
+}