From: Wolfgang Bangerth Date: Fri, 8 Jul 2022 03:38:13 +0000 (-0600) Subject: Add a test. X-Git-Tag: v9.5.0-rc1~1056^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=305fe7f61b55b2375bd93759d4e29de63fc70ba2;p=dealii.git Add a test. --- diff --git a/tests/mpi/isend_irecv_01.cc b/tests/mpi/isend_irecv_01.cc new file mode 100644 index 0000000000..f525129324 --- /dev/null +++ b/tests/mpi/isend_irecv_01.cc @@ -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 + +#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> + 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(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> 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 index 0000000000..382990dea6 --- /dev/null +++ b/tests/mpi/isend_irecv_01.mpirun=2.output @@ -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 index 0000000000..94b52047d4 --- /dev/null +++ b/tests/mpi/isend_irecv_01.mpirun=4.output @@ -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. +