]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a bug in collective set function.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 1 Oct 2009 14:59:36 +0000 (14:59 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 1 Oct 2009 14:59:36 +0000 (14:59 +0000)
git-svn-id: https://svn.dealii.org/trunk@19640 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/sparse_matrix.templates.h

index 374f9173eeff2d0e66c75dafd511a12d2d78a891..90afcc5e5a6852952f232558d029dfc604f286cd 100644 (file)
@@ -490,6 +490,8 @@ SparseMatrix<number>::add (const unsigned int  row,
                                   // actually need to add.
   const unsigned int * const my_cols = cols->get_column_numbers();
   unsigned int index = cols->get_rowstart_indices()[row];
+  const unsigned int next_row_index = cols->get_rowstart_indices()[row+1];
+
   for (unsigned int j=0; j<n_cols; ++j)
     {
       const number value = values[j];
@@ -504,8 +506,7 @@ SparseMatrix<number>::add (const unsigned int  row,
                                   // the next present index in the sparsity
                                   // pattern (otherwise, do a binary
                                   // search)
-      if (index != cols->get_rowstart_indices()[row+1] &&
-         my_cols[index] == col_indices[j])
+      if (index != next_row_index && my_cols[index] == col_indices[j])
        goto add_value;
 
       index = cols->operator()(row, col_indices[j]);
@@ -540,12 +541,15 @@ SparseMatrix<number>::set (const unsigned int  row,
                           const bool          elide_zero_values)
 {
   Assert (cols != 0, ExcNotInitialized());
+  Assert (row < m(), ExcInvalidIndex1(row));
 
                                   // First, search all the indices to find
                                   // out which values we actually need to
                                   // set.
   const unsigned int * my_cols = cols->get_column_numbers();
-  unsigned int index = cols->get_rowstart_indices()[row];
+  std::size_t index = cols->get_rowstart_indices()[row], next_index = index;
+  const std::size_t next_row_index = cols->get_rowstart_indices()[row+1];
+
   for (unsigned int j=0; j<n_cols; ++j)
     {
       const number value = values[j];
@@ -560,23 +564,21 @@ SparseMatrix<number>::set (const unsigned int  row,
                                   // the next present index in the sparsity
                                   // pattern (otherwise, do a binary
                                   // search)
-      if (index != cols->get_rowstart_indices()[row+1] &&
-         my_cols[index] == col_indices[j])
+      if (index != next_row_index && my_cols[index] == col_indices[j])
        goto set_value;
 
-      index = cols->operator()(row, col_indices[j]);
+      next_index = cols->operator()(row, col_indices[j]);
 
                                   // it is allowed to set elements in
                                   // the matrix that are not part of
                                   // the sparsity pattern, if the
                                   // value to which we set it is zero
-      if (index == SparsityPattern::invalid_entry)
+      if (next_index == SparsityPattern::invalid_entry)
        {
-         Assert ((index != SparsityPattern::invalid_entry) ||
-                 (value == 0.),
-                 ExcInvalidIndex(row,col_indices[j]));
+         Assert (value == 0., ExcInvalidIndex(row,col_indices[j]));
          continue;
        }
+      index = next_index;
 
     set_value:
       val[index] = value;

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.