From: Wolfgang Bangerth Date: Tue, 11 May 2021 22:35:54 +0000 (-0600) Subject: Add a test. X-Git-Tag: v9.3.0-rc1~23^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db9600036a02dbdf22bccdfd078f5615c9fd7945;p=dealii.git Add a test. --- diff --git a/tests/base/aligned_vector_replicate_lifetime.cc b/tests/base/aligned_vector_replicate_lifetime.cc new file mode 100644 index 0000000000..66da4c7304 --- /dev/null +++ b/tests/base/aligned_vector_replicate_lifetime.cc @@ -0,0 +1,109 @@ +// --------------------------------------------------------------------- +// +// 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 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()); + + deallog << "*** On process " << Utilities::MPI::this_mpi_process(communicator) + << ": Starting up..." << std::endl; + + // 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_lifetime.mpirun=3.output b/tests/base/aligned_vector_replicate_lifetime.mpirun=3.output new file mode 100644 index 0000000000..85bfe7c317 --- /dev/null +++ b/tests/base/aligned_vector_replicate_lifetime.mpirun=3.output @@ -0,0 +1,36 @@ + +DEAL:0::*** On process 0: Starting up... +DEAL:0::Default constructor. Object number 0 +DEAL:0::destructor. Object number 0 +DEAL:0::*** On process 0: Replicating... +DEAL:0::*** On process 0: Going out of scope +DEAL:0::Objects created: 1 +DEAL:0::Objects destroyed: 1 + +DEAL:1::*** On process 1: Starting up... +DEAL:1::Default constructor. Object number 0 +DEAL:1::copy constructor from 0. Object number 1 +DEAL:1::destructor. Object number 0 +DEAL:1::*** On process 1: Replicating... +DEAL:1::copy constructor from 1. Object number 2 +DEAL:1::destructor. Object number 2 +DEAL:1::move constructor from 1. Object number 3 +DEAL:1::destructor. Object number 1 +DEAL:1::*** On process 1: Going out of scope +DEAL:1::destructor. Object number 3 +DEAL:1::Objects created: 4 +DEAL:1::Objects destroyed: 4 + + +DEAL:2::*** On process 2: Starting up... +DEAL:2::Default constructor. Object number 0 +DEAL:2::copy constructor from 0. Object number 1 +DEAL:2::copy constructor from 0. Object number 2 +DEAL:2::destructor. Object number 0 +DEAL:2::*** On process 2: Replicating... +DEAL:2::destructor. Object number 2 +DEAL:2::destructor. Object number 1 +DEAL:2::*** On process 2: Going out of scope +DEAL:2::Objects created: 3 +DEAL:2::Objects destroyed: 3 +