From 96243c73bad58b0b7e70a4fedc366d13dec2c6fe Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 16 Aug 2016 18:48:42 +0200 Subject: [PATCH] Add a test for the conversion BlockVector->Vector --- include/deal.II/lac/trilinos_vector.h | 4 + source/lac/trilinos_vector.cc | 8 +- tests/mpi/blockvec_02.cc | 73 +++++++++++++++++++ ...kvec_02.with_trilinos=true.mpirun=2.output | 15 ++++ 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 tests/mpi/blockvec_02.cc create mode 100644 tests/mpi/blockvec_02.with_trilinos=true.mpirun=2.output diff --git a/include/deal.II/lac/trilinos_vector.h b/include/deal.II/lac/trilinos_vector.h index 8e57c44931..e2225accc1 100644 --- a/include/deal.II/lac/trilinos_vector.h +++ b/include/deal.II/lac/trilinos_vector.h @@ -583,6 +583,10 @@ namespace TrilinosWrappers * or may not have ghost elements. See the general documentation of this * class for more information. * + * In case @p parallel_partitioning is overlapping, it is not clear which + * process should own which elements. Hence, locally_owned_elements() + * returns an empty IndexSet in this case. + * * @see * @ref GlossGhostedVector "vectors with ghost elements" */ diff --git a/source/lac/trilinos_vector.cc b/source/lac/trilinos_vector.cc index 9ea961c8d1..cfae13069a 100644 --- a/source/lac/trilinos_vector.cc +++ b/source/lac/trilinos_vector.cc @@ -262,10 +262,10 @@ namespace TrilinosWrappers // which process owns what. So we decide that no process // owns anything in that case. if (has_ghosts) - { - owned_elements.clear(); - owned_elements.set_size(parallel_partitioner.size()); - } + { + owned_elements.clear(); + owned_elements.set_size(parallel_partitioner.size()); + } else owned_elements = parallel_partitioner; diff --git a/tests/mpi/blockvec_02.cc b/tests/mpi/blockvec_02.cc new file mode 100644 index 0000000000..4544a49788 --- /dev/null +++ b/tests/mpi/blockvec_02.cc @@ -0,0 +1,73 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2004 - 2015 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 constructor/reinit of BlockVector with IndexSets and the conversion +// to a Vector + +#include "../tests.h" +#include "coarse_grid_common.h" +#include +#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); + + std::vector local_active(2); + + // block 0: + local_active[0].set_size(numproc); + local_active[0].add_range(myid,myid+1); + + local_active[1].set_size(2*numproc); + local_active[1].add_range(myid*2,myid*2+2); + + TrilinosWrappers::MPI::BlockVector v_block(local_active, MPI_COMM_WORLD); + + v_block(myid) = 100.0 + myid; + + v_block.block(1)(myid*2)=myid*2.0; + v_block.block(1)(myid*2+1)=myid*2.0+1.0; + + v_block.compress(VectorOperation::insert); + + deallog << "block size: " << v_block.size() << std::endl; + deallog << "block size[0]: " << v_block.block(0).size() << std::endl; + deallog << "block size[1]: " << v_block.block(1).size() << std::endl; + v_block.locally_owned_elements().print(deallog.get_file_stream()); + + TrilinosWrappers::MPI::Vector v; + v.reinit (v_block); + + deallog << "size: " << v.size() << std::endl; + v.locally_owned_elements().print(deallog.get_file_stream()); +} + + + +int main (int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1); + MPILogInitAll log; + test(); +} diff --git a/tests/mpi/blockvec_02.with_trilinos=true.mpirun=2.output b/tests/mpi/blockvec_02.with_trilinos=true.mpirun=2.output new file mode 100644 index 0000000000..b2bc951de6 --- /dev/null +++ b/tests/mpi/blockvec_02.with_trilinos=true.mpirun=2.output @@ -0,0 +1,15 @@ + +DEAL:0::block size: 6 +DEAL:0::block size[0]: 2 +DEAL:0::block size[1]: 4 +{0, [2,3]} +DEAL:0::size: 6 +{0, [2,3]} + +DEAL:1::block size: 6 +DEAL:1::block size[0]: 2 +DEAL:1::block size[1]: 4 +{1, [4,5]} +DEAL:1::size: 6 +{1, [4,5]} + -- 2.39.5