]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Have a function that copies a sequential into a parallel vector, but only the local...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 16 Apr 2004 20:49:34 +0000 (20:49 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 16 Apr 2004 20:49:34 +0000 (20:49 +0000)
git-svn-id: https://svn.dealii.org/trunk@9030 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/petsc_parallel_vector.h
deal.II/lac/source/petsc_parallel_vector.cc

index 2c3f9bd774bb9acc4b61aa0d369dded74a2e3e12..6eb511a7d0077edb4731ba7d8eec86c9f1658818 100644 (file)
@@ -130,6 +130,43 @@ namespace PETScWrappers
                                           */
         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
index 733190a24615a3a91e2eb826d99c31ab0c4ff361..35491c5bebbb07500adc23248f5ac8a8e7a96fdf 100644 (file)
 
 
 #include <lac/petsc_parallel_vector.h>
+#include <lac/petsc_vector.h>
 
 #include <cmath>
+#include <algorithm>
 
 #ifdef DEAL_II_USE_PETSC
 
@@ -105,7 +107,38 @@ namespace PETScWrappers
       
       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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.