GpuSolver.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_GPUSOLVER_BACKEND_HEADER_INCLUDED
21#define OPM_GPUSOLVER_BACKEND_HEADER_INCLUDED
22
23
26
27#include <memory>
28
29namespace Opm {
30
31template<class Scalar> class WellContributions;
32
33namespace Accelerator {
34
35enum class SolverStatus {
40};
41
44template<class Scalar, unsigned int block_size>
46{
47protected:
48 // verbosity
49 // 0: print nothing during solves, only when initializing
50 // 1: print number of iterations and final norm
51 // 2: also print norm each iteration
52 // 3: also print timings of different backend functions
53 int verbosity = 0;
54
55 int maxit = 200;
56 Scalar tolerance = 1e-2;
57
58 int N; // number of rows
59 int Nb; // number of blocked rows (Nb*block_size == N)
60 int nnz; // number of nonzeroes (scalars)
61 int nnzb; // number of nonzero blocks (nnzb*block_size*block_size == nnz)
62
63 unsigned int platformID = 0; // ID of OpenCL platform to be used, only used by openclSolver now
64 unsigned int deviceID = 0; // ID of the device to be used
65
66 bool initialized = false;
67
68public:
75 GpuSolver(int linear_solver_verbosity, int max_it, Scalar tolerance_)
76 : verbosity(linear_solver_verbosity)
77 , maxit(max_it)
78 , tolerance(tolerance_)
79 {}
80 GpuSolver(int linear_solver_verbosity, int max_it,
81 Scalar tolerance_, unsigned int deviceID_)
82 : verbosity(linear_solver_verbosity)
83 , maxit(max_it)
84 , tolerance(tolerance_)
85 , deviceID(deviceID_) {};
86 GpuSolver(int linear_solver_verbosity, int max_it,
87 double tolerance_, unsigned int platformID_,
88 unsigned int deviceID_)
89 : verbosity(linear_solver_verbosity)
90 , maxit(max_it)
91 , tolerance(tolerance_)
92 , platformID(platformID_)
93 , deviceID(deviceID_)
94 {}
95
97 virtual ~GpuSolver() = default;
98
100 virtual SolverStatus solve_system(std::shared_ptr<BlockedMatrix<Scalar>> matrix,
101 Scalar* b,
102 std::shared_ptr<BlockedMatrix<Scalar>> jacMatrix,
103 WellContributions<Scalar>& wellContribs,
104 GpuResult& res) = 0;
105
106 virtual void get_result(Scalar* x) = 0;
107}; // end class GpuSolver
108
109} // namespace Accelerator
110} // namespace Opm
111
112#endif
Definition: BlockedMatrix.hpp:29
Definition: GpuResult.hpp:31
Definition: GpuSolver.hpp:46
virtual ~GpuSolver()=default
Define virtual destructor, so that the derivedclass destructor will be called.
int nnzb
Definition: GpuSolver.hpp:61
unsigned int platformID
Definition: GpuSolver.hpp:63
unsigned int deviceID
Definition: GpuSolver.hpp:64
GpuSolver(int linear_solver_verbosity, int max_it, Scalar tolerance_, unsigned int deviceID_)
Definition: GpuSolver.hpp:80
Scalar tolerance
Definition: GpuSolver.hpp:56
GpuSolver(int linear_solver_verbosity, int max_it, double tolerance_, unsigned int platformID_, unsigned int deviceID_)
Definition: GpuSolver.hpp:86
bool initialized
Definition: GpuSolver.hpp:66
virtual SolverStatus solve_system(std::shared_ptr< BlockedMatrix< Scalar > > matrix, Scalar *b, std::shared_ptr< BlockedMatrix< Scalar > > jacMatrix, WellContributions< Scalar > &wellContribs, GpuResult &res)=0
Define as pure virtual functions, so derivedclass must implement them.
int maxit
Definition: GpuSolver.hpp:55
int N
Definition: GpuSolver.hpp:58
int verbosity
Definition: GpuSolver.hpp:53
virtual void get_result(Scalar *x)=0
int nnz
Definition: GpuSolver.hpp:60
int Nb
Definition: GpuSolver.hpp:59
GpuSolver(int linear_solver_verbosity, int max_it, Scalar tolerance_)
Definition: GpuSolver.hpp:75
Definition: WellContributions.hpp:51
SolverStatus
Definition: GpuSolver.hpp:35
Definition: blackoilboundaryratevector.hh:39