]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use at least three temporary vectors for GMRES. 6133/head
authorDavid Wells <wellsd2@rpi.edu>
Sat, 31 Mar 2018 23:13:16 +0000 (19:13 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sun, 1 Apr 2018 18:44:29 +0000 (14:44 -0400)
This prevents possible integer wrap-around that is not desired.

This was found by coverity.

include/deal.II/lac/solver_gmres.h

index 47d51d4c34c4ce35c6615ec7077178f8082f9e0a..dcdc6b6f55605a27e8833a470f0f860b678313b7 100644 (file)
@@ -197,7 +197,8 @@ public:
     /**
      * Maximum number of temporary vectors. This parameter controls the size
      * of the Arnoldi basis, which for historical reasons is
-     * #max_n_tmp_vectors-2.
+     * #max_n_tmp_vectors-2. SolverGMRES assumes that there are at least three
+     * temporary vectors, so this value must be greater than or equal to three.
      */
     unsigned int    max_n_tmp_vectors;
 
@@ -598,7 +599,10 @@ AdditionalData (const unsigned int max_n_tmp_vectors,
   right_preconditioning(right_preconditioning),
   use_default_residual(use_default_residual),
   force_re_orthogonalization(force_re_orthogonalization)
-{}
+{
+  Assert(3 <= max_n_tmp_vectors, ExcMessage("SolverGMRES needs at least three "
+                                            "temporary vectors."));
+}
 
 
 
@@ -774,7 +778,10 @@ SolverGMRES<VectorType>::solve (const MatrixType         &A,
 //TODO:[GK] Make sure the parameter in the constructor means maximum basis size
 
   LogStream::Prefix prefix("GMRES");
-  const unsigned int n_tmp_vectors = additional_data.max_n_tmp_vectors;
+
+  // extra call to std::max to placate static analyzers: coverity rightfully
+  // complains that data.max_n_tmp_vectors - 2 may overflow
+  const unsigned int n_tmp_vectors = std::max(additional_data.max_n_tmp_vectors, 3u);
 
   // Generate an object where basis vectors are stored.
   internal::SolverGMRESImplementation::TmpVectors<VectorType> tmp_vectors (n_tmp_vectors, this->memory);

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.