From: Martin Kronbichler Date: Mon, 22 Jul 2019 10:34:01 +0000 (+0200) Subject: Choose a more appropriate tolerance for vector add_and_dot X-Git-Tag: v9.2.0-rc1~1361^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8402%2Fhead;p=dealii.git Choose a more appropriate tolerance for vector add_and_dot --- diff --git a/tests/lac/la_parallel_vector_add_and_dot_complex.cc b/tests/lac/la_parallel_vector_add_and_dot_complex.cc index 5b5f21631b..88734d847e 100644 --- a/tests/lac/la_parallel_vector_add_and_dot_complex.cc +++ b/tests/lac/la_parallel_vector_add_and_dot_complex.cc @@ -61,14 +61,18 @@ check() } deallog << "Add and dot is "; - if (std::abs(prod - prod_check) < - 4. * std::numeric_limits::epsilon() * - std::sqrt(static_cast(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::epsilon() * + std::sqrt(static_cast(size)) * size * + size; + if (std::abs(prod - prod_check) < tolerance) deallog << "correct" << std::endl; else - deallog << "wrong; should be " << prod / static_cast(size) - << ", is " << prod_check / static_cast(size) - << std::endl; + deallog << "wrong by " << std::abs(prod - prod_check) + << " with tolerance " << tolerance << "; should be " + << prod / static_cast(size) << ", is " + << prod_check / static_cast(size) << std::endl; } } diff --git a/tests/lac/la_vector_add_and_dot_complex.cc b/tests/lac/la_vector_add_and_dot_complex.cc index f86fd6453e..c4dfbf3a0a 100644 --- a/tests/lac/la_vector_add_and_dot_complex.cc +++ b/tests/lac/la_vector_add_and_dot_complex.cc @@ -58,14 +58,18 @@ check() } deallog << "Add and dot is "; - if (std::abs(prod - prod_check) < - 4. * std::numeric_limits::epsilon() * - std::sqrt(static_cast(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::epsilon() * + std::sqrt(static_cast(size)) * size * + size; + if (std::abs(prod - prod_check) < tolerance) deallog << "correct" << std::endl; else - deallog << "wrong; should be " << prod / static_cast(size) - << ", is " << prod_check / static_cast(size) - << std::endl; + deallog << "wrong by " << std::abs(prod - prod_check) + << " with tolerance " << tolerance << "; should be " + << prod / static_cast(size) << ", is " + << prod_check / static_cast(size) << std::endl; } } diff --git a/tests/lac/vector_add_and_dot_complex.cc b/tests/lac/vector_add_and_dot_complex.cc index 20396444de..48f8fbe585 100644 --- a/tests/lac/vector_add_and_dot_complex.cc +++ b/tests/lac/vector_add_and_dot_complex.cc @@ -55,14 +55,18 @@ check() } deallog << "Add and dot is "; - if (std::abs(prod - prod_check) < - 4. * std::abs(std::numeric_limits::epsilon()) * - std::sqrt(static_cast(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::epsilon() * + std::sqrt(static_cast(size)) * size * + size; + if (std::abs(prod - prod_check) < tolerance) deallog << "correct" << std::endl; else - deallog << "wrong; should be " << prod / static_cast(size) - << ", is " << prod_check / static_cast(size) - << std::endl; + deallog << "wrong by " << std::abs(prod - prod_check) + << " with tolerance " << tolerance << "; should be " + << prod / static_cast(size) << ", is " + << prod_check / static_cast(size) << std::endl; } }