]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add test
authorTimo Heister <timo.heister@gmail.com>
Sat, 12 Feb 2022 22:32:51 +0000 (17:32 -0500)
committerTimo Heister <timo.heister@gmail.com>
Mon, 14 Feb 2022 17:18:46 +0000 (12:18 -0500)
tests/mpi/broadcast_02.cc [new file with mode: 0644]
tests/mpi/broadcast_02.mpirun=3.output [new file with mode: 0644]

diff --git a/tests/mpi/broadcast_02.cc b/tests/mpi/broadcast_02.cc
new file mode 100644 (file)
index 0000000..0f461da
--- /dev/null
@@ -0,0 +1,85 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2021 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::broadcast().
+
+// If this flag is enabled, messages bigger than 2^32 bytes will be
+// transmitted. This takes a while and requires quite a bit of memory,
+// so it is disabled by default:
+bool big = false;
+
+#include <deal.II/base/mpi.h>
+
+#include "../tests.h"
+
+void
+check1()
+{
+  const auto my_proc = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+
+  int x[3];
+  if (my_proc == 0)
+    {
+      x[0] = 1;
+      x[1] = 2;
+      x[2] = 3;
+    }
+
+  Utilities::MPI::broadcast(x, 3, 0, MPI_COMM_WORLD);
+  AssertThrow(x[0] == 1, ExcInternalError());
+  AssertThrow(x[1] == 2, ExcInternalError());
+  AssertThrow(x[2] == 3, ExcInternalError());
+  deallog << "OK" << std::endl;
+}
+
+void
+check2(std::size_t count)
+{
+  const auto my_proc = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+
+  std::vector<char> x(count, '?');
+  if (my_proc == 0)
+    {
+      for (auto &c : x)
+        c = 'X';
+      x[count - 1] = '!';
+    }
+
+  Utilities::MPI::broadcast(x.data(), count, 0, MPI_COMM_WORLD);
+
+  AssertThrow(x[0] == 'X', ExcInternalError());
+  AssertThrow(x[count - 1] == '!', ExcInternalError());
+  deallog << "OK" << std::endl;
+}
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll                    log;
+
+  check1();
+  check2(1ULL << 3);
+
+  if (big)
+    {
+      check2(1ULL << 31);
+      check2((1ULL << 31) + 1);
+      check2(1ULL << 32);
+      check2((1ULL << 32) + 5);
+    }
+}
diff --git a/tests/mpi/broadcast_02.mpirun=3.output b/tests/mpi/broadcast_02.mpirun=3.output
new file mode 100644 (file)
index 0000000..a168662
--- /dev/null
@@ -0,0 +1,11 @@
+
+DEAL:0::OK
+DEAL:0::OK
+
+DEAL:1::OK
+DEAL:1::OK
+
+
+DEAL:2::OK
+DEAL:2::OK
+

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.