From c8c4c50b00591e2d0dadfd9429a37ddf2ec9b1f6 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Sat, 6 Jan 2024 13:30:38 +0100 Subject: [PATCH] Fix allocation in TrilinosWrappers::SparseMatrix::AccessorBase --- source/lac/trilinos_sparse_matrix.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index 971f37be54..f36ab6f8d1 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -158,28 +158,27 @@ namespace TrilinosWrappers // get a representation of the present row int ncols; - TrilinosWrappers::types::int_type colnums = matrix->n(); + TrilinosWrappers::types::int_type colnums = + matrix->row_length(this->a_row); if (value_cache.get() == nullptr) { - value_cache = - std::make_shared>(matrix->n()); - colnum_cache = std::make_shared>(matrix->n()); + value_cache = std::make_shared>(colnums); + colnum_cache = std::make_shared>(colnums); } else { - value_cache->resize(matrix->n()); - colnum_cache->resize(matrix->n()); + value_cache->resize(colnums); + colnum_cache->resize(colnums); } - int ierr = matrix->trilinos_matrix().ExtractGlobalRowCopy( + const int ierr = matrix->trilinos_matrix().ExtractGlobalRowCopy( this->a_row, colnums, ncols, value_cache->data(), reinterpret_cast( colnum_cache->data())); - value_cache->resize(ncols); - colnum_cache->resize(ncols); + AssertDimension(ncols, colnums); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); // copy it into our caches if the -- 2.39.5