From: Denis Davydov Date: Fri, 23 Mar 2018 20:26:04 +0000 (+0100) Subject: doc: give example of Utilities::MPI::Partitioner X-Git-Tag: v9.0.0-rc1~284^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F6095%2Fhead;p=dealii.git doc: give example of Utilities::MPI::Partitioner --- diff --git a/doc/doxygen/images/partitioner.png b/doc/doxygen/images/partitioner.png new file mode 100644 index 0000000000..a4c3534e63 Binary files /dev/null and b/doc/doxygen/images/partitioner.png differ diff --git a/include/deal.II/base/partitioner.h b/include/deal.II/base/partitioner.h index 7dd443a9de..1429531f26 100644 --- a/include/deal.II/base/partitioner.h +++ b/include/deal.II/base/partitioner.h @@ -53,6 +53,14 @@ namespace Utilities * information is gathered once when constructing the partitioner, which * obviates subsequent global communication steps when exchanging data. * + * The figure below gives an example of index space $[0,74)$ being split into + * four processes. + * @image html partitioner.png + * Here process 0 will import 5 DoFs from process 1 (first pair of import targets), + * which corresponds to the first 3 elements of its import indices. Whereas + * process 2 will import 3 DoFs from process 0, which corresponds to the first + * two elements of its import indices. + * * The partitioner includes a mechanism for converting global to local and * local to global indices. Internally, this class stores vector elements * using the convention as follows: The local range is associated with diff --git a/tests/mpi/parallel_partitioner_03b.cc b/tests/mpi/parallel_partitioner_03b.cc new file mode 100644 index 0000000000..80f2187bfa --- /dev/null +++ b/tests/mpi/parallel_partitioner_03b.cc @@ -0,0 +1,144 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2012 - 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. +// +// --------------------------------------------------------------------- + + +// a variation of parallel_partitioner_03, which is used to draw a figure in +// MPI::Partitioner documentation. + +#include "../tests.h" +#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); + + if (myid==0) deallog << "numproc=" << numproc << std::endl; + + const unsigned int set = 20; + AssertIndexRange (numproc, set-2); + const unsigned int local_size = set - myid; + unsigned int global_size = 0; + unsigned int my_start = 0; + for (unsigned int i=0; ighost_indices = {1, 2, 13, set-2, set-1, set, set+1, 2*set, + 2*set+1, 2*set+3 + }; + local_relevant.add_indices (ghost_indices.begin(), ghost_indices.end()); + } + else if (myid==1) + { + std::vectorghost_indices = {1, 2, 13, set-2, set-1, set, set+1, 2*set, + 2*set+1, 2*set+3, 3*set + }; + local_relevant.add_indices (ghost_indices.begin(), ghost_indices.end()); + } + else if (myid==2) + { + std::vector ghost_indices = { set-2, set-1, set, set+1, 2*set, + 2*set+1, 2*set+3 + }; + local_relevant.add_indices (ghost_indices.begin(), ghost_indices.end()); + + } + else + { + std::vectorghost_indices = {1, 2, 13, 2*set+3 + }; + local_relevant.add_indices (ghost_indices.begin(), ghost_indices.end()); + } + + Utilities::MPI::Partitioner v(local_owned, local_relevant, MPI_COMM_WORLD); + + // write the info on ghost processors and import indices to file + { + std::ofstream file((std::string("dat.") + Utilities::int_to_string(myid)).c_str()); + file << "**** proc " << myid << std::endl; + file << "owned:" << std::endl; + local_owned.print(file); + file <<"relevant:" << std::endl; + local_relevant.print(file); + file << "ghost targets: "; + for (unsigned int i=0; i