From 8bcaf55df6754238b2e4e41bf6a5dd276a97bdd2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20K=C3=B6cher?= Date: Wed, 13 Jun 2018 18:09:20 +0200 Subject: [PATCH] bugfix for TrilinosWrapper::SparseMatrix ::add(factor, SparseMatrix) and ::copy_from(SparseMatrix) --- include/deal.II/lac/trilinos_sparse_matrix.h | 10 ++++++++++ source/lac/trilinos_sparse_matrix.cc | 9 ++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/deal.II/lac/trilinos_sparse_matrix.h b/include/deal.II/lac/trilinos_sparse_matrix.h index c41cc74318..54017d21f7 100644 --- a/include/deal.II/lac/trilinos_sparse_matrix.h +++ b/include/deal.II/lac/trilinos_sparse_matrix.h @@ -519,6 +519,16 @@ namespace TrilinosWrappers */ typedef dealii::types::global_dof_index size_type; + /** + * Exception + */ + DeclException1(ExcAccessToNonlocalRow, + std::size_t, + << "You tried to access row " << arg1 + << " of a non-contiguous locally owned row set." + << " The row " << arg1 + << " is not stored locally and can't be accessed."); + /** * 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 diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index 3529b6e22f..58bbd5b977 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -416,10 +416,11 @@ namespace TrilinosWrappers // Try to copy all the rows of the matrix one by one. In case of error // (i.e., the column indices are different), we need to abort and blow // away the matrix. - for (size_type row = local_range.first; row < local_range.second; ++row) + for (const auto &row : locally_owned_range_indices()) { const int row_local = matrix->RowMap().LID( static_cast(row)); + Assert((row_local >= 0), ExcAccessToNonlocalRow(row)); int n_entries, rhs_n_entries; TrilinosScalar *value_ptr, *rhs_value_ptr; @@ -1439,6 +1440,7 @@ namespace TrilinosWrappers int ncols = -1; int local_row = matrix->LRID(static_cast(row)); + Assert((local_row >= 0), ExcAccessToNonlocalRow(row)); // on the processor who owns this // row, we'll have a non-negative @@ -1449,7 +1451,7 @@ namespace TrilinosWrappers AssertThrow(ierr == 0, ExcTrilinosError(ierr)); } - return ncols; + return static_cast(ncols); } @@ -1885,10 +1887,11 @@ namespace TrilinosWrappers const std::pair local_range = rhs.local_range(); const bool same_col_map = matrix->ColMap().SameAs(rhs.matrix->ColMap()); - for (size_type row = local_range.first; row < local_range.second; ++row) + for (const auto &row : locally_owned_range_indices()) { const int row_local = matrix->RowMap().LID( static_cast(row)); + Assert((row_local >= 0), ExcAccessToNonlocalRow(row)); // First get a view to the matrix columns of both matrices. Note that // the data is in local index spaces so we need to be careful not only -- 2.39.5