From 197005326cf815adbde30aabfb8430e40e0b5273 Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 24 Mar 2004 23:24:14 +0000 Subject: [PATCH] Various small bug fixes etc. git-svn-id: https://svn.dealii.org/trunk@8869 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/petsc_vector.h | 49 +++++++++++++++++++-- deal.II/lac/source/petsc_parallel_vector.cc | 2 +- deal.II/lac/source/petsc_vector.cc | 20 +++++++-- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/deal.II/lac/include/lac/petsc_vector.h b/deal.II/lac/include/lac/petsc_vector.h index 65f0822a5c..6ccee550b5 100644 --- a/deal.II/lac/include/lac/petsc_vector.h +++ b/deal.II/lac/include/lac/petsc_vector.h @@ -22,6 +22,7 @@ #ifdef DEAL_II_USE_PETSC #include +#include namespace PETScWrappers @@ -72,11 +73,16 @@ namespace PETScWrappers explicit Vector (const ::Vector &v); /** - * Copy-constructor the - * values from a PETSc wrapper vector - * class. + * Copy-constructor the values from a + * PETSc wrapper vector class. */ - explicit Vector (const VectorBase &v); + explicit Vector (const Vector &v); + + /** + * Copy-constructor the values from a + * PETSc wrapper parallel vector class. + */ + explicit Vector (const MPI::Vector &v); /** * Copy the given vector. Resize the @@ -84,6 +90,21 @@ namespace PETScWrappers */ Vector & operator = (const Vector &v); + /** + * Copy all the elements of the + * parallel vector @arg v into this + * local vector. Note that due to the + * communication model of MPI, @em all + * processes have to actually perform + * this operation, even if they do not + * use the result. It is not sufficient + * if only one processor tries to copy + * the elements from the other + * processors over to its own process + * space. + */ + Vector & operator = (const MPI::Vector &v); + /** * Set all components of the vector to * the given number @p{s}. Simply pass @@ -190,6 +211,26 @@ namespace PETScWrappers + inline + Vector & + Vector::operator = (const MPI::Vector &v) + { + // the petsc function we call wants to + // generate the vector itself, so destroy + // the old one first + int ierr = VecDestroy (vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + // then do the gather operation + ierr = VecConvertMPIToSeqAll (static_cast(v), + &vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + return *this; + } + + + template inline Vector & diff --git a/deal.II/lac/source/petsc_parallel_vector.cc b/deal.II/lac/source/petsc_parallel_vector.cc index 9d6b77abba..89e24bb5d7 100644 --- a/deal.II/lac/source/petsc_parallel_vector.cc +++ b/deal.II/lac/source/petsc_parallel_vector.cc @@ -112,7 +112,7 @@ namespace PETScWrappers Vector::create_vector (const unsigned int n, const unsigned int local_size) { - Assert (local_size < n, ExcIndexRange (local_size, 0, n)); + Assert (local_size <= n, ExcIndexRange (local_size, 0, n)); const int ierr = VecCreateMPI (PETSC_COMM_SELF, local_size, n, &vector); diff --git a/deal.II/lac/source/petsc_vector.cc b/deal.II/lac/source/petsc_vector.cc index 29633938dd..a61c1387df 100644 --- a/deal.II/lac/source/petsc_vector.cc +++ b/deal.II/lac/source/petsc_vector.cc @@ -37,10 +37,24 @@ namespace PETScWrappers - Vector::Vector (const VectorBase &v) + Vector::Vector (const Vector &v) + : + VectorBase () { - Vector::create_vector (v.size()); - VectorBase::operator = (v); + // first create a dummy vector, then copy + // over the other one + Vector::create_vector (1); + Vector::operator = (v); + } + + + + Vector::Vector (const MPI::Vector &v) + { + // first create a dummy vector, then copy + // over the other one + Vector::create_vector (1); + Vector::operator = (v); } -- 2.39.5