Moved amgcl declarations to header

This commit is contained in:
Tong Dong Qiu 2021-06-08 11:37:16 +02:00
parent 7c7911b9bc
commit 47e2899ba8
2 changed files with 38 additions and 41 deletions

View File

@ -27,19 +27,6 @@
#include <opm/simulators/linalg/bda/BdaResult.hpp>
#include <opm/simulators/linalg/bda/amgclSolverBackend.hpp>
#include <amgcl/backend/builtin.hpp>
#include <amgcl/backend/cuda.hpp>
#include <amgcl/relaxation/cusparse_ilu0.hpp>
#include <amgcl/adapter/crs_tuple.hpp>
#include <amgcl/make_block_solver.hpp>
#include <amgcl/relaxation/as_preconditioner.hpp>
#include <amgcl/relaxation/ilu0.hpp>
#include <amgcl/solver/bicgstab.hpp>
#include <amgcl/value_type/static_matrix.hpp>
#include <amgcl/adapter/block_matrix.hpp>
namespace bda
{
@ -75,6 +62,10 @@ void amgclSolverBackend<block_size>::initialize(int N_, int nnz_, int dim, doubl
rhs.resize(N);
x.resize(N);
#if AMGCL_CUDA
cusparseCreate(&bprm.cusparse_handle);
#endif
initialized = true;
} // end initialize()
@ -141,35 +132,7 @@ void amgclSolverBackend<block_size>::solve_system(double *b, WellContributions &
int iters = 0;
double error = 0.0;
#define AMGCL_CUDA 0
try {
#if AMGCL_CUDA
#if !HAVE_CUDA
#error "Error amgcl is trying to use CUDA, but CUDA was not found by CMake"
#endif
typedef amgcl::backend::cuda<double> Backend;
Backend::params bprm;
cusparseCreate(&bprm.cusparse_handle);
#else
typedef amgcl::static_matrix<double, block_size, block_size> dmat_type; // matrix value type in double precision
typedef amgcl::static_matrix<double, block_size, 1> dvec_type; // the corresponding vector value type
typedef amgcl::backend::builtin<dmat_type> Backend;
typename Backend::params bprm; // leave empty
#endif
// choose linear solver components
typedef amgcl::relaxation::as_preconditioner<Backend, amgcl::relaxation::ilu0> Precond;
typedef amgcl::solver::bicgstab<Backend> IterSolver;
#if AMGCL_CUDA
typedef amgcl::make_solver<Precond, IterSolver> Solver;
#else
typedef amgcl::make_block_solver<Precond, IterSolver> Solver;
#endif
// create matrix object
auto A = std::tie(N, A_rows, A_cols, A_vals);

View File

@ -27,6 +27,18 @@
#include <opm/simulators/linalg/bda/WellContributions.hpp>
#include <amgcl/amg.hpp>
#include <amgcl/backend/builtin.hpp>
#include <amgcl/backend/cuda.hpp>
#include <amgcl/relaxation/cusparse_ilu0.hpp>
#include <amgcl/adapter/crs_tuple.hpp>
#include <amgcl/make_block_solver.hpp>
#include <amgcl/relaxation/as_preconditioner.hpp>
#include <amgcl/relaxation/ilu0.hpp>
#include <amgcl/solver/bicgstab.hpp>
#include <amgcl/value_type/static_matrix.hpp>
#define AMGCL_CUDA 0
namespace bda
{
@ -49,6 +61,27 @@ class amgclSolverBackend : public BdaSolver<block_size>
using Base::tolerance;
using Base::initialized;
#if AMGCL_CUDA
#if !HAVE_CUDA
#error "Error amgcl is trying to use CUDA, but CUDA was not found by CMake"
#endif
typedef amgcl::backend::cuda<double> Backend;
#else
typedef amgcl::static_matrix<double, block_size, block_size> dmat_type; // matrix value type in double precision
typedef amgcl::static_matrix<double, block_size, 1> dvec_type; // the corresponding vector value type
typedef amgcl::backend::builtin<dmat_type> Backend;
#endif
// choose linear solver components
typedef amgcl::relaxation::as_preconditioner<Backend, amgcl::relaxation::ilu0> Precond;
typedef amgcl::solver::bicgstab<Backend> IterSolver;
#if AMGCL_CUDA
typedef amgcl::make_solver<Precond, IterSolver> Solver;
#else
typedef amgcl::make_block_solver<Precond, IterSolver> Solver;
#endif
private:
// store matrix in CSR format
std::vector<unsigned> A_rows, A_cols;
@ -56,6 +89,7 @@ private:
std::vector<double> x;
std::once_flag print_info;
typename Backend::params bprm; // amgcl backend parameters, only used for cusparseHandle
/// Initialize GPU and allocate memory
/// \param[in] N number of nonzeroes, divide by dim*dim to get number of blocks