From 28705e015f5e89debc804b9a734db1155dc18a87 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Tue, 24 Oct 2017 12:35:36 +0200 Subject: [PATCH] Introduce LA::d::Vector::copy_locally_owned_data_from. --- include/deal.II/lac/la_parallel_vector.h | 18 ++++++++++++++ .../lac/la_parallel_vector.templates.h | 24 ++++++++++++++++--- source/lac/la_parallel_vector.inst.in | 2 ++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/include/deal.II/lac/la_parallel_vector.h b/include/deal.II/lac/la_parallel_vector.h index e66f0bbf11..4135df1c3a 100644 --- a/include/deal.II/lac/la_parallel_vector.h +++ b/include/deal.II/lac/la_parallel_vector.h @@ -513,6 +513,24 @@ namespace LinearAlgebra * @ref GlossGhostedVector "vectors with ghost elements" */ bool has_ghost_elements() const; + + /** + * This method copies the data in the locally owned range from another + * distributed vector @p src into the calling vector. As opposed to + * operator= that also includes ghost entries, this operation ignores + * the ghost range. The only prerequisite is that the local range on the + * calling vector and the given vector @p src are the same on all + * processors. It is explicitly allowed that the two vectors have + * different ghost elements that might or might not be related to each + * other. + * + * Since no data exchange is performed, make sure that neither @p src + * nor the calling vector have pending communications in order to obtain + * correct results. + */ + template + void copy_locally_owned_data_from(const Vector &src); + //@} /** diff --git a/include/deal.II/lac/la_parallel_vector.templates.h b/include/deal.II/lac/la_parallel_vector.templates.h index 2e65d4e02f..c5734e16a6 100644 --- a/include/deal.II/lac/la_parallel_vector.templates.h +++ b/include/deal.II/lac/la_parallel_vector.templates.h @@ -359,7 +359,7 @@ namespace LinearAlgebra thread_loop_partitioner = c.thread_loop_partitioner; - const size_type this_size = local_size(); + const size_type this_size = partitioner->local_size(); if (this_size>0) { dealii::internal::VectorOperations::Vector_copy copier(c.values.get(), values.get()); @@ -376,6 +376,24 @@ namespace LinearAlgebra + template + template + void + Vector::copy_locally_owned_data_from(const Vector &src) + { + AssertDimension(partitioner->local_size(), src.partitioner->local_size()); + if (partitioner->local_size() > 0) + { + dealii::internal::VectorOperations::Vector_copy copier(src.values.get(), + values.get()); + internal::VectorOperations::parallel_for(copier, 0, partitioner->local_size(), + thread_loop_partitioner); + } + } + + + + #ifdef DEAL_II_WITH_PETSC namespace petsc_helpers @@ -534,6 +552,8 @@ namespace LinearAlgebra Vector::compress_finish (::dealii::VectorOperation::values operation) { #ifdef DEAL_II_WITH_MPI + vector_is_ghosted = false; + if (compress_requests.size() == 0) return; @@ -549,8 +569,6 @@ namespace LinearAlgebra ArrayView(values.get(), partitioner->local_size()), ArrayView(values.get() + partitioner->local_size(),partitioner->n_ghost_indices()), compress_requests); - - vector_is_ghosted = false; #else (void)operation; #endif diff --git a/source/lac/la_parallel_vector.inst.in b/source/lac/la_parallel_vector.inst.in index 21a712093b..cdb4b357b0 100644 --- a/source/lac/la_parallel_vector.inst.in +++ b/source/lac/la_parallel_vector.inst.in @@ -34,6 +34,7 @@ for (S1, S2 : REAL_SCALARS) \{ template void Vector::reinit (const Vector&, const bool); + template void Vector::copy_locally_owned_data_from (const Vector&); template S1 Vector::inner_product_local (const Vector&) const; \} \} @@ -58,6 +59,7 @@ for (S1, S2 : COMPLEX_SCALARS) \{ template void Vector::reinit (const Vector&, const bool); + template void Vector::copy_locally_owned_data_from (const Vector&); \} \} } -- 2.39.5