54 using typename Dune::IterativeSolver<X, X>::domain_type;
55 using typename Dune::IterativeSolver<X, X>::range_type;
56 using typename Dune::IterativeSolver<X, X>::field_type;
57 using typename Dune::IterativeSolver<X, X>::real_type;
58 using typename Dune::IterativeSolver<X, X>::scalar_real_type;
59 static constexpr auto block_size = domain_type::block_type::dimension;
76 Dune::ScalarProduct<X>&
sp,
77 std::shared_ptr<Dune::Preconditioner<X, X>> prec,
82 : Dune::IterativeSolver<X, X>(
op,
sp, *prec, reduction, maxit,
verbose)
83 , m_opOnCPUWithMatrix(
op)
85 , m_underlyingSolver(constructSolver(prec, reduction, maxit,
verbose, comm))
89 "Currently we only support operators of type MatrixAdapter in the CUDA/HIP solver. "
90 "Use --matrix-add-well-contributions=true. "
91 "Using WellModelMatrixAdapter with SolverAdapter is not well-defined so it will not work well, or at all.");
94 virtual void apply(X& x, X&
b,
double reduction, Dune::InverseOperatorResult&
res)
override
100 if (!m_inputBuffer) {
101 m_inputBuffer.reset(
new XGPU(
b.dim()));
102 m_outputBuffer.reset(
new XGPU(x.dim()));
105 m_inputBuffer->copyFromHost(
b);
107 m_outputBuffer->copyFromHost(x);
109 m_underlyingSolver.apply(*m_outputBuffer, *m_inputBuffer, reduction,
res);
112 m_inputBuffer->copyToHost(
b);
113 m_outputBuffer->copyToHost(x);
115 virtual void apply(X& x, X&
b, Dune::InverseOperatorResult&
res)
override
120 if (!m_inputBuffer) {
121 m_inputBuffer.reset(
new XGPU(
b.dim()));
122 m_outputBuffer.reset(
new XGPU(x.dim()));
125 m_inputBuffer->copyFromHost(
b);
127 m_outputBuffer->copyFromHost(x);
129 m_underlyingSolver.apply(*m_outputBuffer, *m_inputBuffer,
res);
132 m_inputBuffer->copyToHost(
b);
133 m_outputBuffer->copyToHost(x);
137 Operator& m_opOnCPUWithMatrix;
138 GpuSparseMatrixWrapper<real_type> m_matrix;
146 template <
class Comm>
151 const Comm& communication)
157 auto precAsHolder = std::dynamic_pointer_cast<PreconditionerHolder<X, X>>(prec);
160 "The preconditioner needs to be a CUDA preconditioner (eg. GPUDILU) wrapped in a "
161 "Opm::gpuistl::PreconditionerAdapter wrapped in a "
162 "Opm::gpuistl::GpuBlockPreconditioner. If you are unsure what this means, set "
163 "preconditioner to 'gpudilu'");
171 "The preconditioner needs to be a CUDA preconditioner (eg. GPUDILU) wrapped in a "
172 "Opm::gpuistl::PreconditionerAdapter wrapped in a "
173 "Opm::gpuistl::GpuBlockPreconditioner. If you are unsure what this means, set "
174 "preconditioner to 'gpudilu'");
182 = Dune::OverlappingSchwarzOperator<GpuSparseMatrixWrapper<real_type>, XGPU, XGPU,
CudaCommunication>;
185 auto mpiPreconditioner = std::make_shared<GpuBlockPreconditioner<XGPU, XGPU, CudaCommunication>>(
188 auto scalarProduct = std::make_shared<Dune::ParallelScalarProduct<XGPU, CudaCommunication>>(
209 [[
maybe_unused]]
const Dune::Amg::SequentialInformation& communication)
212 return constructSolver(prec, reduction, maxit,
verbose);
225 auto precAsHolder = std::dynamic_pointer_cast<PreconditionerHolder<XGPU, XGPU>>(prec);
228 "The preconditioner needs to be a CUDA preconditioner wrapped in a "
229 "Opm::gpuistl::PreconditionerHolder (eg. GPUDILU).");
233 auto matrixOperator = std::make_shared<Dune::MatrixAdapter<GpuSparseMatrixWrapper<real_type>, XGPU, XGPU>>(m_matrix);
234 auto scalarProduct = std::make_shared<Dune::SeqScalarProduct<XGPU>>();
238 std::unique_ptr<XGPU> m_inputBuffer;
239 std::unique_ptr<XGPU> m_outputBuffer;
SolverAdapter(Operator &op, Dune::ScalarProduct< X > &sp, std::shared_ptr< Dune::Preconditioner< X, X > > prec, scalar_real_type reduction, int maxit, int verbose, const Comm &comm)
constructor
Definition SolverAdapter.hpp:75