From: kronbichler Date: Mon, 21 Sep 2009 07:22:01 +0000 (+0000) Subject: Fix PETSc problem with my previous commit. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfbfd7e748d19b89f64429d087bd49ddbcce62e5;p=dealii-svn.git Fix PETSc problem with my previous commit. git-svn-id: https://svn.dealii.org/trunk@19484 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 b2f920801f..e4be758cda 100644 --- a/deal.II/lac/include/lac/petsc_vector_base.h +++ b/deal.II/lac/include/lac/petsc_vector_base.h @@ -384,6 +384,29 @@ namespace PETScWrappers void add (const std::vector &indices, const std::vector &values); + /** + * This is a second collective + * add operation. As a + * difference, this function + * takes a deal.II vector of + * values. + */ + void add (const std::vector &indices, + const ::dealii::Vector &values); + + /** + * Take an address where + * n_elements are stored + * contiguously and add them into + * the vector. Handles all cases + * which are not covered by the + * other two add() + * functions above. + */ + void add (const unsigned int n_elements, + const unsigned int *indices, + const PetscScalar *values); + /** * Return the scalar product of two * vectors. The vectors must have the @@ -734,8 +757,9 @@ namespace PETScWrappers * @p add_values flag set to the * corresponding value. */ - void do_set_add_operation (const std::vector &indices, - const std::vector &values, + void do_set_add_operation (const unsigned int n_elements, + const unsigned int *indices, + const PetscScalar *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 a359b72f87..ea4d9575b8 100644 --- a/deal.II/lac/source/petsc_vector_base.cc +++ b/deal.II/lac/source/petsc_vector_base.cc @@ -218,7 +218,9 @@ namespace PETScWrappers VectorBase::set (const std::vector &indices, const std::vector &values) { - do_set_add_operation(indices, values, false); + Assert (indices.size() == values.size(), + ExcMessage ("Function called with arguments of different sizes")); + do_set_add_operation(indices.size(), &indices[0], &values[0], false); } @@ -227,7 +229,32 @@ namespace PETScWrappers VectorBase::add (const std::vector &indices, const std::vector &values) { - do_set_add_operation(indices, values, true); + Assert (indices.size() == values.size(), + ExcMessage ("Function called with arguments of different sizes")); + do_set_add_operation(indices.size(), &indices[0], &values[0], true); + } + + + + void + VectorBase::add (const std::vector &indices, + const ::dealii::Vector&values) + { + Assert (indices.size() == values.size(), + ExcMessage ("Function called with arguments of different sizes")); + do_set_add_operation(indices.size(), &indices[0], + &(*const_cast*>(&values))(0), + true); + } + + + + void + VectorBase::add (const unsigned int n_elements, + const unsigned int *indices, + const PetscScalar *values) + { + do_set_add_operation(n_elements, indices, values, true); } @@ -940,13 +967,11 @@ namespace PETScWrappers void - VectorBase::do_set_add_operation (const std::vector &indices, - const std::vector &values, - const bool add_values) + VectorBase::do_set_add_operation (const unsigned int n_elements, + const unsigned int *indices, + const PetscScalar *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; @@ -963,24 +988,24 @@ namespace PETScWrappers // collective operation, so we // can skip the call if necessary // (unlike the above calls) - if (indices.size() != 0) + if (n_elements != 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()); +#if (PETSC_VERSION_MAJOR <= 2) && \ + ((PETSC_VERSION_MINOR < 2) || \ + ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) + const int * petsc_indices = indices; #else - const std::vector petsc_indices (indices.begin(), - indices.end()); + std::vector petsc_ind (n_elements); + for (unsigned int i=0; i