From 6c9a594f0784124f906b65aa26053ed258a14b0f Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 19 Dec 2014 12:33:45 +0100 Subject: [PATCH] Test umfpack/umfpack_04: Avoid printing exact number of iterations This commit introduces a new macro for tests to test an iterative solve to convergence within a given number of iteration steps. Due to roundoff errors the exact number doesn't have to be stable... --- tests/tests.h | 28 ++++++++++++ tests/umfpack/umfpack_04.cc | 45 +++++++++++++++++-- ...fpack_04.compiler=Intel=yes.release.output | 37 --------------- tests/umfpack/umfpack_04.debug.output | 37 --------------- ...el=no.release.output => umfpack_04.output} | 18 +++----- 5 files changed, 76 insertions(+), 89 deletions(-) delete mode 100644 tests/umfpack/umfpack_04.compiler=Intel=yes.release.output delete mode 100644 tests/umfpack/umfpack_04.debug.output rename tests/umfpack/{umfpack_04.compiler=Intel=no.release.output => umfpack_04.output} (63%) diff --git a/tests/tests.h b/tests/tests.h index 10cc76eb77..fe7ecbd81d 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -144,6 +144,34 @@ void unify_pretty_function (const std::string &filename) } +/* + * Test that a solver converged within a certain range of iteration steps. + * + * SOLVER_COMMAND is the command to issue, CONTROL_COMMAND a function call + * that returns the number of iterations (castable to unsigned int), and + * MIN_ALLOWED, MAX_ALLOWED is the inclusive range of allowed iteration + * steps. + */ + +#define check_solver_within_range(SOLVER_COMMAND, CONTROL_COMMAND, MIN_ALLOWED, MAX_ALLOWED) \ +{ \ + const unsigned int previous_depth = deallog.depth_file(0); \ + SOLVER_COMMAND; \ + deallog.depth_file(previous_depth); \ + const unsigned int steps = CONTROL_COMMAND; \ + if (steps >= MIN_ALLOWED && steps <= MAX_ALLOWED) \ + { \ + deallog << "Solver stopped within " << MIN_ALLOWED << " - " \ + << MAX_ALLOWED << " iterations" << std::endl; \ + } \ + else \ + { \ + deallog << "Solver stopped after " << steps << " iterations" \ + << std::endl; \ + } \ +} + + // ------------------------------ Functions used in initializing subsystems ------------------- diff --git a/tests/umfpack/umfpack_04.cc b/tests/umfpack/umfpack_04.cc index 177d94a40f..d20df2b930 100644 --- a/tests/umfpack/umfpack_04.cc +++ b/tests/umfpack/umfpack_04.cc @@ -174,12 +174,51 @@ void test () ubb = bb; SolverControl control (1000, 1e-13); - SolverCG > bcg(control, SolverCG >::AdditionalData()); - bcg.solve(Bb, bx, bb, PreconditionIdentity()); + + switch (dim) + { + case 1: + check_solver_within_range( + bcg.solve(Bb, bx, bb, PreconditionIdentity()), + control.last_step(), 112, 114); + break; + case 2: + check_solver_within_range( + bcg.solve(Bb, bx, bb, PreconditionIdentity()), + control.last_step(), 60, 62); + break; + case 3: + check_solver_within_range( + bcg.solve(Bb, bx, bb, PreconditionIdentity()), + control.last_step(), 24, 26); + break; + default: + Assert(false, ExcNotImplemented()); + } SolverCG > cg(control, SolverCG >::AdditionalData()); - cg.solve(B, x, b, PreconditionIdentity()); + + switch (dim) + { + case 1: + check_solver_within_range( + cg.solve(B, x, b, PreconditionIdentity()), + control.last_step(), 112, 114); + break; + case 2: + check_solver_within_range( + cg.solve(B, x, b, PreconditionIdentity()), + control.last_step(), 60, 62); + break; + case 3: + check_solver_within_range( + cg.solve(B, x, b, PreconditionIdentity()), + control.last_step(), 24, 26); + break; + default: + Assert(false, ExcNotImplemented()); + } deallog << "Sparse Factorization" << std::endl; SparseDirectUMFPACK umfpack, umfpackb; diff --git a/tests/umfpack/umfpack_04.compiler=Intel=yes.release.output b/tests/umfpack/umfpack_04.compiler=Intel=yes.release.output deleted file mode 100644 index 221e282041..0000000000 --- a/tests/umfpack/umfpack_04.compiler=Intel=yes.release.output +++ /dev/null @@ -1,37 +0,0 @@ - -DEAL::1d -DEAL::Number of dofs = 97 -DEAL:cg::Starting value 0.215517 -DEAL:cg::Convergence step 112 value 0 -DEAL:cg::Starting value 0.215517 -DEAL:cg::Convergence step 112 value 0 -DEAL::Sparse Factorization -DEAL::absolute norms = 6.45748 6.45748 -DEAL::relative norm distance = 0 -DEAL::Block Sparse Factorization -DEAL::absolute norms = 6.45748 6.45748 -DEAL::relative norm distance = 0 -DEAL::2d -DEAL::Number of dofs = 994 -DEAL:cg::Starting value 0.595296 -DEAL:cg::Convergence step 61 value 0 -DEAL:cg::Starting value 0.595296 -DEAL:cg::Convergence step 61 value 0 -DEAL::Sparse Factorization -DEAL::absolute norms = 10.0596 10.0596 -DEAL::relative norm distance = 0 -DEAL::Block Sparse Factorization -DEAL::absolute norms = 10.0596 10.0596 -DEAL::relative norm distance = 0 -DEAL::3d -DEAL::Number of dofs = 669 -DEAL:cg::Starting value 3.12141 -DEAL:cg::Convergence step 25 value 0 -DEAL:cg::Starting value 3.12141 -DEAL:cg::Convergence step 25 value 0 -DEAL::Sparse Factorization -DEAL::absolute norms = 13.7931 13.7931 -DEAL::relative norm distance = 0 -DEAL::Block Sparse Factorization -DEAL::absolute norms = 13.7931 13.7931 -DEAL::relative norm distance = 0 diff --git a/tests/umfpack/umfpack_04.debug.output b/tests/umfpack/umfpack_04.debug.output deleted file mode 100644 index 8a04a69361..0000000000 --- a/tests/umfpack/umfpack_04.debug.output +++ /dev/null @@ -1,37 +0,0 @@ - -DEAL::1d -DEAL::Number of dofs = 97 -DEAL:cg::Starting value 0.215517 -DEAL:cg::Convergence step 113 value 0 -DEAL:cg::Starting value 0.215517 -DEAL:cg::Convergence step 113 value 0 -DEAL::Sparse Factorization -DEAL::absolute norms = 6.45748 6.45748 -DEAL::relative norm distance = 0 -DEAL::Block Sparse Factorization -DEAL::absolute norms = 6.45748 6.45748 -DEAL::relative norm distance = 0 -DEAL::2d -DEAL::Number of dofs = 994 -DEAL:cg::Starting value 0.595296 -DEAL:cg::Convergence step 61 value 0 -DEAL:cg::Starting value 0.595296 -DEAL:cg::Convergence step 61 value 0 -DEAL::Sparse Factorization -DEAL::absolute norms = 10.0596 10.0596 -DEAL::relative norm distance = 0 -DEAL::Block Sparse Factorization -DEAL::absolute norms = 10.0596 10.0596 -DEAL::relative norm distance = 0 -DEAL::3d -DEAL::Number of dofs = 669 -DEAL:cg::Starting value 3.12141 -DEAL:cg::Convergence step 25 value 0 -DEAL:cg::Starting value 3.12141 -DEAL:cg::Convergence step 25 value 0 -DEAL::Sparse Factorization -DEAL::absolute norms = 13.7931 13.7931 -DEAL::relative norm distance = 0 -DEAL::Block Sparse Factorization -DEAL::absolute norms = 13.7931 13.7931 -DEAL::relative norm distance = 0 diff --git a/tests/umfpack/umfpack_04.compiler=Intel=no.release.output b/tests/umfpack/umfpack_04.output similarity index 63% rename from tests/umfpack/umfpack_04.compiler=Intel=no.release.output rename to tests/umfpack/umfpack_04.output index 8a04a69361..de6c549d19 100644 --- a/tests/umfpack/umfpack_04.compiler=Intel=no.release.output +++ b/tests/umfpack/umfpack_04.output @@ -1,10 +1,8 @@ DEAL::1d DEAL::Number of dofs = 97 -DEAL:cg::Starting value 0.215517 -DEAL:cg::Convergence step 113 value 0 -DEAL:cg::Starting value 0.215517 -DEAL:cg::Convergence step 113 value 0 +DEAL::Solver stopped within 112 - 114 iterations +DEAL::Solver stopped within 112 - 114 iterations DEAL::Sparse Factorization DEAL::absolute norms = 6.45748 6.45748 DEAL::relative norm distance = 0 @@ -13,10 +11,8 @@ DEAL::absolute norms = 6.45748 6.45748 DEAL::relative norm distance = 0 DEAL::2d DEAL::Number of dofs = 994 -DEAL:cg::Starting value 0.595296 -DEAL:cg::Convergence step 61 value 0 -DEAL:cg::Starting value 0.595296 -DEAL:cg::Convergence step 61 value 0 +DEAL::Solver stopped within 60 - 62 iterations +DEAL::Solver stopped within 60 - 62 iterations DEAL::Sparse Factorization DEAL::absolute norms = 10.0596 10.0596 DEAL::relative norm distance = 0 @@ -25,10 +21,8 @@ DEAL::absolute norms = 10.0596 10.0596 DEAL::relative norm distance = 0 DEAL::3d DEAL::Number of dofs = 669 -DEAL:cg::Starting value 3.12141 -DEAL:cg::Convergence step 25 value 0 -DEAL:cg::Starting value 3.12141 -DEAL:cg::Convergence step 25 value 0 +DEAL::Solver stopped within 24 - 26 iterations +DEAL::Solver stopped within 24 - 26 iterations DEAL::Sparse Factorization DEAL::absolute norms = 13.7931 13.7931 DEAL::relative norm distance = 0 -- 2.39.5