From 7be3b847464c0435480a003ed85e3ffa9cd2b96c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 28 Apr 2021 12:59:00 -0600 Subject: [PATCH] Add test. --- tests/base/aligned_vector_replicate_05.cc | 106 ++++++++++++++++++ ...ligned_vector_replicate_05.mpirun=3.output | 8 ++ 2 files changed, 114 insertions(+) create mode 100644 tests/base/aligned_vector_replicate_05.cc create mode 100644 tests/base/aligned_vector_replicate_05.mpirun=3.output diff --git a/tests/base/aligned_vector_replicate_05.cc b/tests/base/aligned_vector_replicate_05.cc new file mode 100644 index 0000000000..375b215265 --- /dev/null +++ b/tests/base/aligned_vector_replicate_05.cc @@ -0,0 +1,106 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2012 - 2018 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 AlignedVector::replicate_across_communicator(). +// +// Check that all objects are correctly created/destroyed again. + +#include +#include + +#include "../tests.h" + + +int object_number = 0; +int objects_destroyed = 0; + +class C +{ +public: + C() + { + object_number = ::object_number++; + deallog << "Default constructor. Object number " << object_number + << std::endl; + } + + C(const C &c) + { + object_number = ::object_number++; + deallog << "copy constructor from " << c.object_number << ". Object number " + << object_number << std::endl; + } + + C(const C &&c) + { + object_number = ::object_number++; + deallog << "move constructor from " << c.object_number << ". Object number " + << object_number << std::endl; + } + + ~C() + { + deallog << "destructor. Object number " << object_number << std::endl; + ++objects_destroyed; + } + + template + void + serialize(Archive &ar, const unsigned int) + { + ar &object_number; + } + + +private: + unsigned int object_number; +}; + + + +void +test() +{ + const MPI_Comm communicator = MPI_COMM_WORLD; + const unsigned int root = 1; + Assert(root < Utilities::MPI::n_mpi_processes(communicator), + ExcInternalError()); + + // Create an object of nonzero size and then replicate it. + AlignedVector avec(Utilities::MPI::this_mpi_process(communicator)); + + deallog << "On process " << Utilities::MPI::this_mpi_process(communicator) + << ": Replicating..." << std::endl; + + avec.replicate_across_communicator(communicator, root); + + deallog << "On process " << Utilities::MPI::this_mpi_process(communicator) + << ": Going out of scope" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll all; + + test(); + + deallog << "Objects created: " << object_number << std::endl; + deallog << "Objects destroyed: " << objects_destroyed << std::endl; +} diff --git a/tests/base/aligned_vector_replicate_05.mpirun=3.output b/tests/base/aligned_vector_replicate_05.mpirun=3.output new file mode 100644 index 0000000000..e4fe2b2111 --- /dev/null +++ b/tests/base/aligned_vector_replicate_05.mpirun=3.output @@ -0,0 +1,8 @@ + +DEAL:0::On process 0: 0 + +DEAL:1::On process 1: 0 + + +DEAL:2::On process 2: 0 + -- 2.39.5