]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Optimize setting a matrix to zero. 16399/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 1 Jan 2024 01:46:15 +0000 (18:46 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 2 Jan 2024 01:49:49 +0000 (18:49 -0700)
source/lac/trilinos_sparse_matrix.cc

index b9c74f49b47d33b511366f712ee8a6c66d75979a..231e9e3f836567f6156029846da8bdf6e3e11391 100644 (file)
@@ -1761,14 +1761,23 @@ namespace TrilinosWrappers
   SparseMatrix &
   SparseMatrix::operator=(const double d)
   {
+    (void)d;
     Assert(d == 0, ExcScalarAssignmentOnlyForZeroValue());
     compress(VectorOperation::unknown); // TODO: why do we do this? Should we
                                         // not check for is_compressed?
 
-    const int ierr = matrix->PutScalar(d);
+    // As checked above, we are only allowed to use d==0.0, so pass
+    // a constant zero (instead of a run-time value 'd' that *happens* to
+    // have a zero value) to the underlying class in hopes that the compiler
+    // can optimize this somehow.
+    const int ierr = matrix->PutScalar(/*d=*/0.0);
     AssertThrow(ierr == 0, ExcTrilinosError(ierr));
+
     if (nonlocal_matrix.get() != nullptr)
-      nonlocal_matrix->PutScalar(d);
+      {
+        const int ierr = nonlocal_matrix->PutScalar(/*d=*/0.0);
+        AssertThrow(ierr == 0, ExcTrilinosError(ierr));
+      }
 
     return *this;
   }

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.