From: Timo Heister Date: Sat, 12 Feb 2022 22:32:51 +0000 (-0500) Subject: add test X-Git-Tag: v9.4.0-rc1~488^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e93c8f46af5dcc13b4198a08e4206c24edc295f;p=dealii.git add test --- diff --git a/tests/mpi/broadcast_02.cc b/tests/mpi/broadcast_02.cc new file mode 100644 index 0000000000..0f461da41b --- /dev/null +++ b/tests/mpi/broadcast_02.cc @@ -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 + +#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 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 index 0000000000..a168662560 --- /dev/null +++ b/tests/mpi/broadcast_02.mpirun=3.output @@ -0,0 +1,11 @@ + +DEAL:0::OK +DEAL:0::OK + +DEAL:1::OK +DEAL:1::OK + + +DEAL:2::OK +DEAL:2::OK +