From: wolf Date: Sun, 6 Jun 2004 17:35:32 +0000 (+0000) Subject: Reorder some statements so that we can save a few cycles. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=536cd9e37c36a6c34fb2c5ff554cdd2cf5d89a14;p=dealii-svn.git Reorder some statements so that we can save a few cycles. git-svn-id: https://svn.dealii.org/trunk@9387 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/block_matrix_base.h b/deal.II/lac/include/lac/block_matrix_base.h index 99b49b3d64..831ec6c407 100644 --- a/deal.II/lac/include/lac/block_matrix_base.h +++ b/deal.II/lac/include/lac/block_matrix_base.h @@ -1180,6 +1180,10 @@ BlockMatrixBase::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 row_index = row_block_indices.global_to_local (i), col_index = column_block_indices.global_to_local (j); diff --git a/deal.II/lac/include/lac/petsc_vector_base.h b/deal.II/lac/include/lac/petsc_vector_base.h index fa917458dc..89d41f9961 100644 --- a/deal.II/lac/include/lac/petsc_vector_base.h +++ b/deal.II/lac/include/lac/petsc_vector_base.h @@ -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; } diff --git a/deal.II/lac/source/petsc_matrix_base.cc b/deal.II/lac/source/petsc_matrix_base.cc index d8fb80b9c3..f5f17a8334 100644 --- a/deal.II/lac/source/petsc_matrix_base.cc +++ b/deal.II/lac/source/petsc_matrix_base.cc @@ -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; }