9#include <kernel/solver/base.hpp>
10#include <kernel/lafem/sparse_matrix_csr.hpp>
11#include <kernel/lafem/sparse_matrix_bcsr.hpp>
23 int cuda_ilu_apply(
double * y,
const double * x,
const double * csrVal,
const int * csrRowPtr,
const int * csrColInd,
void * vinfo);
24 void * cuda_ilu_init_symbolic(
int m,
int nnz,
double * csrVal,
const int * csrRowPtr,
const int * csrColInd);
25 void cuda_ilu_init_numeric(
double * csrVal,
const int * csrRowPtr,
const int * csrColInd,
void * vinfo);
26 void cuda_ilu_done_symbolic(
void * vinfo);
28 int cuda_ilub_apply(
double * y,
const double * x,
const double * csrVal,
const int * csrRowPtr,
const int * csrColInd,
void * vinfo);
29 void * cuda_ilub_init_symbolic(
int m,
int nnz,
double * csrVal,
const int * csrRowPtr,
const int * csrColInd,
const int blocksize);
30 void cuda_ilub_init_numeric(
double * csrVal,
const int * csrRowPtr,
const int * csrColInd,
void * vinfo);
31 void cuda_ilub_done_symbolic(
void * vinfo);
44 template<
typename IT_>
51 std::vector<IT_> _row_ptr_l, _col_idx_l;
53 std::vector<IT_> _row_ptr_u, _col_idx_u;
70 IT_ get_nnze_l()
const
72 return _row_ptr_l.empty() ? IT_(0) : _row_ptr_l.back();
76 IT_ get_nnze_u()
const
78 return _row_ptr_u.empty() ? IT_(0) : _row_ptr_u.back();
84 return _n + get_nnze_l() + get_nnze_u();
88 std::size_t bytes_symbolic()
const
90 return sizeof(IT_) * (_row_ptr_l.size() + _row_ptr_u.size() + _col_idx_l.size() + _col_idx_u.size());
105 void set_struct_csr(
const IT_ n,
const IT_* row_ptr_a,
const IT_* col_idx_a)
110 const IT_ nzul = (Math::max(row_ptr_a[n], n) - n) / IT_(2);
120 _row_ptr_l.reserve(n+1);
121 _row_ptr_u.reserve(n+1);
122 _col_idx_l.reserve(nzul);
123 _col_idx_u.reserve(nzul);
126 _row_ptr_l.push_back(0);
127 _row_ptr_u.push_back(0);
130 for(IT_ i(0); i < n; ++i)
132 IT_ j = row_ptr_a[i];
133 const IT_ jend = row_ptr_a[i+1];
134 for(; (j < jend) && (col_idx_a[j] < i); ++j)
136 _col_idx_l.push_back(col_idx_a[j]);
138 if(col_idx_a[j] != i)
139 throw InvalidMatrixStructureException();
140 for(++j; j < jend; ++j)
142 _col_idx_u.push_back(col_idx_a[j]);
144 _row_ptr_l.push_back(IT_(_col_idx_l.size()));
145 _row_ptr_u.push_back(IT_(_col_idx_u.size()));
158 template<
typename DT_>
159 void set_struct(
const LAFEM::SparseMatrixCSR<DT_, IT_>& matrix)
161 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
162 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
163 this->set_struct_csr(IT_(matrix.num_rows()), row_ptr.get_r(), col_idx.get_r());
172 template<
typename DT_,
int m_,
int n_>
173 void set_struct(
const LAFEM::SparseMatrixBCSR<DT_, IT_, m_, n_>& matrix)
175 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
176 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
177 this->set_struct_csr(IT_(matrix.num_rows()), row_ptr.get_r(), col_idx.get_r());
194 void factorize_symbolic(
const int p)
200 std::vector<IT_> new_ptr_l, new_idx_l, new_ptr_u, new_idx_u;
203 std::vector<int> new_lvl_l, new_lvl_u;
206 new_ptr_l.push_back(IT_(0));
207 new_ptr_u.push_back(IT_(0));
210 for(IT_ i(0); i < _n; ++i)
213 for(IT_ j(_row_ptr_l[i]); j < _row_ptr_l[i+1]; ++j)
215 new_idx_l.push_back(_col_idx_l[j]);
216 new_lvl_l.push_back(0);
218 for(IT_ j(_row_ptr_u[i]); j < _row_ptr_u[i+1]; ++j)
220 new_idx_u.push_back(_col_idx_u[j]);
221 new_lvl_u.push_back(0);
225 for(IT_ j(new_ptr_l[i]); j < IT_(new_idx_l.size()); ++j)
228 const IT_ cj = new_idx_l[j];
229 const int lj = new_lvl_l[j];
231 IT_ ouj = new_ptr_u[i];
234 for(IT_ k(new_ptr_u[cj]); k < new_ptr_u[cj+1]; ++k)
237 const IT_ ck = new_idx_u[k];
238 const int lk = new_lvl_u[k];
241 const int ll = lj + lk + 1;
247 olj = _insert(new_idx_l, new_lvl_l, olj, ck, ll);
249 ouj = _insert(new_idx_u, new_lvl_u, ouj, ck, ll);
254 new_ptr_l.push_back(IT_(new_idx_l.size()));
255 new_ptr_u.push_back(IT_(new_idx_u.size()));
259 _row_ptr_l = std::move(new_ptr_l);
260 _col_idx_l = std::move(new_idx_l);
261 _row_ptr_u = std::move(new_ptr_u);
262 _col_idx_u = std::move(new_idx_u);
293 static IT_ _insert(std::vector<IT_>& idx, std::vector<int>& lvl, IT_ i,
const IT_ j,
const int l)
296 IT_ n = IT_(idx.size());
321 idx.push_back(IT_(0));
325 for(IT_ k(n); k > i; --k)
353 template<
typename DT_,
typename IT_>
354 class ILUCoreScalar :
355 public ILUCoreSymbolic<IT_>
358 typedef ILUCoreSymbolic<IT_> BaseClass;
361 std::vector<DT_> _data_l, _data_u, _data_d;
377 _data_d.resize(this->_n);
378 _data_l.resize(this->_col_idx_l.size());
379 _data_u.resize(this->_col_idx_u.size());
383 std::size_t bytes_numeric()
const
385 return sizeof(DT_) * (_data_l.size() + _data_u.size() + _data_d.size());
389 std::size_t bytes()
const
391 return this->bytes_numeric() + this->bytes_symbolic();
406 void copy_data_csr(
const IT_* row_ptr_a,
const IT_* col_idx_a,
const DT_* data_a)
409 for(IT_ i(0); i < this->_n; ++i)
412 IT_ ra = row_ptr_a[i];
413 IT_ xa = row_ptr_a[i+1];
416 for(IT_ j(this->_row_ptr_l[i]); j < this->_row_ptr_l[i+1]; ++j)
418 if(this->_col_idx_l[j] == col_idx_a[ra])
419 _data_l[j] = data_a[ra++];
425 _data_d[i] = data_a[ra++];
428 for(IT_ j(this->_row_ptr_u[i]); j < this->_row_ptr_u[i+1]; ++j)
430 if((ra < xa) && (this->_col_idx_u[j] == col_idx_a[ra]))
431 _data_u[j] = data_a[ra++];
444 void copy_data(
const LAFEM::SparseMatrixCSR<DT_, IT_>& matrix)
446 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
447 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
448 const Memory::TypedView<DT_> mat_val = matrix.val_view_r();
449 this->copy_data_csr(row_ptr.get_r(), col_idx.get_r(), mat_val.get_r());
458 void factorize_numeric_il_du()
461 const IT_* rptr_l = this->_row_ptr_l.data();
462 const IT_* rptr_u = this->_row_ptr_u.data();
463 const IT_* cidx_l = (this->_col_idx_l.empty() ? nullptr : this->_col_idx_l.data());
464 const IT_* cidx_u = (this->_col_idx_u.empty() ? nullptr : this->_col_idx_u.data());
465 DT_* data_l = (this->_data_l.empty() ? nullptr : this->_data_l.data());
466 DT_* data_u = (this->_data_u.empty() ? nullptr : this->_data_u.data());
467 DT_* data_d = this->_data_d.data();
470 for(IT_ i(0); i < this->_n; ++i)
473 const IT_ ql = rptr_l[i+1];
474 const IT_ qu = rptr_u[i+1];
477 for(IT_ j(rptr_l[i]); j < rptr_l[i+1]; ++j)
480 const IT_ cj = cidx_l[j];
487 data_l[j] *= data_d[cj];
491 for(; k < rptr_u[cj+1]; ++k)
493 const IT_ ck = cidx_u[k];
496 for(; (pl < ql) && (cidx_l[pl] <= ck); ++pl)
499 data_l[pl] -= data_l[j] * data_u[k];
504 if((k < rptr_u[cj+1]) && (cidx_u[k] == i))
506 data_d[i] -= data_l[j] * data_u[k];
510 for(; k < rptr_u[cj+1]; ++k)
512 const IT_ ck = cidx_u[k];
513 for(; (pu < qu) && (cidx_u[pu] <= ck); ++pu)
516 data_u[pu] -= data_l[j] * data_u[k];
522 data_d[i] = DT_(1) / data_d[i];
538 void solve_il(DT_* x,
const DT_* b)
const
541 const IT_* rptr = this->_row_ptr_l.data();
542 const IT_* cidx = (this->_col_idx_l.empty() ? nullptr : this->_col_idx_l.data());
543 const DT_* data_l = (this->_data_l.empty() ? nullptr : this->_data_l.data());
545 for(IT_ i(0); i < this->_n; ++i)
548 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
550 r -= data_l[j] * x[cidx[j]];
568 void solve_du(DT_* x,
const DT_* b)
const
570 const IT_* rptr = this->_row_ptr_u.data();
571 const IT_* cidx = (this->_col_idx_u.empty() ? nullptr : this->_col_idx_u.data());
572 const DT_* data_u = (this->_data_u.empty() ? nullptr : this->_data_u.data());
573 const DT_* data_d = this->_data_d.data();
575 for(IT_ i(this->_n); i > IT_(0); )
579 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
581 r -= data_u[j] * x[cidx[j]];
583 x[i] = data_d[i] * r;
599 void solve_ilt(DT_* x,
const DT_* b)
const
601 const IT_* rptr = this->_row_ptr_l.data();
602 const IT_* cidx = (this->_col_idx_l.empty() ? nullptr : this->_col_idx_l.data());
603 const DT_* data_l = (this->_data_l.empty() ? nullptr : this->_data_l.data());
607 for(IT_ i(0); i < this->_n; ++i)
611 for(IT_ i(this->_n); i > IT_(0); )
614 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
617 x[cidx[j]] -= data_l[j] * x[i];
634 void solve_dut(DT_* x,
const DT_* b)
const
636 const IT_* rptr = this->_row_ptr_u.data();
637 const IT_* cidx = (this->_col_idx_u.empty() ? nullptr : this->_col_idx_u.data());
638 const DT_* data_u = (this->_data_u.empty() ? nullptr : this->_data_u.data());
639 const DT_* data_d = this->_data_d.data();
643 for(IT_ i(0); i < this->_n; ++i)
647 for(IT_ i(0); i < this->_n; ++i)
650 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
653 x[cidx[j]] -= data_u[j] * x[i];
675 template<
typename DT_,
typename IT_,
int dim_>
676 class ILUCoreBlocked :
677 public ILUCoreSymbolic<IT_>
680 typedef ILUCoreSymbolic<IT_> BaseClass;
682 static_assert(dim_ > 0,
"invalid block dimension");
684 typedef Tiny::Matrix<DT_, dim_, dim_> MatBlock;
685 typedef Tiny::Vector<DT_, dim_> VecBlock;
688 std::vector<MatBlock> _data_l, _data_u, _data_d;
704 _data_d.resize(this->_n);
705 _data_l.resize(this->_col_idx_l.size());
706 _data_u.resize(this->_col_idx_u.size());
710 std::size_t bytes_numeric()
const
712 return sizeof(DT_) * std::size_t(Math::sqr(dim_)) * (_data_l.size() + _data_u.size() + _data_d.size());
716 std::size_t bytes()
const
718 return this->bytes_numeric() + this->bytes_symbolic();
733 void copy_data_bcsr(
const IT_* row_ptr_a,
const IT_* col_idx_a,
const MatBlock* data_a)
736 for(IT_ i(0); i < this->_n; ++i)
739 IT_ ra = row_ptr_a[i];
740 IT_ xa = row_ptr_a[i+1];
743 for(IT_ j(this->_row_ptr_l[i]); j < this->_row_ptr_l[i+1]; ++j)
745 if(this->_col_idx_l[j] == col_idx_a[ra])
746 _data_l[j] = data_a[ra++];
752 _data_d[i] = data_a[ra++];
755 for(IT_ j(this->_row_ptr_u[i]); j < this->_row_ptr_u[i+1]; ++j)
757 if((ra < xa) && (this->_col_idx_u[j] == col_idx_a[ra]))
758 _data_u[j] = data_a[ra++];
771 void copy_data(
const LAFEM::SparseMatrixBCSR<DT_, IT_, dim_, dim_>& matrix)
773 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
774 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
775 const Memory::TypedView<MatBlock> mat_val = matrix.val_view_r();
776 this->copy_data_bcsr(row_ptr.get_r(), col_idx.get_r(), mat_val.get_r());
785 void factorize_numeric_il_du()
788 const IT_* rptr_l = this->_row_ptr_l.data();
789 const IT_* rptr_u = this->_row_ptr_u.data();
790 const IT_* cidx_l = (this->_col_idx_l.empty() ? nullptr : this->_col_idx_l.data());
791 const IT_* cidx_u = (this->_col_idx_u.empty() ? nullptr : this->_col_idx_u.data());
792 MatBlock* data_l = (this->_data_l.empty() ? nullptr : this->_data_l.data());
793 MatBlock* data_u = (this->_data_u.empty() ? nullptr : this->_data_u.data());
794 MatBlock* data_d = this->_data_d.data();
797 for(IT_ i(0); i < this->_n; ++i)
800 const IT_ ql = rptr_l[i+1];
801 const IT_ qu = rptr_u[i+1];
804 for(IT_ j(rptr_l[i]); j < rptr_l[i+1]; ++j)
807 const IT_ cj = cidx_l[j];
816 const MatBlock l_ij(data_l[j]);
817 data_l[j].set_mat_mat_mult(data_d[cj], l_ij);
822 for(; k < rptr_u[cj+1]; ++k)
824 const IT_ ck = cidx_u[k];
827 for(; (pl < ql) && (cidx_l[pl] <= ck); ++pl)
831 data_l[pl].add_mat_mat_mult(data_l[j], data_u[k], -DT_(1));
836 if((k < rptr_u[cj+1]) && (cidx_u[k] == i))
839 data_d[i].add_mat_mat_mult(data_l[j], data_u[k], -DT_(1));
844 for(; k < rptr_u[cj+1]; ++k)
846 const IT_ ck = cidx_u[k];
847 for(; (pu < qu) && (cidx_u[pu] <= ck); ++pu)
851 data_u[pu].add_mat_mat_mult(data_l[j], data_u[k], -DT_(1));
859 const MatBlock d_ii(data_d[i]);
860 data_d[i].set_inverse(d_ii);
877 void solve_il(VecBlock* x,
const VecBlock* b)
const
879 const IT_* rptr = this->_row_ptr_l.data();
880 const IT_* cidx = (this->_col_idx_l.empty() ? nullptr : this->_col_idx_l.data());
881 const MatBlock* data_l = (this->_data_l.empty() ? nullptr : this->_data_l.data());
883 for(IT_ i(0); i < this->_n; ++i)
886 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
889 r.add_mat_vec_mult(data_l[j], x[cidx[j]], -DT_(1));
907 void solve_du(VecBlock* x,
const VecBlock* b)
const
909 const IT_* rptr = this->_row_ptr_u.data();
910 const IT_* cidx = (this->_col_idx_u.empty() ? nullptr : this->_col_idx_u.data());
911 const MatBlock* data_u = (this->_data_u.empty() ? nullptr : this->_data_u.data());
912 const MatBlock* data_d = this->_data_d.data();
914 for(IT_ i(this->_n); i > IT_(0); )
918 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
921 r.add_mat_vec_mult(data_u[j], x[cidx[j]], -DT_(1));
924 x[i].set_mat_vec_mult(data_d[i], r);
945 template<
typename Matrix_>
949 typedef typename Matrix_::DataType DataType;
950 typedef typename Matrix_::VectorTypeL VectorType;
952 virtual void set_fill_in_param(
int p) = 0;
954 virtual void init_symbolic() = 0;
956 virtual void done_symbolic() = 0;
958 virtual void init_numeric() = 0;
960 virtual String name()
const = 0;
962 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def) = 0;
975 template<PreferredBackend backend_,
typename Matrix_,
typename Filter_>
985 template<
typename DT_,
typename IT_,
typename Filter_>
991 typedef DT_ DataType;
992 typedef IT_ IndexType;
993 typedef Filter_ FilterType;
998 const FilterType& _filter;
999 Intern::ILUCoreScalar<DataType, IndexType> _ilu;
1020 const MatrixType& matrix,
const FilterType& filter) :
1025 auto fill_in_param_p = section->
query(
"fill_in_param");
1026 if(fill_in_param_p.second && !fill_in_param_p.first.parse(_p))
1027 throw ParseError(section_name +
".fill_in_param", fill_in_param_p.first,
"a non-negative integer");
1055 virtual void init_symbolic()
override
1059 XABORTM(
"Matrix is not square!");
1063 _ilu.set_struct(_matrix);
1066 _ilu.factorize_symbolic(_p);
1072 virtual void done_symbolic()
override
1077 virtual void init_numeric()
override
1079 _ilu.copy_data(_matrix);
1080 _ilu.factorize_numeric_il_du();
1108 this->_filter.filter_cor(out);
1111 Statistics::add_time_precon(ts_stop.
elapsed(ts_start));
1123 template<
typename DT_,
typename IT_,
int dim_,
typename Filter_>
1125 public ILUPrecondBase<typename LAFEM::SparseMatrixBCSR<DT_, IT_, dim_, dim_>>
1129 typedef DT_ DataType;
1130 typedef IT_ IndexType;
1131 typedef Filter_ FilterType;
1136 const FilterType& _filter;
1137 Intern::ILUCoreBlocked<DataType, IndexType, dim_> _ilu;
1158 const MatrixType& matrix,
const FilterType& filter) :
1163 auto fill_in_param_p = section->
query(
"fill_in_param");
1164 if(fill_in_param_p.second && !fill_in_param_p.first.parse(_p))
1165 throw ParseError(section_name +
".fill_in_param", fill_in_param_p.first,
"a non-negative integer");
1193 virtual void init_symbolic()
override
1197 XABORTM(
"Matrix is not square!");
1201 _ilu.set_struct(_matrix);
1204 _ilu.factorize_symbolic(_p);
1210 virtual void done_symbolic()
override
1215 virtual void init_numeric()
override
1217 _ilu.copy_data(_matrix);
1218 _ilu.factorize_numeric_il_du();
1246 this->_filter.filter_cor(out);
1249 Statistics::add_time_precon(ts_stop.
elapsed(ts_start));
1256#ifdef FEAT_HAVE_CUDA
1270 template<
typename Filter_>
1272 public ILUPrecondBase<LAFEM::SparseMatrixCSR<double, unsigned int>>
1276 typedef Filter_ FilterType;
1277 typedef typename MatrixType::VectorTypeL VectorType;
1278 typedef typename MatrixType::DataType DataType;
1281 const MatrixType& _matrix;
1282 MatrixType _lu_matrix;
1283 const FilterType& _filter;
1298 explicit ILUPrecondWithBackend(
const MatrixType& matrix,
const FilterType& filter,
const int = 0) :
1304 explicit ILUPrecondWithBackend(
const String& DOXY(section_name),
const PropertyMap* section,
1305 const MatrixType& matrix,
const FilterType& filter) :
1310 auto fill_in_param_p = section->query(
"fill_in_param");
1311 if(fill_in_param_p.second)
1313 XASSERTM(std::stoi(fill_in_param_p.first) == 0,
"For PreferredBackend::cuda, the fill in parameter has to be == 0!");
1320 virtual ~ILUPrecondWithBackend()
1330 virtual void set_fill_in_param(
int p)
override
1332 XASSERTM(p == 0,
"For PreferredBackend::cuda, the fill in parameter has to be == 0!");
1336 virtual String name()
const override
1341 virtual void init_symbolic()
override
1343 if (_matrix.num_cols() != _matrix.num_rows())
1345 XABORTM(
"Matrix is not square!");
1352 Memory::TypedView<int> row_ptr(std::forward<Memory::View&&>(_lu_matrix.row_ptr_view_r(
Memory::Location::cuda)));
1353 Memory::TypedView<int> col_idx(std::forward<Memory::View&&>(_lu_matrix.col_idx_view_r(
Memory::Location::cuda)));
1354 cuda_info = Intern::cuda_ilu_init_symbolic((
int)_lu_matrix.num_rows(), (
int)_lu_matrix.num_nzes(),
1355 a.get_w(), row_ptr.get_r(), col_idx.get_r());
1358 virtual void done_symbolic()
override
1360 Intern::cuda_ilu_done_symbolic(cuda_info);
1363 virtual void init_numeric()
override
1365 _lu_matrix.copy(_matrix);
1369 Memory::TypedView<int> row_ptr(std::forward<Memory::View&&>(_lu_matrix.row_ptr_view_r(
Memory::Location::cuda)));
1370 Memory::TypedView<int> col_idx(std::forward<Memory::View&&>(_lu_matrix.col_idx_view_r(
Memory::Location::cuda)));
1371 Intern::cuda_ilu_init_numeric(a.get_w(), row_ptr.get_r(), col_idx.get_r(), cuda_info);
1374 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
1376 XASSERTM(_matrix.num_rows() == vec_cor.size(),
"matrix / vector size mismatch!");
1377 XASSERTM(_matrix.num_rows() == vec_def.size(),
"matrix / vector size mismatch!");
1387 Memory::TypedView<int> row_ptr(std::forward<Memory::View&&>(_lu_matrix.row_ptr_view_r(
Memory::Location::cuda)));
1388 Memory::TypedView<int> col_idx(std::forward<Memory::View&&>(_lu_matrix.col_idx_view_r(
Memory::Location::cuda)));
1390 status = Intern::cuda_ilu_apply(vx.get_w(), vb.get_r(), a.get_r(), row_ptr.get_r(), col_idx.get_r(), cuda_info);
1393 this->_filter.filter_cor(vec_cor);
1396 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
1489 template<
typename Filter_,
int blocksize_>
1490 class ILUPrecondWithBackend<
PreferredBackend::
cuda, LAFEM::SparseMatrixBCSR<double, unsigned int, blocksize_, blocksize_>, Filter_> :
1491 public ILUPrecondBase<typename LAFEM::SparseMatrixBCSR<double, unsigned int, blocksize_, blocksize_>>
1494 typedef LAFEM::SparseMatrixBCSR<double, unsigned int, blocksize_, blocksize_> MatrixType;
1495 typedef Filter_ FilterType;
1496 typedef typename MatrixType::VectorTypeL VectorType;
1497 typedef typename MatrixType::DataType DataType;
1500 const MatrixType& _matrix;
1501 MatrixType _lu_matrix;
1502 const FilterType& _filter;
1517 explicit ILUPrecondWithBackend(
const MatrixType& matrix,
const FilterType& filter,
const int = 0) :
1539 explicit ILUPrecondWithBackend(
const String& DOXY(section_name),
const PropertyMap* section,
1540 const MatrixType& matrix,
const FilterType& filter) :
1545 auto fill_in_param_p = section->query(
"fill_in_param");
1546 if(fill_in_param_p.second)
1548 XASSERTM(std::stoi(fill_in_param_p.first) == 0,
"For PreferredBackend::cuda, the fill in parameter has to be == 0!");
1555 virtual ~ILUPrecondWithBackend()
1565 virtual void set_fill_in_param(
int p)
override
1567 XASSERTM(p == 0,
"For PreferredBackend::cuda, the fill in parameter has to be == 0!");
1571 virtual String name()
const override
1576 virtual void init_symbolic()
override
1578 if (_matrix.num_cols() != _matrix.num_rows())
1580 XABORTM(
"Matrix is not square!");
1589 cuda_info = Intern::cuda_ilub_init_symbolic((
int)_lu_matrix.num_rows(), (
int)_lu_matrix.num_nzes(),
1590 a.get_w(), row_ptr.get_r(), col_idx.get_r(),blocksize_);
1593 virtual void done_symbolic()
override
1595 Intern::cuda_ilub_done_symbolic(cuda_info);
1598 virtual void init_numeric()
override
1600 _lu_matrix.copy(_matrix);
1606 Intern::cuda_ilub_init_numeric(a.get_w(), row_ptr.get_r(), col_idx.get_r(), cuda_info);
1609 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
1611 XASSERTM(_matrix.num_rows() == vec_cor.size(),
"matrix / vector size mismatch!");
1612 XASSERTM(_matrix.num_rows() == vec_def.size(),
"matrix / vector size mismatch!");
1624 status = Intern::cuda_ilub_apply(vx.get_w(), vb.get_r(), a.get_r(), row_ptr.get_r(), col_idx.get_r(), cuda_info);
1627 this->_filter.filter_cor(vec_cor);
1630 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
1639 template<PreferredBackend backend_,
typename Matrix_,
typename Filter_>
1653 virtual Status apply(
typename Matrix_::VectorTypeL &,
const typename Matrix_::VectorTypeL &)
override
1655 XABORTM(
"not implemented yet!");
1658 virtual String name()
const override
1660 XABORTM(
"not implemented yet!");
1663 virtual void init_symbolic()
override
1665 XABORTM(
"not implemented yet!");
1668 virtual void done_symbolic()
override
1670 XABORTM(
"not implemented yet!");
1673 virtual void set_fill_in_param(
int )
override
1675 XABORTM(
"not implemented yet!");
1678 virtual void init_numeric()
override
1680 XABORTM(
"not implemented yet!");
1695 template<
typename Matrix_,
typename Filter_>
1699 std::shared_ptr<ILUPrecondBase<Matrix_>> _impl;
1702 typedef Matrix_ MatrixType;
1703 typedef Filter_ FilterType;
1704 typedef typename MatrixType::VectorTypeL VectorType;
1705 typedef typename MatrixType::DataType DataType;
1732 _impl = std::make_shared<ILUPrecondWithBackend<PreferredBackend::cuda, Matrix_, Filter_>>(matrix, filter);
1737 _impl = std::make_shared<ILUPrecondWithBackend<PreferredBackend::generic, Matrix_, Filter_>>(matrix, filter, p);
1766 _impl = std::make_shared<ILUPrecondWithBackend<PreferredBackend::cuda, Matrix_, Filter_>>(section_name, section, matrix, filter);
1771 _impl = std::make_shared<ILUPrecondWithBackend<PreferredBackend::generic, Matrix_, Filter_>>(section_name, section, matrix, filter);
1785 return _impl->name();
1796 _impl->set_fill_in_param(p);
1805 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
1807 return _impl->apply(vec_cor, vec_def);
1812 _impl->init_symbolic();
1817 _impl->done_symbolic();
1822 _impl->init_numeric();
1844 template<
typename Matrix_,
typename Filter_>
1846 const Matrix_& matrix,
const Filter_& filter,
const int p = 0)
1848 return std::make_shared<ILUPrecond<Matrix_, Filter_>>(backend, matrix, filter, p);
1872 template<
typename Matrix_,
typename Filter_>
1875 const Matrix_& matrix,
const Filter_& filter)
1877 return std::make_shared<ILUPrecond<Matrix_, Filter_>>(section_name, section, backend, matrix, filter);
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Index size() const
Returns the size of this vector, i.e. its number of entries.
CSR based blocked sparse matrix.
Index num_rows() const
Retrieve matrix row count.
Intern::BCSRVectorHelper< DT_, IT_, block_height_ >::VectorType VectorTypeL
Compatible L-vector type.
Index num_cols() const
Retrieve matrix column count.
Index num_cols() const
Retrieve matrix column count.
Index num_rows() const
Retrieve matrix row count.
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
void release() const
Releases this view.
Class for parser related errors.
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
Inheritances inside ilu_precond.hpp.
ILU(0) and ILU(p) preconditioner implementation.
ILUPrecond(const String §ion_name, const PropertyMap *section, PreferredBackend backend, const MatrixType &matrix, const FilterType &filter)
Constructor using a PropertyMap.
virtual ~ILUPrecond()
Empty virtual destructor.
ILUPrecond(PreferredBackend backend, const MatrixType &matrix, const FilterType &filter, const int p=0)
Constructor.
SolverBase< VectorType > BaseClass
Our base class.
virtual void init_numeric() override
Numeric initialization method.
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
apply the preconditioner
virtual void set_fill_in_param(int p)
Sets the fill-in parameter.
virtual void done_symbolic() override
Symbolic finalization method.
virtual void init_symbolic() override
Symbolic initialization method.
virtual String name() const override
Returns the name of the solver.
ILUPrecondWithBackend(const MatrixType &matrix, const FilterType &filter, const int p=0)
Constructor.
virtual String name() const override
Returns the name of the solver.
virtual ~ILUPrecondWithBackend()
Empty virtual destructor.
virtual Status apply(VectorType &out, const VectorType &in) override
apply the preconditioner
virtual void set_fill_in_param(int p) override
Sets the fill-in parameter.
virtual Status apply(VectorType &out, const VectorType &in) override
apply the preconditioner
virtual void set_fill_in_param(int p) override
Sets the fill-in parameter.
virtual ~ILUPrecondWithBackend()
Empty virtual destructor.
virtual String name() const override
Returns the name of the solver.
ILUPrecondWithBackend(const MatrixType &matrix, const FilterType &filter, const int p=0)
Constructor.
ILU(0) and ILU(p) preconditioner internal implementation.
Polymorphic solver interface.
static void add_flops(Index flops)
Add an amount of flops to the global flop counter.
String class implementation.
double elapsed(const TimeStamp &before) const
Calculates the time elapsed between two time stamps.
Status
Solver status return codes enumeration.
@ success
solving successful (convergence criterion fulfilled)
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)
std::shared_ptr< ILUPrecond< Matrix_, Filter_ > > new_ilu_precond(PreferredBackend backend, const Matrix_ &matrix, const Filter_ &filter, const int p=0)
Creates a new ILUPrecond solver object.
PreferredBackend
The backend that shall be used in all compute heavy calculations.