From 7ef8eb39d04a09d0ace7b9f0aaca377947770c46 Mon Sep 17 00:00:00 2001 From: heister Date: Wed, 4 Sep 2013 17:02:38 +0000 Subject: [PATCH] ghost import for distributed::parallel:BlockVector::operator= and add new constructors git-svn-id: https://svn.dealii.org/trunk@30597 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 9 +++ .../deal.II/lac/parallel_block_vector.h | 63 ++++++++++++++++++- deal.II/include/deal.II/lac/parallel_vector.h | 28 +++++++++ .../deal.II/lac/parallel_vector.templates.h | 18 +++++- 4 files changed, 114 insertions(+), 4 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 9baf5e8c27..5a3549443d 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -68,6 +68,15 @@ inconvenience this causes.

Specific improvements

    +
  1. + Changed: distributed::parallel:BlockVector::operator= now allows importing + of ghost values like all other vector types. Also added some new constructors + for BlockVector and Vector using IndexSets to mirror the other linear algebra + classes. +
    + (Timo Heister, 2013/09/04) +
  2. +
  3. Fixed: VectorTools::compute_no_normal_flux_constraints had a bug that only manifested on complex meshes. This is now fixed. diff --git a/deal.II/include/deal.II/lac/parallel_block_vector.h b/deal.II/include/deal.II/lac/parallel_block_vector.h index d0f5387851..747d12a33e 100644 --- a/deal.II/include/deal.II/lac/parallel_block_vector.h +++ b/deal.II/include/deal.II/lac/parallel_block_vector.h @@ -125,6 +125,20 @@ namespace parallel */ BlockVector (const std::vector &block_sizes); + /** + * Construct a block vector with an IndexSet for the local range + * and ghost entries for each block. + */ + BlockVector (const std::vector &local_ranges, + const std::vector &ghost_indices, + const MPI_Comm communicator); + + /** + * Same as above but the ghost indicies are assumed to be empty. + */ + BlockVector (const std::vector &local_ranges, + const MPI_Comm communicator); + /** * Destructor. Clears memory. */ @@ -356,6 +370,41 @@ namespace parallel } + template + inline + BlockVector::BlockVector (const std::vector &local_ranges, + const std::vector &ghost_indices, + const MPI_Comm communicator) + { + std::vector sizes(local_ranges.size()); + for (unsigned int i=0; iblock_indices.reinit(sizes); + this->components.resize(this->n_blocks()); + + for (unsigned int i=0; in_blocks(); ++i) + this->block(i).reinit(local_ranges[i], ghost_indices[i], communicator); + } + + + template + inline + BlockVector::BlockVector (const std::vector &local_ranges, + const MPI_Comm communicator) + { + std::vector sizes(local_ranges.size()); + for (unsigned int i=0; iblock_indices.reinit(sizes); + this->components.resize(this->n_blocks()); + + for (unsigned int i=0; in_blocks(); ++i) + this->block(i).reinit(local_ranges[i], communicator); + } + + template inline @@ -454,8 +503,18 @@ namespace parallel BlockVector & BlockVector::operator = (const BlockVector &v) { - reinit (v, true); - BaseClass::operator = (v); + // we only allow assignment to vectors with the same number of blocks + // or to an empty BlockVector + Assert (this->n_blocks() == 0 || this->n_blocks() == v.n_blocks(), + ExcDimensionMismatch(this->n_blocks(), v.n_blocks())); + + if (this->n_blocks() != v.n_blocks()) + reinit(v.n_blocks(), true); + + for (size_type i=0; in_blocks(); ++i) + this->components[i] = v.block(i); + + this->collect_sizes(); return *this; } diff --git a/deal.II/include/deal.II/lac/parallel_vector.h b/deal.II/include/deal.II/lac/parallel_vector.h index 6d966154a0..ffea6ae843 100644 --- a/deal.II/include/deal.II/lac/parallel_vector.h +++ b/deal.II/include/deal.II/lac/parallel_vector.h @@ -154,6 +154,12 @@ namespace parallel const IndexSet &ghost_indices, const MPI_Comm communicator); + /** + * Same constructor as above but without any ghost indices. + */ + Vector (const IndexSet &local_range, + const MPI_Comm communicator); + /** * Create the vector based on the parallel partitioning described in @p * partitioner. The input argument is a shared pointer, which store the @@ -204,6 +210,12 @@ namespace parallel const IndexSet &ghost_indices, const MPI_Comm communicator); + /** + * Same as above, but without ghost entries. + */ + void reinit (const IndexSet &local_range, + const MPI_Comm communicator); + /** * Initialize the vector given to the parallel partitioning described in * @p partitioner. The input argument is a shared pointer, which store @@ -1002,6 +1014,22 @@ namespace parallel + template + inline + Vector::Vector (const IndexSet &local_range, + const MPI_Comm communicator) + : + allocated_size (0), + val (0), + import_data (0), + vector_view (0, static_cast(0)) + { + IndexSet ghost_indices(local_range.size()); + reinit (local_range, ghost_indices, communicator); + } + + + template inline Vector::Vector (const size_type size) diff --git a/deal.II/include/deal.II/lac/parallel_vector.templates.h b/deal.II/include/deal.II/lac/parallel_vector.templates.h index 23f0734d03..334966c5f0 100644 --- a/deal.II/include/deal.II/lac/parallel_vector.templates.h +++ b/deal.II/include/deal.II/lac/parallel_vector.templates.h @@ -144,8 +144,22 @@ namespace parallel const IndexSet &ghost_indices, const MPI_Comm communicator) { - // set up parallel partitioner with index sets - // and communicator + // set up parallel partitioner with index sets and communicator + std_cxx1x::shared_ptr new_partitioner + (new Utilities::MPI::Partitioner (locally_owned_indices, + ghost_indices, communicator)); + reinit (new_partitioner); + } + + + + template + void + Vector::reinit (const IndexSet &locally_owned_indices, + const MPI_Comm communicator) + { + // set up parallel partitioner with index sets and communicator + IndexSet ghost_indices(locally_owned_indices.size()); std_cxx1x::shared_ptr new_partitioner (new Utilities::MPI::Partitioner (locally_owned_indices, ghost_indices, communicator)); -- 2.39.5