]> https://gitweb.dealii.org/ - dealii.git/commitdiff
introduce LA::d::Vector::add_local() and sadd_local() to avoid to many communication... 6140/head
authorDenis Davydov <davydden@gmail.com>
Mon, 2 Apr 2018 07:13:05 +0000 (09:13 +0200)
committerDenis Davydov <davydden@gmail.com>
Mon, 2 Apr 2018 07:53:21 +0000 (09:53 +0200)
include/deal.II/lac/la_parallel_block_vector.templates.h
include/deal.II/lac/la_parallel_vector.h
include/deal.II/lac/la_parallel_vector.templates.h

index df6ad24706866e190ed4c22ce8c1b91877bc123e..cb5a2e34b1845a3e0bd093fe77789a51d6728c19 100644 (file)
@@ -944,11 +944,20 @@ namespace LinearAlgebra
           // below we make this work gracefully for identity-like matrices in
           // which case the two loops over j won't do any work as A(j,i)==0
           const unsigned int k = std::min(i,m-1);
-          V.block(i).sadd(s,matrix(k,i)*b, this->block(k));
+          V.block(i).sadd_local(s,matrix(k,i)*b, this->block(k));
           for (unsigned int j = 0  ; j < k; j++)
-            V.block(i).add (matrix(j,i)*b, this->block(j));
+            V.block(i).add_local (matrix(j,i)*b, this->block(j));
           for (unsigned int j = k+1; j < m; j++)
-            V.block(i).add (matrix(j,i)*b, this->block(j));
+            V.block(i).add_local (matrix(j,i)*b, this->block(j));
+        }
+
+      if (V.block(0).vector_is_ghosted)
+        {
+          for (unsigned int i = 0; i < n; i++)
+            Assert (V.block(i).vector_is_ghosted,
+                    ExcMessage("All blocks should be either in ghosted state or not."));
+
+          V.update_ghost_values();
         }
     }
 
index ec5b5677ca5f1667fd795e7f222be7ffb658ee10..00179449cf5c00f56c6519661a4156e004d9a351 100644 (file)
@@ -1060,6 +1060,20 @@ namespace LinearAlgebra
                       << "that this vector can access.");
 
     private:
+
+      /**
+       * Simple addition of a multiple of a vector, i.e. <tt>*this += a*V</tt>
+       * without MPI communication.
+       */
+      void add_local(const Number a, const VectorSpaceVector<Number> &V);
+
+      /**
+       * Scaling and simple addition of a multiple of a vector, i.e. <tt>*this =
+       * s*(*this)+a*V</tt> without MPI communication.
+       */
+      void sadd_local(const Number s, const Number a,
+                      const VectorSpaceVector<Number> &V);
+
       /**
        * Local part of all_zero().
        */
index 6a1a0c53f9eb0717e7e3fcd8b0c29624c86bc2d9..d9ba0a662189800368f4b288614ea05f08db5ef3 100644 (file)
@@ -839,8 +839,8 @@ namespace LinearAlgebra
 
     template <typename Number>
     void
-    Vector<Number>::add (const Number a,
-                         const VectorSpaceVector<Number> &vv)
+    Vector<Number>::add_local (const Number a,
+                               const VectorSpaceVector<Number> &vv)
     {
       // Downcast. Throws an exception if invalid.
       Assert(dynamic_cast<const Vector<Number> *>(&vv)!=nullptr,
@@ -857,6 +857,16 @@ namespace LinearAlgebra
       internal::VectorOperations::Vectorization_add_av<Number> vector_add(values.get(), v.values.get(), a);
       internal::VectorOperations::parallel_for(vector_add, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
+    }
+
+
+
+    template <typename Number>
+    void
+    Vector<Number>::add (const Number a,
+                         const VectorSpaceVector<Number> &vv)
+    {
+      add_local(a,vv);
 
       if (vector_is_ghosted)
         update_ghost_values();
@@ -930,9 +940,9 @@ namespace LinearAlgebra
 
     template <typename Number>
     void
-    Vector<Number>::sadd (const Number x,
-                          const Number a,
-                          const VectorSpaceVector<Number> &vv)
+    Vector<Number>::sadd_local (const Number x,
+                                const Number a,
+                                const VectorSpaceVector<Number> &vv)
     {
       // Downcast. Throws an exception if invalid.
       Assert(dynamic_cast<const Vector<Number> *>(&vv)!=nullptr,
@@ -946,6 +956,17 @@ namespace LinearAlgebra
       internal::VectorOperations::Vectorization_sadd_xav<Number> vector_sadd(values.get(), v.values.get(), a, x);
       internal::VectorOperations::parallel_for(vector_sadd, 0, partitioner->local_size(),
                                                thread_loop_partitioner);
+    }
+
+
+
+    template <typename Number>
+    void
+    Vector<Number>::sadd (const Number x,
+                          const Number a,
+                          const VectorSpaceVector<Number> &vv)
+    {
+      sadd_local(x,a,vv);
 
       if (vector_is_ghosted)
         update_ghost_values();

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.