BILU0.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 BILU0_HPP
21#define BILU0_HPP
22
23#include <mutex>
24
26
30
31
32namespace Opm
33{
34namespace Accelerator
35{
36
40template <unsigned int block_size>
41class BILU0 : public Preconditioner<block_size>
42{
44
45 using Base::N;
46 using Base::Nb;
47 using Base::nnz;
48 using Base::nnzb;
49 using Base::verbosity;
50 using Base::context;
51 using Base::queue;
52 using Base::events;
53 using Base::err;
54
55private:
56 std::unique_ptr<BlockedMatrix> LUmat = nullptr;
57#if CHOW_PATEL
58 std::unique_ptr<BlockedMatrix> Lmat = nullptr, Umat = nullptr;
59#endif
60 std::vector<double> invDiagVals;
61 std::vector<int> diagIndex;
62 std::vector<int> rowsPerColor; // color i contains rowsPerColor[i] rows, which are processed in parallel
63 std::vector<int> rowsPerColorPrefix; // the prefix sum of rowsPerColor
64 std::vector<int> toOrder, fromOrder;
65 int numColors;
66 std::once_flag pattern_uploaded;
67
68 bool opencl_ilu_parallel;
69
70 typedef struct {
71 cl::Buffer invDiagVals; // nnz values of diagonal blocks of the matrix, inverted
72 cl::Buffer diagIndex; // index of diagonal block of each row, used to differentiate between lower and upper triangular part
73 cl::Buffer rowsPerColor; // number of rows for every color
74 cl::Buffer rowIndices; // mapping every row to another index
75 // after mapping, all rows that are processed in parallel are contiguous
76 // equal to the contents of fromOrder
77#if CHOW_PATEL
78 cl::Buffer Lvals, Lcols, Lrows;
79 cl::Buffer Uvals, Ucols, Urows;
80#else
81 cl::Buffer LUvals, LUcols, LUrows;
82#endif
83 } GPU_storage;
84
85 GPU_storage s;
86
87#if CHOW_PATEL
88 ChowPatelIlu<block_size> chowPatelIlu;
89#endif
90
91public:
92
93 BILU0(bool opencl_ilu_parallel, int verbosity);
94
95 // analysis, extract parallelism if specified
96 bool analyze_matrix(BlockedMatrix *mat) override;
97 bool analyze_matrix(BlockedMatrix *mat, BlockedMatrix *jacMat) override;
98
99 // ilu_decomposition
102
103 // apply preconditioner, x = prec(y)
104 // via Lz = y
105 // and Ux = z
106 void apply(const cl::Buffer& y, cl::Buffer& x) override;
107
108 std::tuple<std::vector<int>, std::vector<int>, std::vector<int>> get_preconditioner_structure()
109 {
110 return {{LUmat->rowPointers, LUmat->rowPointers + (Nb + 1)}, {LUmat->colIndices, LUmat->colIndices + nnzb}, diagIndex};
111 }
112
113 std::pair<cl::Buffer, cl::Buffer> get_preconditioner_data()
114 {
115#if CHOW_PATEL
116 return std::make_pair(s.Lvals, s.invDiagVals); // send dummy, BISAI is disabled when ChowPatel is selected
117#else
118 return std::make_pair(s.LUvals, s.invDiagVals);
119#endif
120 }
121};
122
123} // namespace Accelerator
124} // namespace Opm
125
126#endif
127
Definition: BILU0.hpp:42
bool analyze_matrix(BlockedMatrix *mat) override
BILU0(bool opencl_ilu_parallel, int verbosity)
bool create_preconditioner(BlockedMatrix *mat, BlockedMatrix *jacMat) override
std::tuple< std::vector< int >, std::vector< int >, std::vector< int > > get_preconditioner_structure()
Definition: BILU0.hpp:108
std::pair< cl::Buffer, cl::Buffer > get_preconditioner_data()
Definition: BILU0.hpp:113
void apply(const cl::Buffer &y, cl::Buffer &x) override
bool analyze_matrix(BlockedMatrix *mat, BlockedMatrix *jacMat) override
bool create_preconditioner(BlockedMatrix *mat) override
Definition: BlockedMatrix.hpp:31
Definition: Preconditioner.hpp:36
int nnz
Definition: Preconditioner.hpp:41
std::vector< cl::Event > events
Definition: Preconditioner.hpp:47
std::shared_ptr< cl::CommandQueue > queue
Definition: Preconditioner.hpp:46
int N
Definition: Preconditioner.hpp:39
int verbosity
Definition: Preconditioner.hpp:43
cl_int err
Definition: Preconditioner.hpp:48
int Nb
Definition: Preconditioner.hpp:40
std::shared_ptr< cl::Context > context
Definition: Preconditioner.hpp:45
int nnzb
Definition: Preconditioner.hpp:42
Definition: BlackoilPhases.hpp:27