#ifdef DEAL_II_USE_PETSC
#include <lac/petsc_vector_base.h>
+#include <lac/petsc_parallel_vector.h>
namespace PETScWrappers
explicit Vector (const ::Vector<Number> &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
*/
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
+ 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<const Vec &>(v),
+ &vector);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+ return *this;
+ }
+
+
+
template <typename number>
inline
Vector &
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);
- 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);
}