From 80466ff1a333ec2e1e97d96fba55cf7aa9626cd5 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 17 Aug 2018 15:12:25 +0200 Subject: [PATCH] SolverFIRE --- include/deal.II/lac/solver_fire.h | 3 +- tests/cuda/solver_06.cu | 85 +++++++++++++++++++++++++++++++ tests/cuda/solver_06.output | 6 +++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tests/cuda/solver_06.cu create mode 100644 tests/cuda/solver_06.output diff --git a/include/deal.II/lac/solver_fire.h b/include/deal.II/lac/solver_fire.h index 580f06b945..b0fdf22bc7 100644 --- a/include/deal.II/lac/solver_fire.h +++ b/include/deal.II/lac/solver_fire.h @@ -132,7 +132,8 @@ public: * Constructor. Use an object of type GrowingVectorMemory as a default to * allocate memory. */ - SolverFIRE(SolverControl &solver_control, const AdditionalData &data); + SolverFIRE(SolverControl & solver_control, + const AdditionalData &data = AdditionalData()); /** * Virtual destructor. diff --git a/tests/cuda/solver_06.cu b/tests/cuda/solver_06.cu new file mode 100644 index 0000000000..e8aa593338 --- /dev/null +++ b/tests/cuda/solver_06.cu @@ -0,0 +1,85 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Check that dealii::SolverFIRE works with CUDAWrappers::SparseMatrix + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "../testmatrix.h" +#include "../tests.h" + +void +test(Utilities::CUDA::Handle &cuda_handle) +{ + // Build the sparse matrix on the host + const unsigned int problem_size = 10; + unsigned int size = (problem_size - 1) * (problem_size - 1); + FDMatrix testproblem(problem_size, problem_size); + SparsityPattern structure(size, size, 5); + SparseMatrix A; + testproblem.five_point_structure(structure); + structure.compress(); + A.reinit(structure); + testproblem.five_point(A); + + // Solve on the host + PreconditionIdentity prec_no; + SolverControl control(10000, 1.e-3); + SolverFIRE<> fire_host(control); + Vector sol_host(size); + Vector rhs_host(size); + for (unsigned int i = 0; i < size; ++i) + rhs_host[i] = static_cast(i); + fire_host.solve(A, sol_host, rhs_host, prec_no); + + // Solve on the device + CUDAWrappers::SparseMatrix A_dev(cuda_handle, A); + LinearAlgebra::CUDAWrappers::Vector sol_dev(size); + LinearAlgebra::CUDAWrappers::Vector rhs_dev(size); + LinearAlgebra::ReadWriteVector rw_vector(size); + for (unsigned int i = 0; i < size; ++i) + rw_vector[i] = static_cast(i); + rhs_dev.import(rw_vector, VectorOperation::insert); + SolverFIRE> fire_dev(control); + fire_dev.solve(A_dev, sol_dev, rhs_dev, prec_no); + + // Check the result + rw_vector.import(sol_dev, VectorOperation::insert); + for (unsigned int i = 0; i < size; ++i) + AssertThrow(std::fabs(rw_vector[i] - sol_host[i]) < 1e-8, + ExcInternalError()); +} + +int +main() +{ + initlog(); + deallog.depth_console(0); + + Utilities::CUDA::Handle cuda_handle; + test(cuda_handle); + + deallog << "OK" << std::endl; + + return 0; +} diff --git a/tests/cuda/solver_06.output b/tests/cuda/solver_06.output new file mode 100644 index 0000000000..0626e5cb42 --- /dev/null +++ b/tests/cuda/solver_06.output @@ -0,0 +1,6 @@ + +DEAL:FIRE::Starting value 173880. +DEAL:FIRE::Convergence step 465 value 0.000927878 +DEAL:FIRE::Starting value 173880. +DEAL:FIRE::Convergence step 465 value 0.000927878 +DEAL::OK -- 2.39.5