22#ifndef OPM_ISTLSOLVER_WITH_GPUBRIDGE_HEADER_INCLUDED
23#define OPM_ISTLSOLVER_WITH_GPUBRIDGE_HEADER_INCLUDED
25#include <opm/simulators/linalg/ISTLSolver.hpp>
37template<
class Matrix,
class Vector,
int block_size>
class GpuBridge;
41template<
class Matrix,
class Vector>
44 using Scalar =
typename Vector::field_type;
48 GpuSolverInfo(
const std::string& accelerator_mode,
49 const int linear_solver_verbosity,
51 const Scalar tolerance,
54 const bool opencl_ilu_parallel,
55 const std::string& linsolver);
60 void prepare(
const Grid& grid,
62 const std::vector<Well>& wellsForConn,
63 const std::unordered_map<std::string, std::set<int>>& possibleFutureConnections,
64 const std::vector<int>& cellPartition,
65 const std::size_t nonzeroes,
66 const bool useWellConn);
68 bool apply(Vector& rhs,
69 const bool useWellConn,
70 WellContribFunc getContribs,
74 Dune::InverseOperatorResult& result);
78 int numJacobiBlocks_ = 0;
84 void blockJacobiAdjacency(
const Grid& grid,
85 const std::vector<int>& cell_part,
86 std::size_t nonzeroes);
88 void copyMatToBlockJac(
const Matrix& mat, Matrix& blockJac);
90 std::unique_ptr<Bridge> bridge_;
91 std::string accelerator_mode_;
92 std::unique_ptr<Matrix> blockJacobiForGPUILU0_;
93 std::vector<std::set<int>> wellConnectionsGraph_;
102template <
class TypeTag>
114 using Matrix =
typename SparseMatrixAdapter::IstlMatrix;
117 using AbstractSolverType = Dune::InverseOperator<Vector, Vector>;
118 using AbstractOperatorType = Dune::AssembledLinearOperator<Matrix, Vector, Vector>;
125 using CommunicationType = Dune::OwnerOverlapCopyCommunication<int,int>;
127 using CommunicationType = Dune::Communication<int>;
131 using AssembledLinearOperatorType = Dune::AssembledLinearOperator< Matrix, Vector, Vector >;
138 : ParentType(simulator, parameters)
146 : ParentType(simulator)
153 OPM_TIMEBLOCK(initializeGpu);
157 if ((this->simulator_.vanguard().grid().comm().size() > 1) && (accelerator_mode !=
"none")) {
158 const bool on_io_rank = (this->simulator_.gridView().
comm().rank() == 0);
160 OpmLog::warning(
"Cannot use AcceleratorMode feature with MPI, setting AcceleratorMode to 'none'.");
162 accelerator_mode =
"none";
165 if (accelerator_mode ==
"none") {
170 const int platformID = Parameters::Get<Parameters::OpenclPlatformId>();
171 const int deviceID = Parameters::Get<Parameters::GpuDeviceId>();
172 const int maxit = Parameters::Get<Parameters::LinearSolverMaxIter>();
173 const double tolerance = Parameters::Get<Parameters::LinearSolverReduction>();
174 const bool opencl_ilu_parallel = Parameters::Get<Parameters::OpenclIluParallel>();
175 const int linear_solver_verbosity = this->parameters_[0].linear_solver_verbosity_;
176 std::string linsolver = Parameters::Get<Parameters::LinearSolver>();
177 gpuBridge_ = std::make_unique<detail::GpuSolverInfo<Matrix,Vector>>(accelerator_mode,
178 linear_solver_verbosity,
190 [[maybe_unused]]
const bool firstcall = (this->matrix_ ==
nullptr);
195 ParentType::initPrepare(M,b);
200#if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
202 if (firstcall && gpuBridge_) {
208 gpuBridge_->prepare(this->simulator_.vanguard().grid(),
209 this->simulator_.vanguard().cartesianIndexMapper(),
210 this->simulator_.vanguard().schedule().getWellsatEnd(),
211 this->simulator_.vanguard().schedule().getPossibleFutureConnections(),
212 this->simulator_.vanguard().cellPartition(),
213 this->getMatrix().nonzeroes(), this->useWellConn_);
240 OPM_TIMEBLOCK(istlSolverGpuBridgeSolve);
241 this->solveCount_ += 1;
243 const int verbosity = this->prm_[this->activeSolverNum_].template get<int>(
"verbosity", 0);
244 const bool write_matrix = verbosity > 10;
246 Helper::writeSystem(this->simulator_,
253 Dune::InverseOperatorResult result;
258 this->simulator_.problem().wellModel().getWellContributions(w);
260 if (!gpuBridge_->apply(*(this->rhs_), this->useWellConn_, getContribs,
261 this->simulator_.gridView().comm().rank(),
262 const_cast<Matrix&
>(this->getMatrix()),
265 if(gpuBridge_->gpuActive()){
267 ParentType::prepareFlexibleSolver();
269 assert(this->flexibleSolver_[this->activeSolverNum_].solver_);
270 this->flexibleSolver_[this->activeSolverNum_].solver_->apply(x, *(this->rhs_), result);
274 return this->checkConvergence(result);
278 std::unique_ptr<detail::GpuSolverInfo<Matrix, Vector>> gpuBridge_;
Definition CollectDataOnIORank.hpp:49
Interface class adding the update() method to the preconditioner interface.
Definition PreconditionerWithUpdate.hpp:32
GpuBridge acts as interface between opm-simulators with the GpuSolvers.
Definition GpuBridge.hpp:37
void setMatrix(const SparseMatrixAdapter &)
Set the matrix for the solver.
Definition ISTLSolverGpuBridge.hpp:229
ISTLSolverGpuBridge(const Simulator &simulator, const FlowLinearSolverParameters ¶meters)
Construct a system solver.
Definition ISTLSolverGpuBridge.hpp:137
ISTLSolverGpuBridge(const Simulator &simulator)
Construct a system solver.
Definition ISTLSolverGpuBridge.hpp:145
bool solve(Vector &x)
Solve the system of equations Ax = b.
Definition ISTLSolverGpuBridge.hpp:234
void prepare(const Matrix &M, Vector &b)
Prepare the solver with the given matrix and right-hand side vector.
Definition ISTLSolverGpuBridge.hpp:187
void setResidual(Vector &)
Set the residual vector.
Definition ISTLSolverGpuBridge.hpp:219
void getResidual(Vector &b) const
Get the residual vector.
Definition ISTLSolverGpuBridge.hpp:224
ISTLSolver(const Simulator &simulator, const FlowLinearSolverParameters ¶meters, bool forceSerial=false)
Construct a system solver.
Definition ISTLSolver.hpp:194
void prepare(const SparseMatrixAdapter &M, Vector &b) override
Prepare the solver with the given sparse matrix and right-hand side vector.
Definition ISTLSolver.hpp:368
bool solve(Vector &x) override
Solve the system of equations Ax = b.
Definition ISTLSolver.hpp:407
const CommunicationType * comm() const override
Get the communication object used by the solver.
Definition ISTLSolver.hpp:448
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition WellContributions.hpp:51
Definition WellOperators.hpp:70
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition propertysystem.hh:233
auto Get(bool errorIfNotRegistered=true)
Retrieve a runtime parameter.
Definition parametersystem.hpp:187
This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
Definition FlowLinearSolverParameters.hpp:98