*/
Vector & operator = (const Vector &v);
+ /**
+ * Copy the given sequential
+ * (non-distributed) vector
+ * into the present parallel
+ * vector. It is assumed that
+ * they have the same size,
+ * and this operation does
+ * not change the
+ * partitioning of the
+ * parallel vector by which
+ * its elements are
+ * distributed across several
+ * MPI processes. What this
+ * operation therefore does
+ * is to copy that chunk of
+ * the given vector @p v that
+ * corresponds to elements of
+ * the target vector that are
+ * stored locally, and copies
+ * them. Elements that are
+ * not stored locally are not
+ * touched.
+ *
+ * This being a parallel
+ * vector, you must make sure
+ * that @em all processes
+ * call this function at the
+ * same time. It is not
+ * possible to change the
+ * local part of a parallel
+ * vector on only one
+ * process, independent of
+ * what other processes do,
+ * with this function.
+ */
+ Vector & operator = (const PETScWrappers::Vector &v);
+
/**
* Set all components of the vector to
* the given number @p{s}. Simply pass
#include <lac/petsc_parallel_vector.h>
+#include <lac/petsc_vector.h>
#include <cmath>
+#include <algorithm>
#ifdef DEAL_II_USE_PETSC
reinit (v.size(), v.local_size(), fast);
}
-
+
+
+
+ Vector &
+ Vector::operator = (const PETScWrappers::Vector &v)
+ {
+ int ierr;
+
+ // get a pointer to the local memory of this vector
+ PetscScalar *dest_array;
+ ierr = VecGetArray (vector, &dest_array);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+ // then also a pointer to the source vector
+ PetscScalar *src_array;
+ ierr = VecGetArray (static_cast<const Vec &>(v), &src_array);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+ // then copy:
+ const std::pair<unsigned int, unsigned int> local_elements = local_range ();
+ std::copy (src_array + local_elements.first, src_array + local_elements.second,
+ dest_array);
+
+ // finally restore the arrays
+ ierr = VecRestoreArray (vector, &dest_array);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+ ierr = VecRestoreArray (static_cast<const Vec &>(v), &src_array);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+ return *this;
+ }
void