]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test. 13492/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 5 Mar 2022 05:02:21 +0000 (22:02 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 5 Mar 2022 05:02:21 +0000 (22:02 -0700)
tests/mpi/broadcast_03.cc [new file with mode: 0644]
tests/mpi/broadcast_03.mpirun=1.output [new file with mode: 0644]
tests/mpi/broadcast_03.mpirun=5.output [new file with mode: 0644]

diff --git a/tests/mpi/broadcast_03.cc b/tests/mpi/broadcast_03.cc
new file mode 100644 (file)
index 0000000..7ee6bf7
--- /dev/null
@@ -0,0 +1,98 @@
+// ---------------------------------------------------------------------
+//
+// 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() for built-in types.
+
+#include <deal.II/base/mpi.h>
+
+#include <iomanip>
+
+#include "../tests.h"
+
+void
+check(const int int_value)
+{
+  const auto my_proc = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+
+  int buffer;
+  if (my_proc == 0)
+    {
+      buffer = int_value;
+    }
+
+  const auto result = Utilities::MPI::broadcast(MPI_COMM_WORLD, buffer);
+
+  deallog << result << " ";
+  deallog << std::endl;
+}
+
+
+void
+check(const double double_value)
+{
+  const auto my_proc = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+
+  double buffer;
+  if (my_proc == 0)
+    {
+      buffer = double_value;
+    }
+
+  const auto result = Utilities::MPI::broadcast(MPI_COMM_WORLD, buffer);
+
+  deallog << std::setprecision(4) << result << " ";
+  deallog << std::endl;
+}
+
+
+void
+check(const std::complex<double> &complex_value)
+{
+  const auto my_proc = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+
+  std::complex<double> buffer;
+  if (my_proc == 0)
+    {
+      buffer = complex_value;
+    }
+
+  const auto result = Utilities::MPI::broadcast(MPI_COMM_WORLD, buffer);
+
+  deallog << std::setprecision(2) << result << " ";
+  deallog << std::endl;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll                    log;
+
+  const unsigned int root = 0;
+  const bool         on_root =
+    (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == root);
+
+  // Test broadcast with int, double, and std::complex data
+  // types. Only provide the right value on the root, and some other
+  // value on non-root processes. We should only see the root value in
+  // the output.
+  check(on_root ? 23 : 12);
+  check(on_root ? 14.32 : std::numeric_limits<double>::max());
+  check(on_root ? std::complex<double>(1., 2.) :
+                  std::complex<double>(1., 222222.));
+}
diff --git a/tests/mpi/broadcast_03.mpirun=1.output b/tests/mpi/broadcast_03.mpirun=1.output
new file mode 100644 (file)
index 0000000..662a8ee
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL:0::23 
+DEAL:0::14.32 
+DEAL:0::(1.0,2.0) 
diff --git a/tests/mpi/broadcast_03.mpirun=5.output b/tests/mpi/broadcast_03.mpirun=5.output
new file mode 100644 (file)
index 0000000..4ce8011
--- /dev/null
@@ -0,0 +1,24 @@
+
+DEAL:0::23 
+DEAL:0::14.32 
+DEAL:0::(1.0,2.0) 
+
+DEAL:1::23 
+DEAL:1::14.32 
+DEAL:1::(1.0,2.0) 
+
+
+DEAL:2::23 
+DEAL:2::14.32 
+DEAL:2::(1.0,2.0) 
+
+
+DEAL:3::23 
+DEAL:3::14.32 
+DEAL:3::(1.0,2.0) 
+
+
+DEAL:4::23 
+DEAL:4::14.32 
+DEAL:4::(1.0,2.0) 
+

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.