From: prill Date: Mon, 16 Jul 2007 05:55:14 +0000 (+0000) Subject: Restored VectorBase::set and introduced a collective add function. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd149e5ec6fb7c14d708a47ef0c09ea1a970f7f0;p=dealii-svn.git Restored VectorBase::set and introduced a collective add function. git-svn-id: https://svn.dealii.org/trunk@14856 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/petsc_vector_base.h b/deal.II/lac/include/lac/petsc_vector_base.h index 79a69eada8..66579a3fe2 100644 --- a/deal.II/lac/include/lac/petsc_vector_base.h +++ b/deal.II/lac/include/lac/petsc_vector_base.h @@ -370,12 +370,18 @@ namespace PETScWrappers * are stated in the first argument, * the corresponding values in the * second. - * If the flag @p add_values is true, - * the values are added to the vector. */ void set (const std::vector &indices, - const std::vector &values, - const bool add_values = false); + const std::vector &values); + + /** + * A collective add operation: This + * function adds a whole set of values + * stored in @p values to the vector + * components specified by @p indices. + */ + void add (const std::vector &indices, + const std::vector &values); /** * Return the scalar product of two @@ -677,6 +683,18 @@ namespace PETScWrappers * Make the reference class a friend. */ friend class internal::VectorReference; + + /** + * Collective set or add + * operation: This function is + * invoked by the collective @p + * set and @p add with the + * @add_values flag set to the + * corresponding value. + */ + void do_set_add_operation (const std::vector &indices, + const std::vector &values, + const bool add_values); }; diff --git a/deal.II/lac/source/petsc_vector_base.cc b/deal.II/lac/source/petsc_vector_base.cc index f9260ec675..2878a49d27 100644 --- a/deal.II/lac/source/petsc_vector_base.cc +++ b/deal.II/lac/source/petsc_vector_base.cc @@ -216,51 +216,18 @@ namespace PETScWrappers void VectorBase::set (const std::vector &indices, - const std::vector &values, - const bool add_values) + const std::vector &values) { - Assert (indices.size() == values.size(), - ExcMessage ("Function called with arguments of different sizes")); + do_set_add_operation(indices, values, false); + } - if (last_action != VectorBase::LastAction::insert) - { - int ierr; - ierr = VecAssemblyBegin (vector); - AssertThrow (ierr == 0, ExcPETScError(ierr)); - ierr = VecAssemblyEnd (vector); - AssertThrow (ierr == 0, ExcPETScError(ierr)); - } - // VecSetValues complains if we - // come with an empty - // vector. however, it is not a - // collective operation, so we - // can skip the call if necessary - // (unlike the above calls) - if (indices.size() != 0) - { -#if (PETSC_VERSION_MAJOR <= 2) && \ - ((PETSC_VERSION_MINOR < 2) || \ - ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) - const std::vector petsc_indices (indices.begin(), - indices.end()); -#else - const std::vector petsc_indices (indices.begin(), - indices.end()); -#endif - - InsertMode mode = INSERT_VALUES; - if (add_values) - mode = ADD_VALUES; - const int ierr - = VecSetValues (vector, indices.size(), - &petsc_indices[0], &values[0], - mode); - AssertThrow (ierr == 0, ExcPETScError(ierr)); - } - - last_action = LastAction::insert; + void + VectorBase::add (const std::vector &indices, + const std::vector &values) + { + do_set_add_operation(indices, values, true); } @@ -879,6 +846,57 @@ namespace PETScWrappers { return vector; } + + + + void + VectorBase::do_set_add_operation (const std::vector &indices, + const std::vector &values, + const bool add_values) + { + Assert (indices.size() == values.size(), + ExcMessage ("Function called with arguments of different sizes")); + + if (last_action != VectorBase::LastAction::insert) + { + int ierr; + ierr = VecAssemblyBegin (vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = VecAssemblyEnd (vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + + // VecSetValues complains if we + // come with an empty + // vector. however, it is not a + // collective operation, so we + // can skip the call if necessary + // (unlike the above calls) + if (indices.size() != 0) + { +#if (PETSC_VERSION_MAJOR <= 2) && \ + ((PETSC_VERSION_MINOR < 2) || \ + ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) + const std::vector petsc_indices (indices.begin(), + indices.end()); +#else + const std::vector petsc_indices (indices.begin(), + indices.end()); +#endif + + InsertMode mode = INSERT_VALUES; + if (add_values) + mode = ADD_VALUES; + const int ierr + = VecSetValues (vector, indices.size(), + &petsc_indices[0], &values[0], + mode); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + + last_action = LastAction::insert; + } }