]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Some of the infrastructure for parallel vectors.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 23 Mar 2004 19:41:21 +0000 (19:41 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 23 Mar 2004 19:41:21 +0000 (19:41 +0000)
git-svn-id: https://svn.dealii.org/trunk@8849 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/petsc_vector.h
deal.II/lac/include/lac/petsc_vector_base.h
deal.II/lac/source/petsc_vector.cc
deal.II/lac/source/petsc_vector_base.cc

index 185ba6ca69da01a54c43be356082e611c909aa4f..f23a6bae4895848dc0ff95cd936d3709d5629dd8 100644 (file)
@@ -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 <typename number>
   Vector::Vector (const ::Vector<number> &v)
   {
-    create_vector (v.size());
+    Vector::create_vector (v.size());
 
     VectorBase::operator = (v);
   }
index 745bd3e4226d29eea6d07d66c41d12f1ba72c85c..bebc71cf2dab33ab7d9ab3838f5fb995297f60f4 100644 (file)
@@ -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;
   };
 
index 248f3c599c9ce47959008552b859e0ea0621bf83..14794f06573ec2347ca1b079656b0552ac4c8c5c 100644 (file)
@@ -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);
index e0b3ef4c4b0727e40199078e37a0b98efe95a405..bf7919c8aa43ed9323a6cb92c5c30f373fab82d3 100644 (file)
@@ -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
   {

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.