From 24da324a4fbd71b0f2b2e6d83b2ae9690d861e3e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 23 Mar 2004 19:41:21 +0000 Subject: [PATCH] Some of the infrastructure for parallel vectors. git-svn-id: https://svn.dealii.org/trunk@8849 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/petsc_vector.h | 13 +++++--- deal.II/lac/include/lac/petsc_vector_base.h | 35 +++++++++++++++------ deal.II/lac/source/petsc_vector.cc | 17 +++------- deal.II/lac/source/petsc_vector_base.cc | 14 +++++++++ 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/deal.II/lac/include/lac/petsc_vector.h b/deal.II/lac/include/lac/petsc_vector.h index 185ba6ca69..f23a6bae48 100644 --- a/deal.II/lac/include/lac/petsc_vector.h +++ b/deal.II/lac/include/lac/petsc_vector.h @@ -101,11 +101,16 @@ namespace PETScWrappers protected: /** * Create a vector of length @p{n}. For - * this class, we create a sequential + * this class, we create a parallel * vector. @arg n denotes the total - * size of the vector to be created. + * size of the vector to be + * created. @arg local_size denotes how + * many of these elements shall be + * stored locally. The last argument is + * ignored for sequential vectors. */ - virtual void create_vector (const unsigned int n); + virtual void create_vector (const unsigned int n, + const unsigned int local_size = 0); }; @@ -116,7 +121,7 @@ namespace PETScWrappers template Vector::Vector (const ::Vector &v) { - create_vector (v.size()); + Vector::create_vector (v.size()); VectorBase::operator = (v); } diff --git a/deal.II/lac/include/lac/petsc_vector_base.h b/deal.II/lac/include/lac/petsc_vector_base.h index 745bd3e422..bebc71cf2d 100644 --- a/deal.II/lac/include/lac/petsc_vector_base.h +++ b/deal.II/lac/include/lac/petsc_vector_base.h @@ -293,10 +293,21 @@ namespace PETScWrappers bool operator != (const VectorBase &v) const; /** - * Return dimension of the vector. + * Return the global dimension of the vector. */ unsigned int size () const; + /** + * Return the local dimension of the + * vector, i.e. the number of elements + * stored on the present MPI + * process. For sequential vectors, + * this number is the same as size(), + * but for parallel vectors it may be + * smaller. + */ + unsigned int local_size () const; + /** * Provide access to a given element, * both read and write. @@ -617,15 +628,21 @@ namespace PETScWrappers mutable LastAction::Values last_action; /** - * Create a vector of length - * @p{n}. Derived classes have to - * overload this function according to - * the type of vector they create - * (e.g. sequential or - * parallel/distributed vectors). + * Create a vector of length @p{n}. For + * this class, we create a parallel + * vector. @arg n denotes the total + * size of the vector to be + * created. @arg local_size denotes how + * many of these elements shall be + * stored locally. The last argument is + * ignored for sequential vectors. + */ + virtual void create_vector (const unsigned int n, + const unsigned int local_size = 0) = 0; + + /** + * Make the reference class a friend. */ - virtual void create_vector (const unsigned int n) = 0; - friend class internal::VectorReference; }; diff --git a/deal.II/lac/source/petsc_vector.cc b/deal.II/lac/source/petsc_vector.cc index 248f3c599c..14794f0657 100644 --- a/deal.II/lac/source/petsc_vector.cc +++ b/deal.II/lac/source/petsc_vector.cc @@ -25,35 +25,28 @@ namespace PETScWrappers Vector::Vector () { - const int n = 0; - const int ierr - = VecCreateSeq (PETSC_COMM_SELF, n, &vector); - AssertThrow (ierr == 0, ExcPETScError(ierr)); + Vector::create_vector (0); } Vector::Vector (const unsigned int n) { - const int ierr - = VecCreateSeq (PETSC_COMM_SELF, n, &vector); - AssertThrow (ierr == 0, ExcPETScError(ierr)); + Vector::create_vector (n); } Vector::Vector (const VectorBase &v) { - int ierr - = VecCreateSeq (PETSC_COMM_SELF, v.size(), &vector); - AssertThrow (ierr == 0, ExcPETScError(ierr)); - + Vector::create_vector (v.size()); VectorBase::operator = (v); } void - Vector::create_vector (const unsigned int n) + Vector::create_vector (const unsigned int n, + const unsigned int /*local_size*/) { const int ierr = VecCreateSeq (PETSC_COMM_SELF, n, &vector); diff --git a/deal.II/lac/source/petsc_vector_base.cc b/deal.II/lac/source/petsc_vector_base.cc index e0b3ef4c4b..bf7919c8aa 100644 --- a/deal.II/lac/source/petsc_vector_base.cc +++ b/deal.II/lac/source/petsc_vector_base.cc @@ -140,6 +140,7 @@ namespace PETScWrappers } + bool VectorBase::operator != (const VectorBase &v) const { @@ -155,6 +156,7 @@ namespace PETScWrappers } + unsigned int VectorBase::size () const { @@ -167,6 +169,18 @@ namespace PETScWrappers + unsigned int + VectorBase::local_size () const + { + int sz; + const int ierr = VecGetLocalSize (vector, &sz); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + return sz; + } + + + PetscScalar VectorBase::operator * (const VectorBase &vec) const { -- 2.39.5