FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
ssor_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
10#include <kernel/solver/base.hpp>
11
12namespace FEAT
13{
14 namespace Solver
15 {
16 namespace Intern
17 {
18 int cuda_ssor_forward_apply(int m, double * y, const double * x, const double * csrVal, const int * csrColInd, int ncolors, double omega,
19 int * colored_row_ptr, int * rows_per_color, int * inverse_row_ptr);
20 int cuda_ssor_backward_apply(int m, double * y, const double * x, const double * csrVal, const int * csrColInd, int ncolors, double omega,
21 int * colored_row_ptr, int * rows_per_color, int * inverse_row_ptr);
22 template <int block_size_>
23 int cuda_ssor_forward_bcsr_apply(int m, double * y, const double * x, const double * csrVal, const int * csrColInd, int ncolors, double omega,
24 int * colored_row_ptr, int * rows_per_color, int * inverse_row_ptr);
25 template <int block_size_>
26 int cuda_ssor_backward_bcsr_apply(int m, double * y, const double * x, const double * csrVal, const int * csrColInd, int ncolors, double omega,
27 int * colored_row_ptr, int * rows_per_color, int * inverse_row_ptr);
28 void cuda_sor_done_symbolic(int * colored_row_ptr, int * rows_per_color, int * inverse_row_ptr);
29 void cuda_sor_init_symbolic(int m, int nnz, const double * csrVal, const int * csrRowPtr, const int * csrColInd, int & ncolors,
30 int* & colored_row_ptr, int* & rows_per_color, int* & inverse_row_ptr);
31 }
32
47 template<typename Matrix_>
49 {
50 public:
51 typedef typename Matrix_::DataType DataType;
52 typedef typename Matrix_::VectorTypeL VectorType;
53
54 virtual void set_omega(DataType omega) = 0;
55
56 virtual void init_symbolic() = 0;
57
58 virtual void done_symbolic() = 0;
59
60 virtual String name() const = 0;
61
62 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) = 0;
63
64 virtual ~SSORPrecondBase() {}
65 }; // SSORPrecondBase class
66
67 template<PreferredBackend backend_, typename Matrix_, typename Filter_>
69
83 template<typename Filter_, typename DT_, typename IT_>
85 public SSORPrecondBase<typename LAFEM::SparseMatrixCSR<DT_, IT_>>
86 {
87 public:
89 typedef DT_ DataType;
90 typedef IT_ IndexType;
91 typedef Filter_ FilterType;
92 typedef typename MatrixType::VectorTypeL VectorType;
93
94 protected:
95 const MatrixType& _matrix;
96 const FilterType& _filter;
97 DataType _omega;
98
99 public:
113 explicit SSORPrecondWithBackend(const MatrixType& matrix, const FilterType& filter, const DataType omega = DataType(1)) :
114 _matrix(matrix),
115 _filter(filter),
116 _omega(omega)
117 {
118 if (_matrix.num_cols() != _matrix.num_rows())
119 {
120 XABORTM("Matrix is not square!");
121 }
122 }
123
124 explicit SSORPrecondWithBackend(const String& section_name, const PropertyMap* section,
125 const MatrixType& matrix, const FilterType& filter) :
126 _matrix(matrix),
127 _filter(filter),
128 _omega(1)
129 {
130 if (_matrix.num_cols() != _matrix.num_rows())
131 {
132 XABORTM("Matrix is not square!");
133 }
134
135 auto omega_p = section->query("omega");
136 if(omega_p.second && !omega_p.first.parse(this->_omega))
137 throw ParseError(section_name + ".omega", omega_p.first, "a positive float");
138 }
139
141 virtual String name() const override
142 {
143 return "SSOR";
144 }
145
153 virtual void set_omega(DataType omega) override
154 {
155 XASSERT(omega > DataType(0));
156 _omega = omega;
157 }
158
159 virtual void init_symbolic() override
160 {
161 }
162
163 virtual void done_symbolic() override
164 {
165 }
166
167 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
168 {
169 XASSERTM(_matrix.num_rows() == vec_cor.size(), "matrix / vector size mismatch!");
170 XASSERTM(_matrix.num_rows() == vec_def.size(), "matrix / vector size mismatch!");
171
172 TimeStamp ts_start;
173
174 // copy in-vector to out-vector
175 vec_cor.copy(vec_def);
176
177 _apply_intern(_matrix, vec_cor, vec_def);
178
179 vec_cor.scale(vec_cor, _omega * (DataType(2.0) - _omega));
180
181 this->_filter.filter_cor(vec_cor);
182
183 TimeStamp ts_stop;
184 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
185 Statistics::add_flops(_matrix.num_nzes() *2 + 6 * vec_cor.size());
186
187 return Status::success;
188 }
189
190 protected:
191 void _apply_intern(const LAFEM::SparseMatrixCSR<DataType, IndexType>& matrix, VectorType& vec_cor, const VectorType& vec_def)
192 {
193 // create pointers
194 Memory::TypedView<DataType> pout(vec_cor.elements_view_rw());
195 const Memory::TypedView<DataType> pin(vec_def.elements_view_r());
196 const Memory::TypedView<DataType> pval(matrix.val_view_r());
197 const Memory::TypedView<IndexType> pcol_idx(matrix.col_idx_view_r());
198 const Memory::TypedView<IndexType> prow_ptr(matrix.row_ptr_view_r());
199 const IndexType n((IndexType(matrix.num_rows())));
200
201 // __forward-insertion__
202 // iteration over all rows
203 for (Index i(0); i < n; ++i)
204 {
205 IndexType col;
206 DataType d(0);
207 // iteration over all elements on the left side of the main-diagonal
208 for (col = prow_ptr[i]; pcol_idx[col] < i; ++col)
209 {
210 d += pval[col] * pout[pcol_idx[col]];
211 }
212 pout[i] = (pin[i] - _omega * d) / pval[col];
213 }
214
215 // __backward-insertion__
216 // iteration over all rows
217 for (Index i(n); i > 0;)
218 {
219 --i;
220 IndexType col;
221 DataType d(0);
222 // iteration over all elements on the right side of the main-diagonal
223 for (col = prow_ptr[i+1] - IndexType(1); pcol_idx[col] > i; --col)
224 {
225 d += pval[col] * pout[pcol_idx[col]];
226 }
227 pout[i] -= _omega * d / pval[col];
228 }
229 }
230 }; // class SSORPrecondWithBackend<generic, SparseMatrixCSR>
231
232 template<typename Filter_, typename DT_, typename IT_, int block_height_, int block_width_>
233 class SSORPrecondWithBackend<PreferredBackend::generic, LAFEM::SparseMatrixBCSR<DT_, IT_, block_height_, block_width_>, Filter_> :
234 public SSORPrecondBase<typename LAFEM::SparseMatrixBCSR<DT_, IT_, block_height_, block_width_>>
235 {
236 static_assert(block_height_ == block_width_, "only square blocks are supported!");
237 public:
239 typedef Filter_ FilterType;
240 typedef typename MatrixType::VectorTypeL VectorType;
241 typedef typename MatrixType::DataType DataType;
242 typedef typename MatrixType::IndexType IndexType;
243
244 protected:
245 const MatrixType& _matrix;
246 const FilterType& _filter;
247 DataType _omega;
248
249 void _apply_intern(const MatrixType & matrix, VectorType& vec_cor, const VectorType& vec_def)
250 {
251 // create pointers
252 auto* pout(vec_cor.elements());
253 const auto* pin(vec_def.elements());
254 const auto* pval(matrix.val());
255 const IndexType * pcol_idx(matrix.col_idx());
256 const IndexType * prow_ptr(matrix.row_ptr());
257 const IndexType n((IndexType(matrix.num_rows())));
258 typename MatrixType::ValueType inverse;
259
260 // __forward-insertion__
261 // iteration over all rows
262 for (Index i(0); i < n; ++i)
263 {
264 IndexType col;
265 typename VectorType::ValueType d(0);
266 // iteration over all elements on the left side of the main-diagonal
267 for (col = prow_ptr[i]; pcol_idx[col] < i; ++col)
268 {
269 d += pval[col] * pout[pcol_idx[col]];
270 }
271 //pout[i] = (pin[i] - _omega * d) / pval[col];
272 inverse.set_inverse(pval[col]);
273 pout[i] = inverse * (pin[i] - _omega * d);
274 }
275
276 // __backward-insertion__
277 // iteration over all rows
278 for (Index i(n); i > 0;)
279 {
280 --i;
281 IndexType col;
282 typename VectorType::ValueType d(0);
283 // iteration over all elements on the right side of the main-diagonal
284 for (col = prow_ptr[i+1] - IndexType(1); pcol_idx[col] > i; --col)
285 {
286 d += pval[col] * pout[pcol_idx[col]];
287 }
288 //pout[i] -= _omega * d / pval[col];
289 inverse.set_inverse(pval[col]);
290 pout[i] = pout[i] - (_omega * inverse * d);
291 }
292 }
293
294 public:
308 explicit SSORPrecondWithBackend(const MatrixType& matrix, const FilterType& filter, const DataType omega = DataType(1)) :
309 _matrix(matrix),
310 _filter(filter),
311 _omega(omega)
312 {
313 if (_matrix.num_cols() != _matrix.num_rows())
314 {
315 XABORTM("Matrix is not square!");
316 }
317 }
318
319 explicit SSORPrecondWithBackend(const String& /*section_name*/, const PropertyMap* section,
320 const MatrixType& matrix, const FilterType& filter) :
321 _matrix(matrix),
322 _filter(filter),
323 _omega(1)
324 {
325 if (_matrix.num_cols() != _matrix.num_rows())
326 {
327 XABORTM("Matrix is not square!");
328 }
329
330 // Check if we have set _omega
331 auto omega_p = section->query("omega");
332 if(omega_p.second)
333 {
334 set_omega(DataType(std::stod(omega_p.first)));
335 }
336 }
337
339 virtual String name() const override
340 {
341 return "SSOR";
342 }
343
351 virtual void set_omega(DataType omega) override
352 {
353 XASSERT(omega > DataType(0));
354 _omega = omega;
355 }
356
357 virtual void init_symbolic() override
358 {
359 }
360
361 virtual void done_symbolic() override
362 {
363 }
364
365 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
366 {
367 XASSERTM(_matrix.num_rows() == vec_cor.size(), "matrix / vector size mismatch!");
368 XASSERTM(_matrix.num_rows() == vec_def.size(), "matrix / vector size mismatch!");
369
370 TimeStamp ts_start;
371
372 // copy in-vector to out-vector
373 vec_cor.copy(vec_def);
374
375 _apply_intern(_matrix, vec_cor, vec_def);
376
377 this->_filter.filter_cor(vec_cor);
378
379 TimeStamp ts_stop;
380 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
381 Statistics::add_flops(_matrix.num_nzes_raw() * 2 + 6 * vec_cor.size_raw());
382
383 return Status::success;
384 }
385 }; // class SSORPrecondWithBackend<generic, SparseMatrixBCSR>
386
387#ifdef FEAT_HAVE_CUDA
404 template<typename Filter_>
405 class SSORPrecondWithBackend<PreferredBackend::cuda, LAFEM::SparseMatrixCSR<double, unsigned int>, Filter_> :
406 public SSORPrecondBase<LAFEM::SparseMatrixCSR<double, unsigned int>>
407 {
408 public:
409 typedef LAFEM::SparseMatrixCSR<double, unsigned int> MatrixType;
410 typedef Filter_ FilterType;
411 typedef typename MatrixType::VectorTypeL VectorType;
412 typedef typename MatrixType::DataType DataType;
413 typedef typename MatrixType::IndexType IndexType;
414
415 protected:
416 const MatrixType& _matrix;
417 const FilterType& _filter;
418 double _omega;
419 // row ptr permutation, sorted by color(each color sorted by amount of rows), start/end index per row
420 int * _colored_row_ptr;
421 // amount of rows per color (sorted by amount of rows)
422 int * _rows_per_color;
423 // mapping of idx to native row number
424 int * _inverse_row_ptr;
425 // number of colors
426 int _ncolors;
427
428 public:
442 explicit SSORPrecondWithBackend(const MatrixType& matrix, const FilterType& filter, const DataType omega = DataType(1)) :
443 _matrix(matrix),
444 _filter(filter),
445 _omega(omega),
446 _colored_row_ptr(nullptr),
447 _rows_per_color(nullptr),
448 _inverse_row_ptr(nullptr),
449 _ncolors(0)
450 {
451 if (_matrix.num_cols() != _matrix.num_rows())
452 {
453 XABORTM("Matrix is not square!");
454 }
455 }
456
457 explicit SSORPrecondWithBackend(const String& /*section_name*/, const PropertyMap* section,
458 const MatrixType& matrix, const FilterType& filter) :
459 _matrix(matrix),
460 _filter(filter),
461 _omega(1),
462 _colored_row_ptr(nullptr),
463 _rows_per_color(nullptr),
464 _inverse_row_ptr(nullptr),
465 _ncolors(0)
466 {
467 if (_matrix.num_cols() != _matrix.num_rows())
468 {
469 XABORTM("Matrix is not square!");
470 }
471
472 // Check if we have set _omega
473 auto omega_p = section->query("omega");
474 if(omega_p.second)
475 {
476 set_omega(DataType(std::stod(omega_p.first)));
477 }
478 }
479
481 virtual String name() const override
482 {
483 return "SSOR";
484 }
485
493 virtual void set_omega(DataType omega) override
494 {
495 XASSERT(omega > DataType(0));
496 _omega = omega;
497 }
498
499 virtual void init_symbolic() override
500 {
501 Memory::TypedView<DataType> a = _matrix.val_view_r(Memory::Location::cuda);
502 // cast from 'unsigned int' to 'int'
503 Memory::TypedView<int> row_ptr(std::forward<Memory::View&&>(_matrix.row_ptr_view_r(Memory::Location::cuda)));
504 Memory::TypedView<int> col_idx(std::forward<Memory::View&&>(_matrix.col_idx_view_r(Memory::Location::cuda)));
505 Intern::cuda_sor_init_symbolic((int)_matrix.num_rows(), (int)_matrix.num_nzes(), a.get_r(), row_ptr.get_r(), col_idx.get_r(), _ncolors,
506 _colored_row_ptr, _rows_per_color, _inverse_row_ptr);
507 }
508
509 virtual void done_symbolic() override
510 {
511 Intern::cuda_sor_done_symbolic(_colored_row_ptr, _rows_per_color, _inverse_row_ptr);
512 }
513
514 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
515 {
516 XASSERTM(_matrix.num_rows() == vec_cor.size(), "matrix / vector size mismatch!");
517 XASSERTM(_matrix.num_rows() == vec_def.size(), "matrix / vector size mismatch!");
518
519 TimeStamp ts_start;
520
521 int status = 0;
522
523 {
524 Memory::TypedView<DataType> vx = vec_cor.elements_view_w(Memory::Location::cuda);
525 const Memory::TypedView<DataType> vb = vec_def.elements_view_r(Memory::Location::cuda);
526 const Memory::TypedView<DataType> a = _matrix.val_view_r(Memory::Location::cuda);
527 // cast from 'unsigned int' to 'int'
528 Memory::TypedView<int> col_idx(std::forward<Memory::View&&>(_matrix.col_idx_view_r(Memory::Location::cuda)));
529
530 status |= Intern::cuda_ssor_forward_apply((int)vec_cor.size(), vx.get_w(), vb.get_r(), a.get_r(), col_idx.get_r(), _ncolors, _omega, _colored_row_ptr, _rows_per_color, _inverse_row_ptr);
531 status |= Intern::cuda_ssor_backward_apply((int)vec_cor.size(), vx.get_w(), vb.get_r(), a.get_r(), col_idx.get_r(), _ncolors, _omega, _colored_row_ptr, _rows_per_color, _inverse_row_ptr);
532 }
533
534 vec_cor.scale(vec_cor, _omega * (2.0 - _omega));
535
536 this->_filter.filter_cor(vec_cor);
537
538 TimeStamp ts_stop;
539 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
540 Statistics::add_flops(_matrix.num_nzes() *2 + 6 * vec_cor.size());
541
542 return (status == 0) ? Status::success : Status::aborted;
543 }
544 }; // class SSORPrecondWithBackend<cuda, SparseMatrixCSR>
545
546 template<typename Filter_, int block_height_, int block_width_>
547 class SSORPrecondWithBackend<PreferredBackend::cuda, LAFEM::SparseMatrixBCSR<double, unsigned int, block_height_, block_width_>, Filter_> :
548 public SSORPrecondBase<typename LAFEM::SparseMatrixBCSR<double, unsigned int, block_height_, block_width_>>
549 {
550 static_assert(block_height_ == block_width_, "only square blocks are supported!");
551 public:
552 typedef LAFEM::SparseMatrixBCSR<double, unsigned int, block_height_, block_width_> MatrixType;
553 typedef Filter_ FilterType;
554 typedef typename MatrixType::VectorTypeL VectorType;
555 typedef typename MatrixType::DataType DataType;
556 typedef typename MatrixType::IndexType IndexType;
557
558 protected:
559 const MatrixType& _matrix;
560 const FilterType& _filter;
561 double _omega;
562 // row ptr permutation, sorted by color(each color sorted by amount of rows), start/end index per row
563 int * _colored_row_ptr;
564 // amount of rows per color (sorted by amount of rows)
565 int * _rows_per_color;
566 // mapping of idx to native row number
567 int * _inverse_row_ptr;
568 // number of colors
569 int _ncolors;
570
571 public:
585 explicit SSORPrecondWithBackend(const MatrixType& matrix, const FilterType& filter, const DataType omega = DataType(1)) :
586 _matrix(matrix),
587 _filter(filter),
588 _omega(omega),
589 _colored_row_ptr(nullptr),
590 _rows_per_color(nullptr),
591 _inverse_row_ptr(nullptr),
592 _ncolors(0)
593 {
594 if (_matrix.num_cols() != _matrix.num_rows())
595 {
596 XABORTM("Matrix is not square!");
597 }
598 }
599
600 explicit SSORPrecondWithBackend(const String& /*section_name*/, const PropertyMap* section,
601 const MatrixType& matrix, const FilterType& filter) :
602 _matrix(matrix),
603 _filter(filter),
604 _omega(1),
605 _colored_row_ptr(nullptr),
606 _rows_per_color(nullptr),
607 _inverse_row_ptr(nullptr),
608 _ncolors(0)
609 {
610 if (_matrix.num_cols() != _matrix.num_rows())
611 {
612 XABORTM("Matrix is not square!");
613 }
614
615 // Check if we have set _omega
616 auto omega_p = section->query("omega");
617 if(omega_p.second)
618 {
619 set_omega(DataType(std::stod(omega_p.first)));
620 }
621 }
622
624 virtual String name() const override
625 {
626 return "SSOR";
627 }
628
636 virtual void set_omega(DataType omega) override
637 {
638 XASSERT(omega > DataType(0));
639 _omega = omega;
640 }
641
642 virtual void init_symbolic() override
643 {
644 Memory::TypedView<DataType> a = _matrix.val_view_raw_r(Memory::Location::cuda);
645 const Memory::TypedView<IndexType> row_ptr = _matrix.row_ptr_view_r(Memory::Location::cuda);
646 const Memory::TypedView<IndexType> col_idx = _matrix.col_idx_view_r(Memory::Location::cuda);
647 Intern::cuda_sor_init_symbolic((int)_matrix.num_rows(), (int)_matrix.num_nzes(), a.get_r(), row_ptr.get_r(), col_idx.get_r(), _ncolors,
648 _colored_row_ptr, _rows_per_color, _inverse_row_ptr);
649 }
650
651 virtual void done_symbolic() override
652 {
653 Intern::cuda_sor_done_symbolic(_colored_row_ptr, _rows_per_color, _inverse_row_ptr);
654 }
655
656 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
657 {
658 XASSERTM(_matrix.num_rows() == vec_cor.size(), "matrix / vector size mismatch!");
659 XASSERTM(_matrix.num_rows() == vec_def.size(), "matrix / vector size mismatch!");
660
661 TimeStamp ts_start;
662
663 int status = 0;
664
665 {
666 Memory::TypedView<DataType> vx = vec_cor.elements_view_raw_w(Memory::Location::cuda);
667 const Memory::TypedView<DataType> vb = vec_def.elements_view_raw_r(Memory::Location::cuda);
668 const Memory::TypedView<DataType> a = _matrix.val_view_raw_r(Memory::Location::cuda);
669 const Memory::TypedView<IndexType> col_idx = _matrix.col_idx_view_r(Memory::Location::cuda);
670
671 status |= Intern::cuda_ssor_forward_bcsr_apply<block_height_>((int)vec_cor.size(), vx.get_w(),vb.get_r(), a.get_r(), col_idx.get_r(), _ncolors, _omega, _colored_row_ptr, _rows_per_color, _inverse_row_ptr);
672 status |= Intern::cuda_ssor_backward_bcsr_apply<block_height_>((int)vec_cor.size(), vx.get_w(), vb.get_r(), a.get_r(), col_idx.get_r(), _ncolors, _omega, _colored_row_ptr, _rows_per_color, _inverse_row_ptr);
673 }
674
675 vec_cor.scale(vec_cor, _omega * (2.0 - _omega));
676
677 this->_filter.filter_cor(vec_cor);
678
679 TimeStamp ts_stop;
680 Statistics::add_time_precon(ts_stop.elapsed(ts_start));
681 Statistics::add_flops(_matrix.num_nzes_raw() *2 + 6 * vec_cor.size_raw());
682
683 return (status == 0) ? Status::success : Status::aborted;
684 }
685 }; // class SSORPrecondWithBackend<cuda, SparseMatrixBCSR>
686#endif //FEAT_HAVE_CUDA
687
689 template<PreferredBackend backend_, typename Matrix_, typename Filter_>
691 public SSORPrecondBase<Matrix_>
692 {
693 public:
694 template<typename DT_>
695 explicit SSORPrecondWithBackend(const Matrix_&, const Filter_&, const DT_)
696 {
697 }
698
699 explicit SSORPrecondWithBackend(const Matrix_&, const Filter_&)
700 {
701 }
702
703 explicit SSORPrecondWithBackend(const String&, const PropertyMap*, const Matrix_&, const Filter_&)
704 {
705 }
706
707 virtual Status apply(typename Matrix_::VectorTypeL &, const typename Matrix_::VectorTypeL &) override
708 {
709 XABORTM("not implemented yet!");
710 }
711
712 virtual String name() const override
713 {
714 XABORTM("not implemented yet!");
715 }
716
717 virtual void init_symbolic() override
718 {
719 XABORTM("not implemented yet!");
720 }
721
722 virtual void done_symbolic() override
723 {
724 XABORTM("not implemented yet!");
725 }
726
727 virtual void set_omega(typename Matrix_::DataType /*omega*/) override
728 {
729 XABORTM("not implemented yet!");
730 }
731 };
732
745 template<typename Matrix_, typename Filter_>
746 class SSORPrecond : public SolverBase<typename Matrix_::VectorTypeL>
747 {
748 private:
749 std::shared_ptr<SSORPrecondBase<Matrix_>> _impl;
750
751 public:
752 typedef Matrix_ MatrixType;
753 typedef Filter_ FilterType;
754 typedef typename MatrixType::VectorTypeL VectorType;
755 typedef typename MatrixType::DataType DataType;
756
759
760 public:
777 SSORPrecond(const PreferredBackend backend, const MatrixType& matrix, const FilterType& filter, DataType omega = DataType(1))
778 {
779 switch (backend)
780 {
782 _impl = std::make_shared<SSORPrecondWithBackend<PreferredBackend::cuda, Matrix_, Filter_>>(matrix, filter, omega);
783 break;
786 default:
787 _impl = std::make_shared<SSORPrecondWithBackend<PreferredBackend::generic, Matrix_, Filter_>>(matrix, filter, omega);
788 }
789 }
790
810 SSORPrecond(const PreferredBackend backend, const String& section_name, const PropertyMap* section, const MatrixType& matrix, const FilterType& filter, DataType omega = DataType(1)) :
811 BaseClass(section_name, section)
812 {
813 switch (backend)
814 {
816 _impl = std::make_shared<SSORPrecondWithBackend<PreferredBackend::cuda, Matrix_, Filter_>>(section_name, section, matrix, filter, omega);
817 break;
820 default:
821 _impl = std::make_shared<SSORPrecondWithBackend<PreferredBackend::generic, Matrix_, Filter_>>(section_name, section, matrix, filter, omega);
822 }
823 }
824
828 virtual ~SSORPrecond()
829 {
830 }
831
833 virtual String name() const override
834 {
835 return _impl->name();
836 }
837
845 virtual void set_omega(DataType omega)
846 {
847 _impl->set_omega(omega);
848 }
849
850 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
851 {
852 return _impl->apply(vec_cor, vec_def);
853 }
854
855 virtual void init_symbolic() override
856 {
857 _impl->init_symbolic();
858 }
859
860 virtual void done_symbolic() override
861 {
862 _impl->done_symbolic();
863 }
864 }; // class SSORPrecond
865
884 template<typename Matrix_, typename Filter_>
885 inline std::shared_ptr<SSORPrecond<Matrix_, Filter_>> new_ssor_precond(
886 const PreferredBackend backend, const Matrix_& matrix, const Filter_& filter,
887 const typename Matrix_::DataType omega = typename Matrix_::DataType(1))
888 {
889 return std::make_shared<SSORPrecond<Matrix_, Filter_>>
890 (backend, matrix, filter, omega);
891 }
892
914 template<typename Matrix_, typename Filter_>
915 inline std::shared_ptr<SSORPrecond<Matrix_, Filter_>> new_ssor_precond(
916 const String& section_name, const PropertyMap* section, PreferredBackend backend,
917 const Matrix_& matrix, const Filter_& filter)
918 {
919 return std::make_shared<SSORPrecond<Matrix_, Filter_>>
920 (backend, section_name, section, matrix, filter);
921 }
922 } // namespace Solver
923} // 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
FEAT Kernel base header.
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_nzes_raw() const
Returns the scalar matrix nonzero element count.
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.
Index num_nzes() const
Retrieve non zero element count.
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 sor_precond.hpp.
SSOR preconditioner implementation.
virtual void done_symbolic() override
Symbolic finalization method.
SSORPrecond(const PreferredBackend backend, const MatrixType &matrix, const FilterType &filter, DataType omega=DataType(1))
Constructor.
SSORPrecond(const PreferredBackend backend, const String &section_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, DataType omega=DataType(1))
Constructor using a PropertyMap.
virtual ~SSORPrecond()
Empty virtual destructor.
virtual void init_symbolic() override
Symbolic initialization method.
virtual void set_omega(DataType omega)
Sets the damping parameter.
virtual String name() const override
Returns the name of the solver.
SolverBase< VectorType > BaseClass
Our base class.
SSORPrecondWithBackend(const MatrixType &matrix, const FilterType &filter, const DataType omega=DataType(1))
Constructor.
SSORPrecondWithBackend(const MatrixType &matrix, const FilterType &filter, const DataType omega=DataType(1))
Constructor.
Dummy class for not implemented specializations.
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
Tiny Matrix class template.
CUDA_HOST_DEVICE Matrix & set_inverse(const Matrix< T_, m_, n_, sma_, sna_ > &a)
Sets this matrix to the inverse of another matrix.
std::shared_ptr< SSORPrecond< Matrix_, Filter_ > > new_ssor_precond(const PreferredBackend backend, const Matrix_ &matrix, const Filter_ &filter, const typename Matrix_::DataType omega=typename Matrix_::DataType(1))
Creates a new SSORPrecond solver object.
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)
FEAT namespace.
Definition: adjactor.hpp:12
PreferredBackend
The backend that shall be used in all compute heavy calculations.
Definition: backend.hpp:18
std::uint64_t Index
Index data type.