From 1c1a4281ffd12dfaf93db0422f8c166f0a22b9b5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 7 Jun 2004 19:55:51 +0000 Subject: [PATCH] Work around a problem where we cannot elide zero additions for certain matrices by introducing a traits class for each matrix class. git-svn-id: https://svn.dealii.org/trunk@9402 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/block_matrix_base.h | 8 +++-- .../lac/petsc_parallel_sparse_matrix.h | 30 +++++++++++++++++++ deal.II/lac/include/lac/petsc_sparse_matrix.h | 21 +++++++++++++ deal.II/lac/include/lac/sparse_matrix.h | 20 +++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/deal.II/lac/include/lac/block_matrix_base.h b/deal.II/lac/include/lac/block_matrix_base.h index 831ec6c407..b50cb2e5eb 100644 --- a/deal.II/lac/include/lac/block_matrix_base.h +++ b/deal.II/lac/include/lac/block_matrix_base.h @@ -1180,8 +1180,12 @@ BlockMatrixBase::add (const unsigned int i, const unsigned int j, const value_type value) { - // save some cycles for zero additions - if (value == 0) + // save some cycles for zero additions, but + // only if it is safe for the matrix we are + // working with + if ((MatrixType::Traits::zero_addition_can_be_elided == true) + && + (value == 0)) return; const std::pair diff --git a/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h b/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h index ca64fc6a55..469cb4373f 100644 --- a/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h @@ -75,6 +75,36 @@ namespace PETScWrappers class SparseMatrix : public MatrixBase { public: + /** + * A structure that describes some of + * the traits of this class in terms + * of its run-time behavior. Some + * other classes (such as the block + * matrix classes) that take one or + * other of the matrix classes as its + * template parameters can tune their + * behavior based on the variables in + * this class. + */ + struct Traits + { + /** + * It is not safe to elide + * additions of zeros to + * individual elements of this + * matrix. The reason is that + * additions to the matrix may + * trigger collective operations + * synchronising buffers on + * multiple processes. If an + * addition is elided on one + * process, this may lead to + * other processes hanging in an + * infinite waiting loop. + */ + static const bool zero_addition_can_be_elided = false; + }; + /** * Default constructor. Create an * empty matrix. diff --git a/deal.II/lac/include/lac/petsc_sparse_matrix.h b/deal.II/lac/include/lac/petsc_sparse_matrix.h index 76291d259e..6b54011476 100644 --- a/deal.II/lac/include/lac/petsc_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_sparse_matrix.h @@ -41,6 +41,27 @@ namespace PETScWrappers class SparseMatrix : public MatrixBase { public: + /** + * A structure that describes some of + * the traits of this class in terms of + * its run-time behavior. Some other + * classes (such as the block matrix + * classes) that take one or other of + * the matrix classes as its template + * parameters can tune their behavior + * based on the variables in this + * class. + */ + struct Traits + { + /** + * It is safe to elide additions of + * zeros to individual elements of + * this matrix. + */ + static const bool zero_addition_can_be_elided = true; + }; + /** * Default constructor. Create an empty * matrix. diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index a4f1243ec8..991385d378 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -418,6 +418,26 @@ class SparseMatrix : public virtual Subscriptor typedef internals::SparseMatrixIterators::Iterator iterator; + + /** + * A structure that describes some of the + * traits of this class in terms of its + * run-time behavior. Some other classes + * (such as the block matrix classes) + * that take one or other of the matrix + * classes as its template parameters can + * tune their behavior based on the + * variables in this class. + */ + struct Traits + { + /** + * It is safe to elide additions of + * zeros to individual elements of + * this matrix. + */ + static const bool zero_addition_can_be_elided = true; + }; /** * Constructor; initializes the matrix to -- 2.39.5