From ba14c79afa0582f0fe6f6d2f99536d8b6f66fdb7 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 24 Apr 2016 18:47:28 -0400 Subject: [PATCH] Exit early if there are no matrix entries to add. This gets around an issue where, if one is using a sparsity pattern created by make_flux_sparsity_pattern and the 'nonzero' coupling option, one may end up trying to add zeros to entries that do not exist in the sparsity pattern on the current processor. This problem shows up when adding fluxes between locally owned and ghost cells. This commit sidesteps the issue by exiting early if there is nothing (i.e., the only thing to do is add zero) to do. --- doc/news/changes.h | 8 ++++++++ source/lac/trilinos_sparse_matrix.cc | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/doc/news/changes.h b/doc/news/changes.h index 7ba12b45f3..b22f6ffc36 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -201,6 +201,14 @@ inconvenience this causes.

Specific improvements

    +
  1. Fixed: TrilinosWrappers::SparseMatrix will now exit early if there are no + entries to add to the matrix. This usually occurs when zero elision is on. This + fixes a bug where the matrix raises an exception if there are no entries to add + to a matrix and the provided row and column values are not locally stored. +
    + (David Wells, 2016/04/24) +
  2. +
  3. Fixed: TrilinosWrappers::MPI::Vector and TrilinosWrappers::Vector could access invalid memory in the reinit() method if the MPI communicator was deleted before termination of the program. This usually happened when using diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index 56ad9213e0..b8e96e7a2a 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -1656,6 +1656,11 @@ namespace TrilinosWrappers Assert(n_columns <= (TrilinosWrappers::types::int_type)n_cols, ExcInternalError()); } + // Exit early if there is nothing to do + if (n_columns == 0) + { + return; + } // If the calling processor owns the row to which we want to add values, we // can directly call the Epetra_CrsMatrix input function, which is much -- 2.39.5