]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Reorder some statements so that we can save a few cycles.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 6 Jun 2004 17:35:32 +0000 (17:35 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 6 Jun 2004 17:35:32 +0000 (17:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@9387 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/block_matrix_base.h
deal.II/lac/include/lac/petsc_vector_base.h
deal.II/lac/source/petsc_matrix_base.cc

index 99b49b3d643036249b82f0c7df6c78569d674134..831ec6c407b8b5651d4678435e578d43084d52b7 100644 (file)
@@ -1180,6 +1180,10 @@ BlockMatrixBase<MatrixType>::add (const unsigned int i,
                                   const unsigned int j,
                                   const value_type value)
 {
+                                   // save some cycles for zero additions
+  if (value == 0)
+    return;
+  
   const std::pair<unsigned int,unsigned int>
     row_index = row_block_indices.global_to_local (i),
     col_index = column_block_indices.global_to_local (j);
index fa917458dcbcb015eec53c6fcb6fd040cdf46535..89d41f996192426d5391b87c3e7faa835f3e8e4d 100644 (file)
@@ -751,16 +751,26 @@ namespace PETScWrappers
 
           ierr = VecAssemblyEnd (vector);
           AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+          vector.last_action = VectorBase::LastAction::add;
         }
-      
-      const signed int petsc_i = index;
 
+                                       // we have to do above actions in any
+                                       // case to be consistent with the MPI
+                                       // communication model (see the
+                                       // comments in the documentation of
+                                       // PETScWrappers::MPI::Vector), but we
+                                       // can save some work if the addend is
+                                       // zero
+      if (value == 0)
+        return *this;
+      
                                        // use the PETSc function to add something
+      const signed int petsc_i = index;
       const int ierr
         = VecSetValues (vector, 1, &petsc_i, &value, ADD_VALUES);
       AssertThrow (ierr == 0, ExcPETScError(ierr));
 
-      vector.last_action = VectorBase::LastAction::add;
       
       return *this;
     }
@@ -779,17 +789,26 @@ namespace PETScWrappers
 
           ierr = VecAssemblyEnd (vector);
           AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+          vector.last_action = VectorBase::LastAction::add;
         }
       
-      const signed int petsc_i = index;
+                                       // we have to do above actions in any
+                                       // case to be consistent with the MPI
+                                       // communication model (see the
+                                       // comments in the documentation of
+                                       // PETScWrappers::MPI::Vector), but we
+                                       // can save some work if the addend is
+                                       // zero
+      if (value == 0)
+        return *this;
 
                                        // use the PETSc function to add something
+      const signed int petsc_i = index;
       const PetscScalar subtractand = -value;
       const int ierr
         = VecSetValues (vector, 1, &petsc_i, &subtractand, ADD_VALUES);
       AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-      vector.last_action = VectorBase::LastAction::add;
       
       return *this;
     }
@@ -808,8 +827,20 @@ namespace PETScWrappers
 
           ierr = VecAssemblyEnd (vector);
           AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+          vector.last_action = VectorBase::LastAction::insert;
         }
       
+                                       // we have to do above actions in any
+                                       // case to be consistent with the MPI
+                                       // communication model (see the
+                                       // comments in the documentation of
+                                       // PETScWrappers::MPI::Vector), but we
+                                       // can save some work if the factor is
+                                       // one
+      if (value == 1.)
+        return *this;
+
       const signed int petsc_i = index;
 
       const PetscScalar new_value
@@ -818,8 +849,6 @@ namespace PETScWrappers
       const int ierr
         = VecSetValues (vector, 1, &petsc_i, &new_value, INSERT_VALUES);
       AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-      vector.last_action = VectorBase::LastAction::insert;
       
       return *this;
     }
@@ -838,8 +867,20 @@ namespace PETScWrappers
 
           ierr = VecAssemblyEnd (vector);
           AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+          vector.last_action = VectorBase::LastAction::insert;
         }
       
+                                       // we have to do above actions in any
+                                       // case to be consistent with the MPI
+                                       // communication model (see the
+                                       // comments in the documentation of
+                                       // PETScWrappers::MPI::Vector), but we
+                                       // can save some work if the factor is
+                                       // one
+      if (value == 1.)
+        return *this;
+
       const signed int petsc_i = index;
 
       const PetscScalar new_value
@@ -848,8 +889,6 @@ namespace PETScWrappers
       const int ierr
         = VecSetValues (vector, 1, &petsc_i, &new_value, INSERT_VALUES);
       AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-      vector.last_action = VectorBase::LastAction::insert;
       
       return *this;
     }
index d8fb80b9c3102a1d8e7d704268a55c29840d81c6..f5f17a83342931787c6382f68ba9a2d2aad1bf07 100644 (file)
@@ -152,8 +152,20 @@ namespace PETScWrappers
 
         ierr = MatAssemblyEnd(matrix,MAT_FLUSH_ASSEMBLY);
         AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+        last_action = LastAction::add;
       }
     
+                                     // we have to do above actions in any
+                                     // case to be consistent with the MPI
+                                     // communication model (see the
+                                     // comments in the documentation of
+                                     // PETScWrappers::MPI::Vector), but we
+                                     // can save some work if the addend is
+                                     // zero
+    if (value == 0)
+      return;
+
     const signed int petsc_i = i;
     const signed int petsc_j = j;
           
@@ -161,8 +173,6 @@ namespace PETScWrappers
       = MatSetValues (matrix, 1, &petsc_i, 1, &petsc_j,
                       &value, ADD_VALUES);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-    last_action = LastAction::add;
   }
 
 

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.