From d8ca5ca44ebb8c73dac50168b16d46dc1d13b4d1 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Sun, 21 Oct 2018 15:26:43 +0200 Subject: [PATCH] Make CUDA tests more robust --- tests/cuda/precondition_01.cu | 14 ++- tests/cuda/precondition_01.output | 174 ++---------------------------- tests/cuda/precondition_02.cu | 14 ++- tests/cuda/precondition_02.output | 174 ++---------------------------- 4 files changed, 34 insertions(+), 342 deletions(-) diff --git a/tests/cuda/precondition_01.cu b/tests/cuda/precondition_01.cu index b238ad379a..9de6715e61 100644 --- a/tests/cuda/precondition_01.cu +++ b/tests/cuda/precondition_01.cu @@ -42,7 +42,6 @@ test(Utilities::CUDA::Handle &cuda_handle) structure.compress(); A.reinit(structure); testproblem.five_point(A); - A.print(std::cout); // Solve on the device CUDAWrappers::SparseMatrix A_dev(cuda_handle, A); @@ -52,7 +51,8 @@ test(Utilities::CUDA::Handle &cuda_handle) for (unsigned int i = 0; i < size; ++i) rw_vector[i] = static_cast(i); rhs_dev.import(rw_vector, VectorOperation::insert); - SolverControl control(100, 1.e-10); + const Number tolerance = 1000. * std::numeric_limits::epsilon(); + SolverControl control(100, tolerance); SolverCG> cg_dev(control); CUDAWrappers::PreconditionIC prec_ic(cuda_handle); @@ -61,19 +61,23 @@ test(Utilities::CUDA::Handle &cuda_handle) cg_dev.solve(A_dev, sol_dev, rhs_dev, prec_ic); // Check the result - rw_vector.import(sol_dev, VectorOperation::insert); - for (unsigned int i = 0; i < size; ++i) - deallog << rw_vector[i] << std::endl; + LinearAlgebra::CUDAWrappers::Vector residual(size); + A_dev.residual(residual, sol_dev, rhs_dev); + Assert(residual.l2_norm() < 20 * tolerance, ExcInternalError()); + deallog << "OK" << std::endl; } int main() { initlog(); + deallog << std::setprecision(10); deallog.depth_console(0); Utilities::CUDA::Handle cuda_handle; + deallog << "Testing float" << std::endl; test(cuda_handle); + deallog << "Testing double" << std::endl; test(cuda_handle); deallog << "OK" << std::endl; diff --git a/tests/cuda/precondition_01.output b/tests/cuda/precondition_01.output index 0f5ff01738..27a4138a2b 100644 --- a/tests/cuda/precondition_01.output +++ b/tests/cuda/precondition_01.output @@ -1,168 +1,10 @@ -DEAL:cg::Starting value 416.989 -DEAL:cg::Convergence step 19 value 1.41136e-11 -DEAL::20.9607 -DEAL::38.8073 -DEAL::52.3525 -DEAL::61.2758 -DEAL::65.4369 -DEAL::64.6135 -DEAL::58.3945 -DEAL::46.1455 -DEAL::27.0190 -DEAL::45.0353 -DEAL::80.9161 -DEAL::107.327 -DEAL::124.314 -DEAL::131.858 -DEAL::129.623 -DEAL::116.819 -DEAL::92.1685 -DEAL::53.9305 -DEAL::69.2645 -DEAL::122.495 -DEAL::160.725 -DEAL::184.794 -DEAL::195.060 -DEAL::191.200 -DEAL::172.090 -DEAL::135.779 -DEAL::79.5345 -DEAL::91.5276 -DEAL::160.074 -DEAL::208.285 -DEAL::238.076 -DEAL::250.389 -DEAL::245.025 -DEAL::220.563 -DEAL::174.324 -DEAL::102.428 -DEAL::109.771 -DEAL::189.991 -DEAL::245.262 -DEAL::278.838 -DEAL::292.394 -DEAL::285.950 -DEAL::257.813 -DEAL::204.524 -DEAL::120.855 -DEAL::121.567 -DEAL::207.855 -DEAL::265.937 -DEAL::300.618 -DEAL::314.399 -DEAL::307.567 -DEAL::278.215 -DEAL::222.104 -DEAL::132.468 -DEAL::123.643 -DEAL::207.924 -DEAL::263.011 -DEAL::295.300 -DEAL::308.015 -DEAL::301.706 -DEAL::274.376 -DEAL::221.208 -DEAL::133.913 -DEAL::111.079 -DEAL::182.188 -DEAL::226.884 -DEAL::252.556 -DEAL::262.656 -DEAL::257.865 -DEAL::236.376 -DEAL::193.440 -DEAL::119.974 -DEAL::75.4858 -DEAL::118.864 -DEAL::144.783 -DEAL::159.382 -DEAL::165.189 -DEAL::162.720 -DEAL::150.825 -DEAL::126.202 -DEAL::81.5441 -DEAL:cg::Starting value 416.989 -DEAL:cg::Convergence step 17 value 5.54040e-11 -DEAL::20.9607 -DEAL::38.8073 -DEAL::52.3525 -DEAL::61.2757 -DEAL::65.4369 -DEAL::64.6135 -DEAL::58.3945 -DEAL::46.1455 -DEAL::27.0190 -DEAL::45.0353 -DEAL::80.9161 -DEAL::107.327 -DEAL::124.314 -DEAL::131.858 -DEAL::129.623 -DEAL::116.819 -DEAL::92.1685 -DEAL::53.9305 -DEAL::69.2645 -DEAL::122.495 -DEAL::160.725 -DEAL::184.794 -DEAL::195.060 -DEAL::191.200 -DEAL::172.090 -DEAL::135.779 -DEAL::79.5345 -DEAL::91.5276 -DEAL::160.074 -DEAL::208.285 -DEAL::238.076 -DEAL::250.389 -DEAL::245.025 -DEAL::220.563 -DEAL::174.324 -DEAL::102.428 -DEAL::109.771 -DEAL::189.991 -DEAL::245.262 -DEAL::278.838 -DEAL::292.394 -DEAL::285.950 -DEAL::257.813 -DEAL::204.524 -DEAL::120.855 -DEAL::121.567 -DEAL::207.855 -DEAL::265.937 -DEAL::300.618 -DEAL::314.399 -DEAL::307.567 -DEAL::278.215 -DEAL::222.104 -DEAL::132.468 -DEAL::123.643 -DEAL::207.924 -DEAL::263.011 -DEAL::295.300 -DEAL::308.015 -DEAL::301.706 -DEAL::274.376 -DEAL::221.208 -DEAL::133.913 -DEAL::111.079 -DEAL::182.188 -DEAL::226.884 -DEAL::252.556 -DEAL::262.656 -DEAL::257.865 -DEAL::236.376 -DEAL::193.440 -DEAL::119.974 -DEAL::75.4858 -DEAL::118.864 -DEAL::144.783 -DEAL::159.382 -DEAL::165.189 -DEAL::162.720 -DEAL::150.825 -DEAL::126.202 -DEAL::81.5441 +DEAL::Testing float +DEAL:cg::Starting value 416.9891968 +DEAL:cg::Convergence step 11 value 3.993874634e-05 +DEAL::OK +DEAL::Testing double +DEAL:cg::Starting value 416.9892085 +DEAL:cg::Convergence step 20 value 9.834412497e-14 +DEAL::OK DEAL::OK diff --git a/tests/cuda/precondition_02.cu b/tests/cuda/precondition_02.cu index 990d4a92b9..edfea90e81 100644 --- a/tests/cuda/precondition_02.cu +++ b/tests/cuda/precondition_02.cu @@ -42,7 +42,6 @@ test(Utilities::CUDA::Handle &cuda_handle) structure.compress(); A.reinit(structure); testproblem.five_point(A); - A.print(std::cout); // Solve on the device CUDAWrappers::SparseMatrix A_dev(cuda_handle, A); @@ -52,7 +51,8 @@ test(Utilities::CUDA::Handle &cuda_handle) for (unsigned int i = 0; i < size; ++i) rw_vector[i] = static_cast(i); rhs_dev.import(rw_vector, VectorOperation::insert); - SolverControl control(100, 1.e-10); + const Number tolerance = 1000. * std::numeric_limits::epsilon(); + SolverControl control(100, tolerance); SolverCG> cg_dev(control); CUDAWrappers::PreconditionILU prec_ilu(cuda_handle); @@ -61,19 +61,23 @@ test(Utilities::CUDA::Handle &cuda_handle) cg_dev.solve(A_dev, sol_dev, rhs_dev, prec_ilu); // Check the result - rw_vector.import(sol_dev, VectorOperation::insert); - for (unsigned int i = 0; i < size; ++i) - deallog << rw_vector[i] << std::endl; + LinearAlgebra::CUDAWrappers::Vector residual(size); + A_dev.residual(residual, sol_dev, rhs_dev); + Assert(residual.l2_norm() < 20 * tolerance, ExcInternalError()); + deallog << "OK" << std::endl; } int main() { initlog(); + deallog << std::setprecision(10); deallog.depth_console(0); Utilities::CUDA::Handle cuda_handle; + deallog << "Testing float" << std::endl; test(cuda_handle); + deallog << "Testing double" << std::endl; test(cuda_handle); deallog << "OK" << std::endl; diff --git a/tests/cuda/precondition_02.output b/tests/cuda/precondition_02.output index 913218546b..1c14226e67 100644 --- a/tests/cuda/precondition_02.output +++ b/tests/cuda/precondition_02.output @@ -1,168 +1,10 @@ -DEAL:cg::Starting value 416.989 -DEAL:cg::Convergence step 19 value 1.40142e-11 -DEAL::20.9607 -DEAL::38.8073 -DEAL::52.3525 -DEAL::61.2758 -DEAL::65.4369 -DEAL::64.6135 -DEAL::58.3945 -DEAL::46.1455 -DEAL::27.0190 -DEAL::45.0353 -DEAL::80.9161 -DEAL::107.327 -DEAL::124.314 -DEAL::131.858 -DEAL::129.623 -DEAL::116.819 -DEAL::92.1685 -DEAL::53.9305 -DEAL::69.2645 -DEAL::122.495 -DEAL::160.725 -DEAL::184.794 -DEAL::195.060 -DEAL::191.200 -DEAL::172.090 -DEAL::135.779 -DEAL::79.5345 -DEAL::91.5276 -DEAL::160.074 -DEAL::208.285 -DEAL::238.076 -DEAL::250.389 -DEAL::245.025 -DEAL::220.563 -DEAL::174.324 -DEAL::102.428 -DEAL::109.771 -DEAL::189.991 -DEAL::245.262 -DEAL::278.838 -DEAL::292.394 -DEAL::285.950 -DEAL::257.813 -DEAL::204.524 -DEAL::120.855 -DEAL::121.567 -DEAL::207.855 -DEAL::265.937 -DEAL::300.618 -DEAL::314.399 -DEAL::307.567 -DEAL::278.215 -DEAL::222.104 -DEAL::132.468 -DEAL::123.643 -DEAL::207.924 -DEAL::263.011 -DEAL::295.300 -DEAL::308.015 -DEAL::301.706 -DEAL::274.376 -DEAL::221.208 -DEAL::133.913 -DEAL::111.079 -DEAL::182.188 -DEAL::226.884 -DEAL::252.556 -DEAL::262.656 -DEAL::257.865 -DEAL::236.376 -DEAL::193.440 -DEAL::119.974 -DEAL::75.4858 -DEAL::118.864 -DEAL::144.783 -DEAL::159.382 -DEAL::165.189 -DEAL::162.720 -DEAL::150.825 -DEAL::126.202 -DEAL::81.5441 -DEAL:cg::Starting value 416.989 -DEAL:cg::Convergence step 17 value 5.54040e-11 -DEAL::20.9607 -DEAL::38.8073 -DEAL::52.3525 -DEAL::61.2757 -DEAL::65.4369 -DEAL::64.6135 -DEAL::58.3945 -DEAL::46.1455 -DEAL::27.0190 -DEAL::45.0353 -DEAL::80.9161 -DEAL::107.327 -DEAL::124.314 -DEAL::131.858 -DEAL::129.623 -DEAL::116.819 -DEAL::92.1685 -DEAL::53.9305 -DEAL::69.2645 -DEAL::122.495 -DEAL::160.725 -DEAL::184.794 -DEAL::195.060 -DEAL::191.200 -DEAL::172.090 -DEAL::135.779 -DEAL::79.5345 -DEAL::91.5276 -DEAL::160.074 -DEAL::208.285 -DEAL::238.076 -DEAL::250.389 -DEAL::245.025 -DEAL::220.563 -DEAL::174.324 -DEAL::102.428 -DEAL::109.771 -DEAL::189.991 -DEAL::245.262 -DEAL::278.838 -DEAL::292.394 -DEAL::285.950 -DEAL::257.813 -DEAL::204.524 -DEAL::120.855 -DEAL::121.567 -DEAL::207.855 -DEAL::265.937 -DEAL::300.618 -DEAL::314.399 -DEAL::307.567 -DEAL::278.215 -DEAL::222.104 -DEAL::132.468 -DEAL::123.643 -DEAL::207.924 -DEAL::263.011 -DEAL::295.300 -DEAL::308.015 -DEAL::301.706 -DEAL::274.376 -DEAL::221.208 -DEAL::133.913 -DEAL::111.079 -DEAL::182.188 -DEAL::226.884 -DEAL::252.556 -DEAL::262.656 -DEAL::257.865 -DEAL::236.376 -DEAL::193.440 -DEAL::119.974 -DEAL::75.4858 -DEAL::118.864 -DEAL::144.783 -DEAL::159.382 -DEAL::165.189 -DEAL::162.720 -DEAL::150.825 -DEAL::126.202 -DEAL::81.5441 +DEAL::Testing float +DEAL:cg::Starting value 416.9891968 +DEAL:cg::Convergence step 11 value 3.993944847e-05 +DEAL::OK +DEAL::Testing double +DEAL:cg::Starting value 416.9892085 +DEAL:cg::Convergence step 20 value 9.834484941e-14 +DEAL::OK DEAL::OK -- 2.39.5