FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
ilu_precond.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/solver/base.hpp>
10#include <kernel/lafem/sparse_matrix_csr.hpp>
11#include <kernel/lafem/sparse_matrix_bcsr.hpp>
12
13// includes, system
14#include <vector>
15
16namespace FEAT
17{
18 namespace Solver
19 {
21 namespace Intern
22 {
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);
27
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);
32
44 template<typename IT_>
45 class ILUCoreSymbolic
46 {
47 protected:
49 IT_ _n;
51 std::vector<IT_> _row_ptr_l, _col_idx_l;
53 std::vector<IT_> _row_ptr_u, _col_idx_u;
54 //std::vector<IT_> _lvl_l, _lvl_u;
55
56 public:
58 void clear()
59 {
60 _n = IT_(0);
61 _row_ptr_l.clear();
62 _col_idx_l.clear();
63 _row_ptr_u.clear();
64 _col_idx_u.clear();
65 //_lvl_l.clear();
66 //_lvl_u.clear();
67 }
68
70 IT_ get_nnze_l() const
71 {
72 return _row_ptr_l.empty() ? IT_(0) : _row_ptr_l.back();
73 }
74
76 IT_ get_nnze_u() const
77 {
78 return _row_ptr_u.empty() ? IT_(0) : _row_ptr_u.back();
79 }
80
82 IT_ get_nnze() const
83 {
84 return _n + get_nnze_l() + get_nnze_u();
85 }
86
88 std::size_t bytes_symbolic() const
89 {
90 return sizeof(IT_) * (_row_ptr_l.size() + _row_ptr_u.size() + _col_idx_l.size() + _col_idx_u.size());
91 }
92
105 void set_struct_csr(const IT_ n, const IT_* row_ptr_a, const IT_* col_idx_a)
106 {
107 // First of all, let's guess the number of non-zeros for L and U:
108 // In most of our cases, the sparsity pattern of A is symmetric,
109 // so we have a guess of (nz(A)-n)/2 for both L and U:
110 const IT_ nzul = (Math::max(row_ptr_a[n], n) - n) / IT_(2);
111
112 // store size and clear containers
113 _n = n;
114 _row_ptr_l.clear();
115 _col_idx_l.clear();
116 _row_ptr_u.clear();
117 _col_idx_u.clear();
118
119 // reserve our non-zero guess
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);
124
125 // initialize row-pointers
126 _row_ptr_l.push_back(0);
127 _row_ptr_u.push_back(0);
128
129 // loop over all matrix rows
130 for(IT_ i(0); i < n; ++i)
131 {
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)
135 {
136 _col_idx_l.push_back(col_idx_a[j]);
137 }
138 if(col_idx_a[j] != i)
139 throw InvalidMatrixStructureException();
140 for(++j; j < jend; ++j)
141 {
142 _col_idx_u.push_back(col_idx_a[j]);
143 }
144 _row_ptr_l.push_back(IT_(_col_idx_l.size()));
145 _row_ptr_u.push_back(IT_(_col_idx_u.size()));
146 }
147
148 //_lvl_l.resize(_col_idx_l.size(), IT_(0));
149 //_lvl_u.resize(_col_idx_u.size(), IT_(0));
150 }
151
158 template<typename DT_>
159 void set_struct(const LAFEM::SparseMatrixCSR<DT_, IT_>& matrix)
160 {
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());
164 }
165
172 template<typename DT_, int m_, int n_>
173 void set_struct(const LAFEM::SparseMatrixBCSR<DT_, IT_, m_, n_>& matrix)
174 {
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());
178 }
179
194 void factorize_symbolic(const int p)
195 {
196 if(p < 1)
197 return;
198
199 // our new level-p structures for L and U
200 std::vector<IT_> new_ptr_l, new_idx_l, new_ptr_u, new_idx_u;
201
202 // our temporary level arrays
203 std::vector<int> new_lvl_l, new_lvl_u;
204
205 // initialize new row pointers
206 new_ptr_l.push_back(IT_(0));
207 new_ptr_u.push_back(IT_(0));
208
209 // loop over all rows
210 for(IT_ i(0); i < _n; ++i)
211 {
212 // first off, add all level 0 entries to L and U
213 for(IT_ j(_row_ptr_l[i]); j < _row_ptr_l[i+1]; ++j)
214 {
215 new_idx_l.push_back(_col_idx_l[j]);
216 new_lvl_l.push_back(0);
217 }
218 for(IT_ j(_row_ptr_u[i]); j < _row_ptr_u[i+1]; ++j)
219 {
220 new_idx_u.push_back(_col_idx_u[j]);
221 new_lvl_u.push_back(0);
222 }
223
224 // loop over row L_i
225 for(IT_ j(new_ptr_l[i]); j < IT_(new_idx_l.size()); ++j)
226 {
227 // get column index and level of L_ij
228 const IT_ cj = new_idx_l[j];
229 const int lj = new_lvl_l[j];
230 IT_ olj = j;
231 IT_ ouj = new_ptr_u[i];
232
233 // loop over row U_j
234 for(IT_ k(new_ptr_u[cj]); k < new_ptr_u[cj+1]; ++k)
235 {
236 // get column index and level of U_jk
237 const IT_ ck = new_idx_u[k];
238 const int lk = new_lvl_u[k];
239
240 // compute level of entry L/U_ik
241 const int ll = lj + lk + 1;
242 if(ll > p)
243 continue;
244
245 // insert into L or U
246 if(ck < i)
247 olj = _insert(new_idx_l, new_lvl_l, olj, ck, ll);
248 else if(ck > i)
249 ouj = _insert(new_idx_u, new_lvl_u, ouj, ck, ll);
250 }
251 }
252
253 // update row-pointers
254 new_ptr_l.push_back(IT_(new_idx_l.size()));
255 new_ptr_u.push_back(IT_(new_idx_u.size()));
256 }
257
258 // replace old arrays
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);
263
264 //_lvl_l = new_lvl_l;
265 //_lvl_u = new_lvl_u;
266 }
267
268 protected:
293 static IT_ _insert(std::vector<IT_>& idx, std::vector<int>& lvl, IT_ i, const IT_ j, const int l)
294 {
295 // get the current length of the column-index vector
296 IT_ n = IT_(idx.size());
297
298 // loop over the row and try to find our entry
299 for(; i < n; ++i)
300 {
301 if(idx[i] == j)
302 {
303 // the entry that we want to add already exists in the sparsity pattern,
304 // so check whether we need to adapt its level
305 if(l < lvl[i])
306 lvl[i] = l;
307
308 // return next entry starting position
309 return ++i;
310 }
311 else if(j < idx[i])
312 {
313 // we have reached a column index beyond the entry we want to add,
314 // so stop searching
315 break;
316 }
317 }
318
319 // the entry we want to add does not yet exist in the sparsity pattern,
320 // so we add it at position i by linear insertion:
321 idx.push_back(IT_(0));
322 lvl.push_back(0);
323
324 // shift all entries backward by one position
325 for(IT_ k(n); k > i; --k)
326 {
327 idx[k] = idx[k-1];
328 lvl[k] = lvl[k-1];
329 }
330
331 // insert at desired position
332 idx[i] = j;
333 lvl[i] = l;
334
335 // return next entry starting position
336 return ++i;
337 }
338 }; // class ILUCoreSymbolic
339
353 template<typename DT_, typename IT_>
354 class ILUCoreScalar :
355 public ILUCoreSymbolic<IT_>
356 {
357 protected:
358 typedef ILUCoreSymbolic<IT_> BaseClass;
359
361 std::vector<DT_> _data_l, _data_u, _data_d;
362
363 public:
365 void clear()
366 {
367 BaseClass::clear();
368 _data_l.clear();
369 _data_u.clear();
370 _data_d.clear();
371 }
372
374 void alloc_data()
375 {
376 // resize data arrays
377 _data_d.resize(this->_n);
378 _data_l.resize(this->_col_idx_l.size());
379 _data_u.resize(this->_col_idx_u.size());
380 }
381
383 std::size_t bytes_numeric() const
384 {
385 return sizeof(DT_) * (_data_l.size() + _data_u.size() + _data_d.size());
386 }
387
389 std::size_t bytes() const
390 {
391 return this->bytes_numeric() + this->bytes_symbolic();
392 }
393
406 void copy_data_csr(const IT_* row_ptr_a, const IT_* col_idx_a, const DT_* data_a)
407 {
408 // loop over all rows
409 for(IT_ i(0); i < this->_n; ++i)
410 {
411 // get row pointer of a
412 IT_ ra = row_ptr_a[i];
413 IT_ xa = row_ptr_a[i+1];
414
415 // fetch row i of L
416 for(IT_ j(this->_row_ptr_l[i]); j < this->_row_ptr_l[i+1]; ++j)
417 {
418 if(this->_col_idx_l[j] == col_idx_a[ra])
419 _data_l[j] = data_a[ra++];
420 else //if(this->_col_idx_l[j] < col_idx_a[ra])
421 _data_l[j] = DT_(0);
422 }
423
424 // fetch diagonal of a
425 _data_d[i] = data_a[ra++];
426
427 // fetch row i of U
428 for(IT_ j(this->_row_ptr_u[i]); j < this->_row_ptr_u[i+1]; ++j)
429 {
430 if((ra < xa) && (this->_col_idx_u[j] == col_idx_a[ra]))
431 _data_u[j] = data_a[ra++];
432 else// if(this->_col_idx_u[j] < col_idx_a[ra])
433 _data_u[j] = DT_(0);
434 }
435 }
436 }
437
444 void copy_data(const LAFEM::SparseMatrixCSR<DT_, IT_>& matrix)
445 {
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());
450 }
451
458 void factorize_numeric_il_du()
459 {
460 // get data arrays
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();
468
469 // loop over all rows
470 for(IT_ i(0); i < this->_n; ++i)
471 {
472 // get row-end pointers of L and U
473 const IT_ ql = rptr_l[i+1];
474 const IT_ qu = rptr_u[i+1];
475
476 // loop over row i of L
477 for(IT_ j(rptr_l[i]); j < rptr_l[i+1]; ++j)
478 {
479 // get column index of L_ij
480 const IT_ cj = cidx_l[j];
481
482 // get L/U pointers
483 IT_ pl = j;
484 IT_ pu = rptr_u[i];
485
486 // update L_ij <- L_ij / D_jj
487 data_l[j] *= data_d[cj];
488
489 // loop over row j of U and process row i of L
490 IT_ k(rptr_u[cj]);
491 for(; k < rptr_u[cj+1]; ++k)
492 {
493 const IT_ ck = cidx_u[k];
494 if(ck >= i)
495 break;
496 for(; (pl < ql) && (cidx_l[pl] <= ck); ++pl)
497 {
498 if(cidx_l[pl] == ck)
499 data_l[pl] -= data_l[j] * data_u[k];
500 }
501 }
502
503 // process main diagonal entry
504 if((k < rptr_u[cj+1]) && (cidx_u[k] == i))
505 {
506 data_d[i] -= data_l[j] * data_u[k];
507 ++k;
508 }
509 // loop over row j of U and process row i of U
510 for(; k < rptr_u[cj+1]; ++k)
511 {
512 const IT_ ck = cidx_u[k];
513 for(; (pu < qu) && (cidx_u[pu] <= ck); ++pu)
514 {
515 if(cidx_u[pu] == ck)
516 data_u[pu] -= data_l[j] * data_u[k];
517 }
518 }
519 }
520
521 // invert main diagonal entry
522 data_d[i] = DT_(1) / data_d[i];
523 }
524 }
525
538 void solve_il(DT_* x, const DT_* b) const
539 {
540
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());
544
545 for(IT_ i(0); i < this->_n; ++i)
546 {
547 DT_ r(b[i]);
548 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
549 {
550 r -= data_l[j] * x[cidx[j]];
551 }
552 x[i] = r;
553 }
554 }
555
568 void solve_du(DT_* x, const DT_* b) const
569 {
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();
574
575 for(IT_ i(this->_n); i > IT_(0); )
576 {
577 --i;
578 DT_ r(b[i]);
579 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
580 {
581 r -= data_u[j] * x[cidx[j]];
582 }
583 x[i] = data_d[i] * r;
584 }
585 }
586
599 void solve_ilt(DT_* x, const DT_* b) const
600 {
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());
604
605 if(x != b)
606 {
607 for(IT_ i(0); i < this->_n; ++i)
608 x[i] = b[i];
609 }
610
611 for(IT_ i(this->_n); i > IT_(0); )
612 {
613 --i;
614 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
615 {
616 // x_j -= L_ij * x[i]
617 x[cidx[j]] -= data_l[j] * x[i];
618 }
619 }
620 }
621
634 void solve_dut(DT_* x, const DT_* b) const
635 {
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();
640
641 if(x != b)
642 {
643 for(IT_ i(0); i < this->_n; ++i)
644 x[i] = b[i];
645 }
646
647 for(IT_ i(0); i < this->_n; ++i)
648 {
649 x[i] *= data_d[i];
650 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
651 {
652 // x_j -= U_ij * x_i
653 x[cidx[j]] -= data_u[j] * x[i];
654 }
655 }
656 }
657 }; // class ILUCoreScalar
658
675 template<typename DT_, typename IT_, int dim_>
676 class ILUCoreBlocked :
677 public ILUCoreSymbolic<IT_>
678 {
679 protected:
680 typedef ILUCoreSymbolic<IT_> BaseClass;
681
682 static_assert(dim_ > 0, "invalid block dimension");
683
684 typedef Tiny::Matrix<DT_, dim_, dim_> MatBlock;
685 typedef Tiny::Vector<DT_, dim_> VecBlock;
686
688 std::vector<MatBlock> _data_l, _data_u, _data_d;
689
690 public:
692 void clear()
693 {
694 BaseClass::clear();
695 _data_l.clear();
696 _data_u.clear();
697 _data_d.clear();
698 }
699
701 void alloc_data()
702 {
703 // resize data arrays
704 _data_d.resize(this->_n);
705 _data_l.resize(this->_col_idx_l.size());
706 _data_u.resize(this->_col_idx_u.size());
707 }
708
710 std::size_t bytes_numeric() const
711 {
712 return sizeof(DT_) * std::size_t(Math::sqr(dim_)) * (_data_l.size() + _data_u.size() + _data_d.size());
713 }
714
716 std::size_t bytes() const
717 {
718 return this->bytes_numeric() + this->bytes_symbolic();
719 }
720
733 void copy_data_bcsr(const IT_* row_ptr_a, const IT_* col_idx_a, const MatBlock* data_a)
734 {
735 // loop over all rows
736 for(IT_ i(0); i < this->_n; ++i)
737 {
738 // get row pointer of a
739 IT_ ra = row_ptr_a[i];
740 IT_ xa = row_ptr_a[i+1];
741
742 // fetch row i of L
743 for(IT_ j(this->_row_ptr_l[i]); j < this->_row_ptr_l[i+1]; ++j)
744 {
745 if(this->_col_idx_l[j] == col_idx_a[ra])
746 _data_l[j] = data_a[ra++];
747 else //if(this->_col_idx_l[j] < col_idx_a[ra])
748 _data_l[j] = DT_(0);
749 }
750
751 // fetch diagonal of a
752 _data_d[i] = data_a[ra++];
753
754 // fetch row i of U
755 for(IT_ j(this->_row_ptr_u[i]); j < this->_row_ptr_u[i+1]; ++j)
756 {
757 if((ra < xa) && (this->_col_idx_u[j] == col_idx_a[ra]))
758 _data_u[j] = data_a[ra++];
759 else// if(this->_col_idx_u[j] < col_idx_a[ra])
760 _data_u[j] = DT_(0);
761 }
762 }
763 }
764
771 void copy_data(const LAFEM::SparseMatrixBCSR<DT_, IT_, dim_, dim_>& matrix)
772 {
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());
777 }
778
785 void factorize_numeric_il_du()
786 {
787 // get data arrays
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();
795
796 // loop over all rows
797 for(IT_ i(0); i < this->_n; ++i)
798 {
799 // get row-end pointers of L and U
800 const IT_ ql = rptr_l[i+1];
801 const IT_ qu = rptr_u[i+1];
802
803 // loop over row i of L
804 for(IT_ j(rptr_l[i]); j < rptr_l[i+1]; ++j)
805 {
806 // get column index of L_ij
807 const IT_ cj = cidx_l[j];
808
809 // get L/U pointers
810 IT_ pl = j;
811 IT_ pu = rptr_u[i];
812
813 // update L_ij <- D_jj^{-1} * L_ij
814 {
815 //data_l[j] *= data_d[cj];
816 const MatBlock l_ij(data_l[j]);
817 data_l[j].set_mat_mat_mult(data_d[cj], l_ij);
818 }
819
820 // loop over row j of U and process row i of L
821 IT_ k(rptr_u[cj]);
822 for(; k < rptr_u[cj+1]; ++k)
823 {
824 const IT_ ck = cidx_u[k];
825 if(ck >= i)
826 break;
827 for(; (pl < ql) && (cidx_l[pl] <= ck); ++pl)
828 {
829 if(cidx_l[pl] == ck)
830 //data_l[pl] -= data_l[j] * data_u[k];
831 data_l[pl].add_mat_mat_mult(data_l[j], data_u[k], -DT_(1));
832 }
833 }
834
835 // process main diagonal entry
836 if((k < rptr_u[cj+1]) && (cidx_u[k] == i))
837 {
838 //data_d[i] -= data_l[j] * data_u[k];
839 data_d[i].add_mat_mat_mult(data_l[j], data_u[k], -DT_(1));
840 ++k;
841 }
842
843 // loop over row j of U and process row i of U
844 for(; k < rptr_u[cj+1]; ++k)
845 {
846 const IT_ ck = cidx_u[k];
847 for(; (pu < qu) && (cidx_u[pu] <= ck); ++pu)
848 {
849 if(cidx_u[pu] == ck)
850 //data_u[pu] -= data_l[j] * data_u[k];
851 data_u[pu].add_mat_mat_mult(data_l[j], data_u[k], -DT_(1));
852 }
853 }
854 }
855
856 // invert main diagonal entry
857 {
858 //data_d[i] = DT_(1) / data_d[i];
859 const MatBlock d_ii(data_d[i]);
860 data_d[i].set_inverse(d_ii);
861 }
862 }
863 }
864
877 void solve_il(VecBlock* x, const VecBlock* b) const
878 {
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());
882
883 for(IT_ i(0); i < this->_n; ++i)
884 {
885 VecBlock r(b[i]);
886 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
887 {
888 //r -= data_l[j] * x[cidx[j]];
889 r.add_mat_vec_mult(data_l[j], x[cidx[j]], -DT_(1));
890 }
891 x[i] = r;
892 }
893 }
894
907 void solve_du(VecBlock* x, const VecBlock* b) const
908 {
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();
913
914 for(IT_ i(this->_n); i > IT_(0); )
915 {
916 --i;
917 VecBlock r(b[i]);
918 for(IT_ j(rptr[i]); j < rptr[i+1]; ++j)
919 {
920 //r -= data_u[j] * x[cidx[j]];
921 r.add_mat_vec_mult(data_u[j], x[cidx[j]], -DT_(1));
922 }
923 //x[i] = data_d[i] * r;
924 x[i].set_mat_vec_mult(data_d[i], r);
925 }
926 }
927 }; // class ILUCoreBlocked
928 } // namespace Intern
930
945 template<typename Matrix_>
947 {
948 public:
949 typedef typename Matrix_::DataType DataType;
950 typedef typename Matrix_::VectorTypeL VectorType;
951
952 virtual void set_fill_in_param(int p) = 0;
953
954 virtual void init_symbolic() = 0;
955
956 virtual void done_symbolic() = 0;
957
958 virtual void init_numeric() = 0;
959
960 virtual String name() const = 0;
961
962 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) = 0;
963
964 virtual ~ILUPrecondBase() {}
965 }; // ILUPrecondBase class
966
975 template<PreferredBackend backend_, typename Matrix_, typename Filter_>
977
985 template<typename DT_, typename IT_, typename Filter_>
987 public ILUPrecondBase<typename LAFEM::SparseMatrixCSR<DT_, IT_>>
988 {
989 public:
991 typedef DT_ DataType;
992 typedef IT_ IndexType;
993 typedef Filter_ FilterType;
994 typedef typename MatrixType::VectorTypeL VectorType;
995
996 protected:
997 const MatrixType& _matrix;
998 const FilterType& _filter;
999 Intern::ILUCoreScalar<DataType, IndexType> _ilu;
1000 int _p;
1001
1002 public:
1012 explicit ILUPrecondWithBackend(const MatrixType& matrix, const FilterType& filter, const int p = 0) :
1013 _matrix(matrix),
1014 _filter(filter),
1015 _p(p)
1016 {
1017 }
1018
1019 explicit ILUPrecondWithBackend(const String& section_name, const PropertyMap* section,
1020 const MatrixType& matrix, const FilterType& filter) :
1021 _matrix(matrix),
1022 _filter(filter),
1023 _p(-1)
1024 {
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");
1028 }
1029
1034 {
1035 }
1036
1043 virtual void set_fill_in_param(int p) override
1044 {
1045 XASSERT(p > 0);
1046 _p = p;
1047 }
1048
1050 virtual String name() const override
1051 {
1052 return "ILU";
1053 }
1054
1055 virtual void init_symbolic() override
1056 {
1057 if (_matrix.num_cols() != _matrix.num_rows())
1058 {
1059 XABORTM("Matrix is not square!");
1060 }
1061
1062 // set matrix structure
1063 _ilu.set_struct(_matrix);
1064
1065 // perform symbolic factorization
1066 _ilu.factorize_symbolic(_p);
1067
1068 // allocate data arrays
1069 _ilu.alloc_data();
1070 }
1071
1072 virtual void done_symbolic() override
1073 {
1074 _ilu.clear();
1075 }
1076
1077 virtual void init_numeric() override
1078 {
1079 _ilu.copy_data(_matrix);
1080 _ilu.factorize_numeric_il_du();
1081 }
1082
1089 virtual Status apply(VectorType& out, const VectorType& in) override
1090 {
1091 TimeStamp ts_start;
1092
1093 // get vector data views
1094 Memory::TypedView<DataType> vx = out.elements_view_w();
1095 Memory::TypedView<DataType> vb = in.elements_view_r();
1096
1097 // solve: (I+L)*y = b
1098 _ilu.solve_il(vx.get_w(), vb.get_r());
1099
1100 // solve: (D+U)*x = y
1101 _ilu.solve_du(vx.get_w(), vx.get_w());
1102
1103 // release views
1104 vb.release();
1105 vx.release();
1106
1107 // apply filter
1108 this->_filter.filter_cor(out);
1109
1110 TimeStamp ts_stop;
1111 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
1112 Statistics::add_flops(_ilu.get_nnze() * 2 + out.size());
1113
1114 return Status::success;
1115 }
1116 }; // class ILUPrecondWithBackend<generic, SparseMatrixCSR,...>
1117
1123 template<typename DT_, typename IT_, int dim_, typename Filter_>
1125 public ILUPrecondBase<typename LAFEM::SparseMatrixBCSR<DT_, IT_, dim_, dim_>>
1126 {
1127 public:
1129 typedef DT_ DataType;
1130 typedef IT_ IndexType;
1131 typedef Filter_ FilterType;
1132 typedef typename MatrixType::VectorTypeL VectorType;
1133
1134 protected:
1135 const MatrixType& _matrix;
1136 const FilterType& _filter;
1137 Intern::ILUCoreBlocked<DataType, IndexType, dim_> _ilu;
1138 int _p;
1139
1140 public:
1150 explicit ILUPrecondWithBackend(const MatrixType& matrix, const FilterType& filter, const int p = 0) :
1151 _matrix(matrix),
1152 _filter(filter),
1153 _p(p)
1154 {
1155 }
1156
1157 explicit ILUPrecondWithBackend(const String& section_name, const PropertyMap* section,
1158 const MatrixType& matrix, const FilterType& filter) :
1159 _matrix(matrix),
1160 _filter(filter),
1161 _p(-1)
1162 {
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");
1166 }
1167
1172 {
1173 }
1174
1181 virtual void set_fill_in_param(int p) override
1182 {
1183 XASSERT(p > 0);
1184 _p = p;
1185 }
1186
1188 virtual String name() const override
1189 {
1190 return "ILU";
1191 }
1192
1193 virtual void init_symbolic() override
1194 {
1195 if (_matrix.num_cols() != _matrix.num_rows())
1196 {
1197 XABORTM("Matrix is not square!");
1198 }
1199
1200 // set matrix structure
1201 _ilu.set_struct(_matrix);
1202
1203 // perform symbolic factorization
1204 _ilu.factorize_symbolic(_p);
1205
1206 // allocate data arrays
1207 _ilu.alloc_data();
1208 }
1209
1210 virtual void done_symbolic() override
1211 {
1212 _ilu.clear();
1213 }
1214
1215 virtual void init_numeric() override
1216 {
1217 _ilu.copy_data(_matrix);
1218 _ilu.factorize_numeric_il_du();
1219 }
1220
1227 virtual Status apply(VectorType& out, const VectorType& in) override
1228 {
1229 TimeStamp ts_start;
1230
1231 // get vector data views
1232 Memory::TypedView<Tiny::Vector<DataType, dim_>> vx = out.elements_view_w();
1233 const Memory::TypedView<Tiny::Vector<DataType, dim_>> vb = in.elements_view_r();
1234
1235 // solve: (I+L)*y = b
1236 _ilu.solve_il(vx.get_w(), vb.get_r());
1237
1238 // solve: (D+U)*x = y
1239 _ilu.solve_du(vx.get_w(), vx.get_w());
1240
1241 // release views
1242 vb.release();
1243 vx.release();
1244
1245 // apply filter
1246 this->_filter.filter_cor(out);
1247
1248 TimeStamp ts_stop;
1249 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
1250 Statistics::add_flops(_ilu.get_nnze() * 2 + out.size());
1251
1252 return Status::success;
1253 }
1254 }; // class ILUPrecondWithBackend<generic, SparseMatrixBCSR<...>,...>
1255
1256#ifdef FEAT_HAVE_CUDA
1270 template<typename Filter_>
1271 class ILUPrecondWithBackend<PreferredBackend::cuda, LAFEM::SparseMatrixCSR<double, unsigned int>, Filter_> :
1272 public ILUPrecondBase<LAFEM::SparseMatrixCSR<double, unsigned int>>
1273 {
1274 public:
1276 typedef Filter_ FilterType;
1277 typedef typename MatrixType::VectorTypeL VectorType;
1278 typedef typename MatrixType::DataType DataType;
1279
1280 protected:
1281 const MatrixType& _matrix;
1282 MatrixType _lu_matrix;
1283 const FilterType& _filter;
1284 void * cuda_info;
1285
1286 public:
1298 explicit ILUPrecondWithBackend(const MatrixType& matrix, const FilterType& filter, const int = 0) :
1299 _matrix(matrix),
1300 _filter(filter)
1301 {
1302 }
1303
1304 explicit ILUPrecondWithBackend(const String& DOXY(section_name), const PropertyMap* section,
1305 const MatrixType& matrix, const FilterType& filter) :
1306 _matrix(matrix),
1307 _filter(filter)
1308 {
1309 // Check for _p
1310 auto fill_in_param_p = section->query("fill_in_param");
1311 if(fill_in_param_p.second)
1312 {
1313 XASSERTM(std::stoi(fill_in_param_p.first) == 0, "For PreferredBackend::cuda, the fill in parameter has to be == 0!");
1314 }
1315 }
1316
1320 virtual ~ILUPrecondWithBackend()
1321 {
1322 }
1323
1330 virtual void set_fill_in_param(int p) override
1331 {
1332 XASSERTM(p == 0, "For PreferredBackend::cuda, the fill in parameter has to be == 0!");
1333 }
1334
1336 virtual String name() const override
1337 {
1338 return "ILU";
1339 }
1340
1341 virtual void init_symbolic() override
1342 {
1343 if (_matrix.num_cols() != _matrix.num_rows())
1344 {
1345 XABORTM("Matrix is not square!");
1346 }
1347
1348 _lu_matrix.clone(_matrix, LAFEM::CloneMode::Layout);
1349
1350 Memory::TypedView<DataType> a = _lu_matrix.val_view_rw(Memory::Location::cuda);
1351 // cast from 'unsigned int' to 'int'
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());
1356 }
1357
1358 virtual void done_symbolic() override
1359 {
1360 Intern::cuda_ilu_done_symbolic(cuda_info);
1361 }
1362
1363 virtual void init_numeric() override
1364 {
1365 _lu_matrix.copy(_matrix);
1366
1367 Memory::TypedView<DataType> a = _lu_matrix.val_view_rw(Memory::Location::cuda);
1368 // cast from 'unsigned int' to 'int'
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);
1372 }
1373
1374 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
1375 {
1376 XASSERTM(_matrix.num_rows() == vec_cor.size(), "matrix / vector size mismatch!");
1377 XASSERTM(_matrix.num_rows() == vec_def.size(), "matrix / vector size mismatch!");
1378
1379 TimeStamp ts_start;
1380
1381 int status = 0;
1382 {
1383 Memory::TypedView<DataType> vx = vec_cor.elements_view_w(Memory::Location::cuda);
1384 Memory::TypedView<DataType> vb = vec_cor.elements_view_r(Memory::Location::cuda);
1385 Memory::TypedView<DataType> a = _lu_matrix.val_view_r(Memory::Location::cuda);
1386 // cast from 'unsigned int' to 'int'
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)));
1389
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);
1391 }
1392
1393 this->_filter.filter_cor(vec_cor);
1394
1395 TimeStamp ts_stop;
1396 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
1397 Statistics::add_flops(_matrix.num_nzes() * 2 + vec_cor.size());
1398
1399 return (status == 0) ? Status::success : Status::aborted;
1400 }
1401 }; // class ILUPrecondWithBackend<cuda, SparseMatrixCSR<...>,...>
1402
1403 /*
1404 template<typename Filter_>
1405 class ILUPrecond<LAFEM::SparseMatrixCSR<Mem::CUDA, float, unsigned int>, Filter_> :
1406 public SolverBase<LAFEM::SparseMatrixCSR<Mem::CUDA, float, unsigned int>::VectorTypeL>
1407 {
1408 public:
1409 typedef LAFEM::SparseMatrixCSR<Mem::CUDA, float, unsigned int> MatrixType;
1410 typedef typename MatrixType::VectorTypeL VectorType;
1411 typedef Filter_ FilterType;
1412
1413 explicit ILUPrecond(const MatrixType&, const FilterType&, const int = 0)
1414 {
1415 }
1416
1417 Status apply(VectorType &, const VectorType &) override
1418 {
1419 XABORTM("not implemented yet!");
1420 }
1421
1422 String name() const override
1423 {
1424 XABORTM("not implemented yet!");
1425 }
1426 };
1427
1428 template<typename Filter_>
1429 class ILUPrecond<LAFEM::SparseMatrixCSR<Mem::CUDA, float, unsigned long>, Filter_> :
1430 public SolverBase<LAFEM::SparseMatrixCSR<Mem::CUDA, float, unsigned long>::VectorTypeL>
1431 {
1432 public:
1433 typedef LAFEM::SparseMatrixCSR<Mem::CUDA, float, unsigned long> MatrixType;
1434 typedef typename MatrixType::VectorTypeL VectorType;
1435 typedef Filter_ FilterType;
1436
1437 explicit ILUPrecond(const MatrixType&, const FilterType&, const int = 0)
1438 {
1439 }
1440
1441 Status apply(VectorType &, const VectorType &) override
1442 {
1443 XABORTM("not implemented yet!");
1444 }
1445
1446 String name() const override
1447 {
1448 XABORTM("not implemented yet!");
1449 }
1450 };
1451
1452 template<typename Filter_>
1453 class ILUPrecond<LAFEM::SparseMatrixCSR<Mem::CUDA, double, unsigned long>, Filter_> :
1454 public SolverBase<LAFEM::SparseMatrixCSR<Mem::CUDA, double, unsigned long>::VectorTypeL>
1455 {
1456 public:
1457 typedef LAFEM::SparseMatrixCSR<Mem::CUDA, double, unsigned long> MatrixType;
1458 typedef typename MatrixType::VectorTypeL VectorType;
1459 typedef Filter_ FilterType;
1460
1461 explicit ILUPrecond(const MatrixType&, const FilterType&, const int = 0)
1462 {
1463 }
1464
1465 Status apply(VectorType &, const VectorType &) override
1466 {
1467 XABORTM("not implemented yet!");
1468 }
1469
1470 String name() const override
1471 {
1472 XABORTM("not implemented yet!");
1473 }
1474 };*/
1475
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_>>
1492 {
1493 public:
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;
1498
1499 protected:
1500 const MatrixType& _matrix;
1501 MatrixType _lu_matrix;
1502 const FilterType& _filter;
1503 void * cuda_info;
1504
1505 public:
1517 explicit ILUPrecondWithBackend(const MatrixType& matrix, const FilterType& filter, const int = 0) :
1518 _matrix(matrix),
1519 _filter(filter)
1520 {
1521 }
1522
1539 explicit ILUPrecondWithBackend(const String& DOXY(section_name), const PropertyMap* section,
1540 const MatrixType& matrix, const FilterType& filter) :
1541 _matrix(matrix),
1542 _filter(filter)
1543 {
1544 // Check for _p
1545 auto fill_in_param_p = section->query("fill_in_param");
1546 if(fill_in_param_p.second)
1547 {
1548 XASSERTM(std::stoi(fill_in_param_p.first) == 0, "For PreferredBackend::cuda, the fill in parameter has to be == 0!");
1549 }
1550 }
1551
1555 virtual ~ILUPrecondWithBackend()
1556 {
1557 }
1558
1565 virtual void set_fill_in_param(int p) override
1566 {
1567 XASSERTM(p == 0, "For PreferredBackend::cuda, the fill in parameter has to be == 0!");
1568 }
1569
1571 virtual String name() const override
1572 {
1573 return "ILU";
1574 }
1575
1576 virtual void init_symbolic() override
1577 {
1578 if (_matrix.num_cols() != _matrix.num_rows())
1579 {
1580 XABORTM("Matrix is not square!");
1581 }
1582
1583 _lu_matrix.clone(_matrix, LAFEM::CloneMode::Layout);
1584
1585 Memory::TypedView<DataType> a = _lu_matrix.val_view_raw_rw(Memory::Location::cuda);
1586 Memory::TypedView<int> row_ptr(_lu_matrix.row_ptr_view_r(Memory::Location::cuda));
1587 Memory::TypedView<int> col_idx(_lu_matrix.col_idx_view_r(Memory::Location::cuda));
1588
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_);
1591 }
1592
1593 virtual void done_symbolic() override
1594 {
1595 Intern::cuda_ilub_done_symbolic(cuda_info);
1596 }
1597
1598 virtual void init_numeric() override
1599 {
1600 _lu_matrix.copy(_matrix);
1601
1602 Memory::TypedView<DataType> a = _lu_matrix.val_view_raw_rw(Memory::Location::cuda);
1603 Memory::TypedView<int> row_ptr(_lu_matrix.row_ptr_view_r(Memory::Location::cuda));
1604 Memory::TypedView<int> col_idx(_lu_matrix.col_idx_view_r(Memory::Location::cuda));
1605
1606 Intern::cuda_ilub_init_numeric(a.get_w(), row_ptr.get_r(), col_idx.get_r(), cuda_info);
1607 }
1608
1609 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
1610 {
1611 XASSERTM(_matrix.num_rows() == vec_cor.size(), "matrix / vector size mismatch!");
1612 XASSERTM(_matrix.num_rows() == vec_def.size(), "matrix / vector size mismatch!");
1613
1614 TimeStamp ts_start;
1615
1616 int status = 0;
1617 {
1618 Memory::TypedView<DataType> vx = vec_cor.elements_view_raw_w(Memory::Location::cuda);
1619 Memory::TypedView<DataType> vb = vec_cor.elements_view_raw_r(Memory::Location::cuda);
1620 Memory::TypedView<DataType> a = _lu_matrix.val_view_raw_r(Memory::Location::cuda);
1621 Memory::TypedView<int> row_ptr(_lu_matrix.row_ptr_view_r(Memory::Location::cuda));
1622 Memory::TypedView<int> col_idx(_lu_matrix.col_idx_view_r(Memory::Location::cuda));
1623
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);
1625 }
1626
1627 this->_filter.filter_cor(vec_cor);
1628
1629 TimeStamp ts_stop;
1630 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
1631 Statistics::add_flops(_matrix.num_nzes() * 2 + vec_cor.size());
1632
1633 return (status == 0) ? Status::success : Status::aborted;
1634 }
1635 }; // class ILUPrecondWithBackend<cuda, SparseMatrixBCSR<...>,...>
1636#endif //FEAT_HAVE_CUDA
1637
1639 template<PreferredBackend backend_, typename Matrix_, typename Filter_>
1641 public ILUPrecondBase<Matrix_>
1642 {
1643 public:
1644
1645 explicit ILUPrecondWithBackend(const Matrix_&, const Filter_&, const int = 0)
1646 {
1647 }
1648
1649 explicit ILUPrecondWithBackend(const String& , const PropertyMap*, const Matrix_& , const Filter_& )
1650 {
1651 }
1652
1653 virtual Status apply(typename Matrix_::VectorTypeL &, const typename Matrix_::VectorTypeL &) override
1654 {
1655 XABORTM("not implemented yet!");
1656 }
1657
1658 virtual String name() const override
1659 {
1660 XABORTM("not implemented yet!");
1661 }
1662
1663 virtual void init_symbolic() override
1664 {
1665 XABORTM("not implemented yet!");
1666 }
1667
1668 virtual void done_symbolic() override
1669 {
1670 XABORTM("not implemented yet!");
1671 }
1672
1673 virtual void set_fill_in_param(int /*p*/) override
1674 {
1675 XABORTM("not implemented yet!");
1676 }
1677
1678 virtual void init_numeric() override
1679 {
1680 XABORTM("not implemented yet!");
1681 }
1682 };
1683
1695 template<typename Matrix_, typename Filter_>
1696 class ILUPrecond : public SolverBase<typename Matrix_::VectorTypeL>
1697 {
1698 private:
1699 std::shared_ptr<ILUPrecondBase<Matrix_>> _impl;
1700
1701 public:
1702 typedef Matrix_ MatrixType;
1703 typedef Filter_ FilterType;
1704 typedef typename MatrixType::VectorTypeL VectorType;
1705 typedef typename MatrixType::DataType DataType;
1706
1709
1710 public:
1727 ILUPrecond(PreferredBackend backend, const MatrixType& matrix, const FilterType& filter, const int p = 0)
1728 {
1729 switch (backend)
1730 {
1732 _impl = std::make_shared<ILUPrecondWithBackend<PreferredBackend::cuda, Matrix_, Filter_>>(matrix, filter);
1733 break;
1736 default:
1737 _impl = std::make_shared<ILUPrecondWithBackend<PreferredBackend::generic, Matrix_, Filter_>>(matrix, filter, p);
1738 }
1739 }
1740
1760 ILUPrecond(const String& section_name, const PropertyMap* section, PreferredBackend backend, const MatrixType& matrix, const FilterType& filter) :
1761 BaseClass(section_name, section)
1762 {
1763 switch (backend)
1764 {
1766 _impl = std::make_shared<ILUPrecondWithBackend<PreferredBackend::cuda, Matrix_, Filter_>>(section_name, section, matrix, filter);
1767 break;
1770 default:
1771 _impl = std::make_shared<ILUPrecondWithBackend<PreferredBackend::generic, Matrix_, Filter_>>(section_name, section, matrix, filter);
1772 }
1773 }
1774
1778 virtual ~ILUPrecond()
1779 {
1780 }
1781
1783 virtual String name() const override
1784 {
1785 return _impl->name();
1786 }
1787
1794 virtual void set_fill_in_param(int p)
1795 {
1796 _impl->set_fill_in_param(p);
1797 }
1798
1805 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
1806 {
1807 return _impl->apply(vec_cor, vec_def);
1808 }
1809
1810 virtual void init_symbolic() override
1811 {
1812 _impl->init_symbolic();
1813 }
1814
1815 virtual void done_symbolic() override
1816 {
1817 _impl->done_symbolic();
1818 }
1819
1820 virtual void init_numeric() override
1821 {
1822 _impl->init_numeric();
1823 }
1824 }; // class ILUPrecond
1825
1844 template<typename Matrix_, typename Filter_>
1845 inline std::shared_ptr<ILUPrecond<Matrix_, Filter_>> new_ilu_precond(PreferredBackend backend,
1846 const Matrix_& matrix, const Filter_& filter, const int p = 0)
1847 {
1848 return std::make_shared<ILUPrecond<Matrix_, Filter_>>(backend, matrix, filter, p);
1849 }
1850
1872 template<typename Matrix_, typename Filter_>
1873 inline std::shared_ptr<ILUPrecond<Matrix_, Filter_>> new_ilu_precond(
1874 const String& section_name, const PropertyMap* section, PreferredBackend backend,
1875 const Matrix_& matrix, const Filter_& filter)
1876 {
1877 return std::make_shared<ILUPrecond<Matrix_, Filter_>>(section_name, section, backend, matrix, filter);
1878 }
1879 } // namespace Solver
1880} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
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.
CSR based sparse matrix.
Index num_cols() const
Retrieve matrix column count.
Index num_rows() const
Retrieve matrix row count.
Typed memory view class.
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.
Definition: exception.hpp:132
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 &section_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 Status apply(VectorType &out, const VectorType &in) override
apply the preconditioner
virtual Status apply(VectorType &out, const VectorType &in) override
apply the preconditioner
ILUPrecondWithBackend(const MatrixType &matrix, const FilterType &filter, const int p=0)
Constructor.
ILU(0) and ILU(p) preconditioner internal implementation.
Polymorphic solver interface.
Definition: base.hpp:183
static void add_flops(Index flops)
Add an amount of flops to the global flop counter.
Definition: statistics.hpp:206
String class implementation.
Definition: string.hpp:47
Time stamp class.
Definition: time_stamp.hpp:54
double elapsed(const TimeStamp &before) const
Calculates the time elapsed between two time stamps.
Definition: time_stamp.hpp:100
Status
Solver status return codes enumeration.
Definition: base.hpp:47
@ 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.
FEAT namespace.
Definition: adjactor.hpp:12
PreferredBackend
The backend that shall be used in all compute heavy calculations.
Definition: backend.hpp:18