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<unsigned int,unsigned int>
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.
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.
typedef
internals::SparseMatrixIterators::Iterator<number,false>
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