From: Martin Kronbichler Date: Thu, 19 Oct 2017 12:32:37 +0000 (+0200) Subject: Add tests for the reduced MPI communication. X-Git-Tag: v9.0.0-rc1~933^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F5259%2Fhead;p=dealii.git Add tests for the reduced MPI communication. --- diff --git a/tests/mpi/parallel_partitioner_06.cc b/tests/mpi/parallel_partitioner_06.cc new file mode 100644 index 0000000000..71ba96fd45 --- /dev/null +++ b/tests/mpi/parallel_partitioner_06.cc @@ -0,0 +1,170 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 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. +// +// --------------------------------------------------------------------- + + +// test for the Partitioner with a smaller ghost index set within a larger one +// regarding the export_to_ghosted_array() calls +#include "../tests.h" +#include +#include +#include +#include +#include +#include + + +void test () +{ + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + unsigned int numproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + Assert(numproc > 2, ExcNotImplemented()); + + const unsigned int set = 200; + AssertIndexRange (numproc, set-2); + const unsigned int local_size = set - myid; + types::global_dof_index global_size = 0; + types::global_dof_index my_start = 0; + for (unsigned int i=0; i 0) + local_relevant_1.add_range(my_start-10, my_start); + if (myid < numproc - 1) + local_relevant_1.add_range(my_start+local_size, my_start+local_size+10); + + local_relevant_2 = local_owned; + local_relevant_2.add_indices (&ghost_indices[0], ghost_indices+10); + if (myid > 0) + local_relevant_2.add_index(my_start-10); + if (myid < numproc - 1) + local_relevant_2.add_index(my_start+local_size+9); + + Utilities::MPI::Partitioner v(local_owned, local_relevant_1, MPI_COMM_WORLD); + Utilities::MPI::Partitioner w(local_owned, MPI_COMM_WORLD); + w.set_ghost_indices(local_relevant_2, v.ghost_indices()); + + IndexSet local_relevant_3(global_size); + local_relevant_3.add_index(2); + if (myid > 0 < my_start) + local_relevant_3.add_range(my_start-10, my_start); + Utilities::MPI::Partitioner x(local_owned, MPI_COMM_WORLD); + x.set_ghost_indices(local_relevant_3, v.ghost_indices()); + + // set up a locally owned array with some entries + std::vector locally_owned_data_field(local_size); + for (unsigned int i=0; i &locally_owned_data(locally_owned_data_field); + + // set up a ghost array + std::vector ghosts(v.n_ghost_indices()); + std::vector temp_array(v.n_import_indices()); + std::vector requests; + + // send the full array + v.export_to_ghosted_array_start(3, + make_array_view(locally_owned_data), + make_array_view(temp_array), + make_array_view(ghosts), + requests); + v.export_to_ghosted_array_finish(make_array_view(ghosts), requests); + deallog << "All ghosts: "; + for (unsigned int i=0; i temp_array2(x.n_import_indices()); + std::vector ghosts2(x.n_ghost_indices()); + + std::vector requests2; + x.export_to_ghosted_array_start(4, + make_array_view(locally_owned_data), + make_array_view(temp_array2), + make_array_view(ghosts2), + requests2); + + w.export_to_ghosted_array_finish(make_array_view(ghosts), requests); + deallog << "Ghosts on reduced 1: "; + for (unsigned int i=0; i +#include +#include +#include +#include +#include + + +void test () +{ + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + unsigned int numproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + Assert(numproc > 2, ExcNotImplemented()); + + const unsigned int set = 50; + AssertIndexRange (numproc, set-2); + const unsigned int local_size = set - myid; + types::global_dof_index global_size = 0; + types::global_dof_index my_start = 0; + for (unsigned int i=0; i 0) + local_relevant_1.add_range(my_start-10, my_start); + if (myid < numproc - 1) + local_relevant_1.add_range(my_start+local_size, my_start+local_size+10); + + local_relevant_2 = local_owned; + local_relevant_2.add_indices (&ghost_indices[0], ghost_indices+10); + if (myid > 0) + local_relevant_2.add_index(my_start-10); + if (myid < numproc - 1) + local_relevant_2.add_index(my_start+local_size+9); + + Utilities::MPI::Partitioner v(local_owned, local_relevant_1, MPI_COMM_WORLD); + Utilities::MPI::Partitioner w(local_owned, MPI_COMM_WORLD); + w.set_ghost_indices(local_relevant_2, v.ghost_indices()); + + IndexSet local_relevant_3(global_size); + local_relevant_3.add_index(2); + if (myid > 0 < my_start) + local_relevant_3.add_range(my_start-10, my_start); + Utilities::MPI::Partitioner x(local_owned, MPI_COMM_WORLD); + x.set_ghost_indices(local_relevant_3, v.ghost_indices()); + + // set up a ghost array with some entries + std::vector ghost_array(v.n_ghost_indices(), 1); + + // set up other arrays + std::vector locally_owned_array(local_size); + std::vector temp_array(v.n_import_indices()); + std::vector requests; + + // send the full array + { + std::vector ghosts (ghost_array); + v.import_from_ghosted_array_start(VectorOperation::add, 3, + make_array_view(ghosts), + make_array_view(temp_array), + requests); + v.import_from_ghosted_array_finish(VectorOperation::add, + ArrayView(temp_array.data(), + temp_array.size()), + make_array_view(locally_owned_array), + make_array_view(ghosts), requests); + } + deallog << "From all ghosts: "; + for (unsigned int i=0; i ghosts (ghost_array); + w.import_from_ghosted_array_start(VectorOperation::add, 3, + make_array_view(ghosts), + make_array_view(temp_array), + requests); + w.import_from_ghosted_array_finish(VectorOperation::add, + ArrayView(temp_array.data(), + temp_array.size()), + make_array_view(locally_owned_array), + make_array_view(ghosts), requests); + } + deallog << "From reduced ghosts 1: "; + for (unsigned int i=0; i ghosts (ghost_array); + x.import_from_ghosted_array_start(VectorOperation::add, 3, + make_array_view(ghosts), + make_array_view(temp_array), + requests); + x.import_from_ghosted_array_finish(VectorOperation::add, + ArrayView(temp_array.data(), + temp_array.size()), + make_array_view(locally_owned_array), + make_array_view(ghosts), requests); + } + deallog << "From reduced ghosts 2: "; + for (unsigned int i=0; i ghosts(x.n_ghost_indices(), 1); + x.import_from_ghosted_array_start(VectorOperation::add, 3, + make_array_view(ghosts), + make_array_view(temp_array), + requests); + x.import_from_ghosted_array_finish(VectorOperation::add, + ArrayView(temp_array.data(), + temp_array.size()), + make_array_view(locally_owned_array), + make_array_view(ghosts), requests); + deallog << "From tight reduced ghosts 2: "; + for (unsigned int i=0; i