]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 8 Jul 2022 03:38:13 +0000 (21:38 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 11 Jul 2022 22:51:53 +0000 (16:51 -0600)
tests/mpi/isend_irecv_01.cc [new file with mode: 0644]
tests/mpi/isend_irecv_01.mpirun=2.output [new file with mode: 0644]
tests/mpi/isend_irecv_01.mpirun=4.output [new file with mode: 0644]

diff --git a/tests/mpi/isend_irecv_01.cc b/tests/mpi/isend_irecv_01.cc
new file mode 100644 (file)
index 0000000..f525129
--- /dev/null
@@ -0,0 +1,97 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 - 2022 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Test Utilities::MPI::isend() and Utilities::MPI::irecv().
+
+#include <deal.II/base/mpi.h>
+
+#include "../tests.h"
+
+
+
+void
+test(const MPI_Comm comm)
+{
+  using MessageType = unsigned int;
+
+  // First post a bunch of receives before we start working on the
+  // sends. We expect ten sends from each other process.
+  std::multimap<unsigned int, Utilities::MPI::Future<MessageType>>
+    receive_futures;
+  for (unsigned int rank = 0; rank < Utilities::MPI::n_mpi_processes(comm);
+       ++rank)
+    if (rank != Utilities::MPI::this_mpi_process(comm))
+      for (unsigned int message = 0; message < 10; ++message)
+        {
+          receive_futures.emplace(rank,
+                                  Utilities::MPI::irecv<MessageType>(comm,
+                                                                     rank));
+        }
+
+  // Wait a bit -- make sure all of those std::future-like objects are
+  // actually delayed a bit before we query them below.
+  sleep(10);
+
+  // Send ten packages each to each of the other processes. Each
+  // packet is simply an unsigned integer with that other process's
+  // rank.
+  std::vector<Utilities::MPI::Future<void>> send_futures;
+  for (unsigned int rank = 0; rank < Utilities::MPI::n_mpi_processes(comm);
+       ++rank)
+    if (rank != Utilities::MPI::this_mpi_process(comm))
+      for (unsigned int message = 0; message < 10; ++message)
+        {
+          send_futures.emplace_back(
+            Utilities::MPI::isend(MessageType(rank), comm, rank));
+        }
+
+  // Finally wait for the receives to be done as well.
+  for (auto &receive_future : receive_futures)
+    {
+      // Wait for the receive, obtain the message, and make sure that
+      // it is what we expected:
+      const MessageType message = receive_future.second.get();
+      Assert(message == Utilities::MPI::this_mpi_process(comm),
+             ExcMessage("On process " +
+                        std::to_string(Utilities::MPI::this_mpi_process(comm)) +
+                        ", we were expected a message from process " +
+                        std::to_string(receive_future.first) +
+                        " with a message value equal to the destination "
+                        "process (that is, our own rank). But we got " +
+                        std::to_string(message)));
+      deallog << "Receive future returned successfully." << std::endl;
+    }
+
+  // Finally wait for the sends to be done as well.
+  for (auto &send_future : send_futures)
+    {
+      send_future.wait();
+      deallog << "Send future returned successfully." << std::endl;
+    }
+}
+
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll                    all;
+
+  const MPI_Comm comm = MPI_COMM_WORLD;
+
+  test(comm);
+}
diff --git a/tests/mpi/isend_irecv_01.mpirun=2.output b/tests/mpi/isend_irecv_01.mpirun=2.output
new file mode 100644 (file)
index 0000000..382990d
--- /dev/null
@@ -0,0 +1,43 @@
+
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+
diff --git a/tests/mpi/isend_irecv_01.mpirun=4.output b/tests/mpi/isend_irecv_01.mpirun=4.output
new file mode 100644 (file)
index 0000000..94b5204
--- /dev/null
@@ -0,0 +1,247 @@
+
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Receive future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+DEAL:0::Send future returned successfully.
+
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Receive future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+DEAL:1::Send future returned successfully.
+
+
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Receive future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+DEAL:2::Send future returned successfully.
+
+
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Receive future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+DEAL:3::Send future returned successfully.
+

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.