]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix allocation in TrilinosWrappers::SparseMatrix::AccessorBase 16416/head
authorPeter Munch <peterrmuench@gmail.com>
Sat, 6 Jan 2024 12:30:38 +0000 (13:30 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Sat, 6 Jan 2024 20:35:17 +0000 (21:35 +0100)
source/lac/trilinos_sparse_matrix.cc

index 971f37be54962c5ed841de790dcd2aae6accf30e..f36ab6f8d1502b46878a40438aba55a5dc1a6b9f 100644 (file)
@@ -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<std::vector<TrilinosScalar>>(matrix->n());
-          colnum_cache = std::make_shared<std::vector<size_type>>(matrix->n());
+          value_cache  = std::make_shared<std::vector<TrilinosScalar>>(colnums);
+          colnum_cache = std::make_shared<std::vector<size_type>>(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<TrilinosWrappers::types::int_type *>(
           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

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.