From 083a729794c7c73c9f0d0fc0d1ba1dd28b6b774f Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Tue, 12 May 2015 14:51:50 -0400 Subject: [PATCH] add tests for MPI::min() --- tests/mpi/collective_min.cc | 81 +++++++++++++++++++ tests/mpi/collective_min.mpirun=1.output | 2 + tests/mpi/collective_min.mpirun=10.output | 2 + tests/mpi/collective_min.mpirun=4.output | 2 + tests/mpi/collective_min_array.cc | 67 +++++++++++++++ .../mpi/collective_min_array.mpirun=1.output | 2 + .../mpi/collective_min_array.mpirun=10.output | 2 + .../mpi/collective_min_array.mpirun=4.output | 2 + tests/mpi/collective_min_array_in_place.cc | 66 +++++++++++++++ ...lective_min_array_in_place.mpirun=1.output | 2 + ...ective_min_array_in_place.mpirun=10.output | 2 + ...lective_min_array_in_place.mpirun=4.output | 2 + tests/mpi/collective_min_vector.cc | 68 ++++++++++++++++ .../mpi/collective_min_vector.mpirun=1.output | 2 + .../collective_min_vector.mpirun=10.output | 2 + .../mpi/collective_min_vector.mpirun=4.output | 2 + tests/mpi/collective_min_vector_in_place.cc | 67 +++++++++++++++ ...ective_min_vector_in_place.mpirun=1.output | 2 + ...ctive_min_vector_in_place.mpirun=10.output | 2 + ...ective_min_vector_in_place.mpirun=4.output | 2 + 20 files changed, 379 insertions(+) create mode 100644 tests/mpi/collective_min.cc create mode 100644 tests/mpi/collective_min.mpirun=1.output create mode 100644 tests/mpi/collective_min.mpirun=10.output create mode 100644 tests/mpi/collective_min.mpirun=4.output create mode 100644 tests/mpi/collective_min_array.cc create mode 100644 tests/mpi/collective_min_array.mpirun=1.output create mode 100644 tests/mpi/collective_min_array.mpirun=10.output create mode 100644 tests/mpi/collective_min_array.mpirun=4.output create mode 100644 tests/mpi/collective_min_array_in_place.cc create mode 100644 tests/mpi/collective_min_array_in_place.mpirun=1.output create mode 100644 tests/mpi/collective_min_array_in_place.mpirun=10.output create mode 100644 tests/mpi/collective_min_array_in_place.mpirun=4.output create mode 100644 tests/mpi/collective_min_vector.cc create mode 100644 tests/mpi/collective_min_vector.mpirun=1.output create mode 100644 tests/mpi/collective_min_vector.mpirun=10.output create mode 100644 tests/mpi/collective_min_vector.mpirun=4.output create mode 100644 tests/mpi/collective_min_vector_in_place.cc create mode 100644 tests/mpi/collective_min_vector_in_place.mpirun=1.output create mode 100644 tests/mpi/collective_min_vector_in_place.mpirun=10.output create mode 100644 tests/mpi/collective_min_vector_in_place.mpirun=4.output diff --git a/tests/mpi/collective_min.cc b/tests/mpi/collective_min.cc new file mode 100644 index 0000000000..1539da6b1c --- /dev/null +++ b/tests/mpi/collective_min.cc @@ -0,0 +1,81 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2009 - 2015 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check Utilities::MPI::min() + +#include "../tests.h" +#include +#include +#include + +void test() +{ + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + const unsigned int numprocs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + + int int_sum; + unsigned int uint_sum; + double double_sum; + float float_sum; + + int_sum + = + Utilities::MPI::min(numprocs+myid, + MPI_COMM_WORLD); + uint_sum + = + Utilities::MPI::min(numprocs+myid, + MPI_COMM_WORLD); + float_sum + = + Utilities::MPI::min(numprocs+myid, + MPI_COMM_WORLD); + double_sum + = + Utilities::MPI::min(numprocs+myid, + MPI_COMM_WORLD); + + if (myid==0) + deallog << int_sum << ' ' << uint_sum << ' ' << double_sum << ' ' << float_sum << std::endl; +} + + +int main(int argc, char *argv[]) +{ +#ifdef DEAL_II_WITH_MPI + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, numbers::invalid_unsigned_int); +#else + (void)argc; + (void)argv; + compile_time_error; + +#endif + + if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + deallog.push("mpi"); + test(); + deallog.pop(); + } + else + test(); +} diff --git a/tests/mpi/collective_min.mpirun=1.output b/tests/mpi/collective_min.mpirun=1.output new file mode 100644 index 0000000000..b28f27fc5b --- /dev/null +++ b/tests/mpi/collective_min.mpirun=1.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 1 1.00000 1.00000 diff --git a/tests/mpi/collective_min.mpirun=10.output b/tests/mpi/collective_min.mpirun=10.output new file mode 100644 index 0000000000..90ff33ea7c --- /dev/null +++ b/tests/mpi/collective_min.mpirun=10.output @@ -0,0 +1,2 @@ + +DEAL:mpi::10 10 10.0000 10.0000 diff --git a/tests/mpi/collective_min.mpirun=4.output b/tests/mpi/collective_min.mpirun=4.output new file mode 100644 index 0000000000..9d561e3472 --- /dev/null +++ b/tests/mpi/collective_min.mpirun=4.output @@ -0,0 +1,2 @@ + +DEAL:mpi::4 4 4.00000 4.00000 diff --git a/tests/mpi/collective_min_array.cc b/tests/mpi/collective_min_array.cc new file mode 100644 index 0000000000..0c51e6b70d --- /dev/null +++ b/tests/mpi/collective_min_array.cc @@ -0,0 +1,67 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2009 - 2015 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check Utilities::MPI::min() for arrays + +#include "../tests.h" +#include +#include +#include + +void test() +{ + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + const unsigned int numprocs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + + unsigned int values[2] = { 1, 2 }; + unsigned int minima[2]; + Utilities::MPI::min (values, + MPI_COMM_WORLD, + minima); + Assert (minima[0] == 1, ExcInternalError()); + Assert (minima[1] == 2, ExcInternalError()); + + if (myid==0) + deallog << minima[0] << ' ' << minima[1] << std::endl; +} + + +int main(int argc, char *argv[]) +{ +#ifdef DEAL_II_WITH_MPI + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, numbers::invalid_unsigned_int); +#else + (void)argc; + (void)argv; + compile_time_error; + +#endif + + if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + deallog.push("mpi"); + test(); + deallog.pop(); + } + else + test(); +} diff --git a/tests/mpi/collective_min_array.mpirun=1.output b/tests/mpi/collective_min_array.mpirun=1.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_array.mpirun=1.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_array.mpirun=10.output b/tests/mpi/collective_min_array.mpirun=10.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_array.mpirun=10.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_array.mpirun=4.output b/tests/mpi/collective_min_array.mpirun=4.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_array.mpirun=4.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_array_in_place.cc b/tests/mpi/collective_min_array_in_place.cc new file mode 100644 index 0000000000..ce893afb15 --- /dev/null +++ b/tests/mpi/collective_min_array_in_place.cc @@ -0,0 +1,66 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2009 - 2015 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check Utilities::MPI::min() for arrays, but with input=output + +#include "../tests.h" +#include +#include +#include + +void test() +{ + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + const unsigned int numprocs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + + unsigned int minima[2] = { 1, 2 }; + Utilities::MPI::min (minima, + MPI_COMM_WORLD, + minima); + Assert (minima[0] == 1, ExcInternalError()); + Assert (minima[1] == 2, ExcInternalError()); + + if (myid==0) + deallog << minima[0] << ' ' << minima[1] << std::endl; +} + + +int main(int argc, char *argv[]) +{ +#ifdef DEAL_II_WITH_MPI + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, numbers::invalid_unsigned_int); +#else + (void)argc; + (void)argv; + compile_time_error; + +#endif + + if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + deallog.push("mpi"); + test(); + deallog.pop(); + } + else + test(); +} diff --git a/tests/mpi/collective_min_array_in_place.mpirun=1.output b/tests/mpi/collective_min_array_in_place.mpirun=1.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_array_in_place.mpirun=1.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_array_in_place.mpirun=10.output b/tests/mpi/collective_min_array_in_place.mpirun=10.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_array_in_place.mpirun=10.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_array_in_place.mpirun=4.output b/tests/mpi/collective_min_array_in_place.mpirun=4.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_array_in_place.mpirun=4.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_vector.cc b/tests/mpi/collective_min_vector.cc new file mode 100644 index 0000000000..f32bc2f700 --- /dev/null +++ b/tests/mpi/collective_min_vector.cc @@ -0,0 +1,68 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2009 - 2015 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check Utilities::MPI::min() for vectors + +#include "../tests.h" +#include +#include +#include + +void test() +{ + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + const unsigned int numprocs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + + unsigned int values_[2] = { 1, 2 }; + std::vector values(&values_[0], &values_[2]); + std::vector output(2); + Utilities::MPI::min (values, + MPI_COMM_WORLD, + output); + Assert (output[0] == 1, ExcInternalError()); + Assert (output[1] == 2, ExcInternalError()); + + if (myid==0) + deallog << output[0] << ' ' << output[1] << std::endl; +} + + +int main(int argc, char *argv[]) +{ +#ifdef DEAL_II_WITH_MPI + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, numbers::invalid_unsigned_int); +#else + (void)argc; + (void)argv; + compile_time_error; + +#endif + + if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + deallog.push("mpi"); + test(); + deallog.pop(); + } + else + test(); +} diff --git a/tests/mpi/collective_min_vector.mpirun=1.output b/tests/mpi/collective_min_vector.mpirun=1.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_vector.mpirun=1.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_vector.mpirun=10.output b/tests/mpi/collective_min_vector.mpirun=10.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_vector.mpirun=10.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_vector.mpirun=4.output b/tests/mpi/collective_min_vector.mpirun=4.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_vector.mpirun=4.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_vector_in_place.cc b/tests/mpi/collective_min_vector_in_place.cc new file mode 100644 index 0000000000..c87c80b9d4 --- /dev/null +++ b/tests/mpi/collective_min_vector_in_place.cc @@ -0,0 +1,67 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2009 - 2015 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check Utilities::MPI::min for vectors, but with input=output + +#include "../tests.h" +#include +#include +#include + +void test() +{ + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + const unsigned int numprocs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + + unsigned int values_[2] = { 1, 2 }; + std::vector inout(&values_[0], &values_[2]); + Utilities::MPI::min (inout, + MPI_COMM_WORLD, + inout); + Assert (inout[0] == 1, ExcInternalError()); + Assert (inout[1] == 2, ExcInternalError()); + + if (myid==0) + deallog << inout[0] << ' ' << inout[1] << std::endl; +} + + +int main(int argc, char *argv[]) +{ +#ifdef DEAL_II_WITH_MPI + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, numbers::invalid_unsigned_int); +#else + (void)argc; + (void)argv; + compile_time_error; + +#endif + + if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + deallog.push("mpi"); + test(); + deallog.pop(); + } + else + test(); +} diff --git a/tests/mpi/collective_min_vector_in_place.mpirun=1.output b/tests/mpi/collective_min_vector_in_place.mpirun=1.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_vector_in_place.mpirun=1.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_vector_in_place.mpirun=10.output b/tests/mpi/collective_min_vector_in_place.mpirun=10.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_vector_in_place.mpirun=10.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 diff --git a/tests/mpi/collective_min_vector_in_place.mpirun=4.output b/tests/mpi/collective_min_vector_in_place.mpirun=4.output new file mode 100644 index 0000000000..6e10373d77 --- /dev/null +++ b/tests/mpi/collective_min_vector_in_place.mpirun=4.output @@ -0,0 +1,2 @@ + +DEAL:mpi::1 2 -- 2.39.5