]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Choose a more appropriate tolerance for vector add_and_dot 8402/head
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Mon, 22 Jul 2019 10:34:01 +0000 (12:34 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Mon, 22 Jul 2019 10:34:01 +0000 (12:34 +0200)
tests/lac/la_parallel_vector_add_and_dot_complex.cc
tests/lac/la_vector_add_and_dot_complex.cc
tests/lac/vector_add_and_dot_complex.cc

index 5b5f21631bdb2381ae7caa6b66d93ff547213865..88734d847e10323716971b207697f4a72ab954bb 100644 (file)
@@ -61,14 +61,18 @@ check()
         }
 
       deallog << "Add and dot is ";
-      if (std::abs(prod - prod_check) <
-          4. * std::numeric_limits<number>::epsilon() *
-            std::sqrt(static_cast<number>(size)) * size)
+      // check tolerance with respect to the expected size of result which is
+      // ~ size^2 including the roundoff error ~ sqrt(size) we expect
+      const number tolerance = 4. * std::numeric_limits<number>::epsilon() *
+                               std::sqrt(static_cast<number>(size)) * size *
+                               size;
+      if (std::abs(prod - prod_check) < tolerance)
         deallog << "correct" << std::endl;
       else
-        deallog << "wrong; should be " << prod / static_cast<number>(size)
-                << ", is " << prod_check / static_cast<number>(size)
-                << std::endl;
+        deallog << "wrong by " << std::abs(prod - prod_check)
+                << " with tolerance " << tolerance << "; should be "
+                << prod / static_cast<number>(size) << ", is "
+                << prod_check / static_cast<number>(size) << std::endl;
     }
 }
 
index f86fd6453e2af8216b659ce2dea52d9fa0b8ba1a..c4dfbf3a0a7e29bf49d1aa71b8327f54c604e307 100644 (file)
@@ -58,14 +58,18 @@ check()
         }
 
       deallog << "Add and dot is ";
-      if (std::abs(prod - prod_check) <
-          4. * std::numeric_limits<number>::epsilon() *
-            std::sqrt(static_cast<number>(size)) * size)
+      // check tolerance with respect to the expected size of result which is
+      // ~ size^2 including the roundoff error ~ sqrt(size) we expect
+      const number tolerance = 4. * std::numeric_limits<number>::epsilon() *
+                               std::sqrt(static_cast<number>(size)) * size *
+                               size;
+      if (std::abs(prod - prod_check) < tolerance)
         deallog << "correct" << std::endl;
       else
-        deallog << "wrong; should be " << prod / static_cast<number>(size)
-                << ", is " << prod_check / static_cast<number>(size)
-                << std::endl;
+        deallog << "wrong by " << std::abs(prod - prod_check)
+                << " with tolerance " << tolerance << "; should be "
+                << prod / static_cast<number>(size) << ", is "
+                << prod_check / static_cast<number>(size) << std::endl;
     }
 }
 
index 20396444de540481c052f25bca186e01d48f4118..48f8fbe5852022654855a6fd68a27cf762a2e9c8 100644 (file)
@@ -55,14 +55,18 @@ check()
         }
 
       deallog << "Add and dot is ";
-      if (std::abs(prod - prod_check) <
-          4. * std::abs(std::numeric_limits<number>::epsilon()) *
-            std::sqrt(static_cast<double>(size)) * size)
+      // check tolerance with respect to the expected size of result which is
+      // ~ size^2 including the roundoff error ~ sqrt(size) we expect
+      const number tolerance = 4. * std::numeric_limits<number>::epsilon() *
+                               std::sqrt(static_cast<number>(size)) * size *
+                               size;
+      if (std::abs(prod - prod_check) < tolerance)
         deallog << "correct" << std::endl;
       else
-        deallog << "wrong; should be " << prod / static_cast<number>(size)
-                << ", is " << prod_check / static_cast<number>(size)
-                << std::endl;
+        deallog << "wrong by " << std::abs(prod - prod_check)
+                << " with tolerance " << tolerance << "; should be "
+                << prod / static_cast<number>(size) << ", is "
+                << prod_check / static_cast<number>(size) << std::endl;
     }
 }
 

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.