From bce4a15edcbd352bb73abd919fcc1fca5bc79634 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Thu, 1 Oct 2009 14:59:36 +0000 Subject: [PATCH] Fix a bug in collective set function. git-svn-id: https://svn.dealii.org/trunk@19640 0785d39b-7218-0410-832d-ea1e28bc413d --- .../lac/include/lac/sparse_matrix.templates.h | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index 374f9173ee..90afcc5e5a 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -490,6 +490,8 @@ SparseMatrix::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::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::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::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; -- 2.39.5