FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
amavanka_gmres.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/iterative.hpp>
10#include <kernel/global/matrix.hpp>
11#include <kernel/global/filter.hpp>
12#include <kernel/global/vector.hpp>
13#include <kernel/lafem/arch/batched_vector_apply.hpp>
14#include <kernel/lafem/tuple_mirror.hpp>
15#include <kernel/lafem/vector_mirror.hpp>
16#include <kernel/solver/amavanka.hpp>
17#include <kernel/lafem/unit_filter.hpp>
18#include <kernel/lafem/unit_filter_blocked.hpp>
19#include <kernel/lafem/tuple_filter.hpp>
20#include <kernel/lafem/filter_chain.hpp>
21#include <kernel/lafem/filter_sequence.hpp>
22#include <kernel/lafem/slip_filter.hpp>
23#include <kernel/lafem/none_filter.hpp>
24#include <kernel/lafem/mean_filter.hpp>
25#include <kernel/lafem/mean_filter_blocked.hpp>
26
27#include <kernel/solver/backend_aux/csr_apply_helper.hpp>
28
29#include <kernel/solver/krylov_orthogonalizer.hpp>
30
31#ifdef FEAT_HAVE_CUDA
32#include <kernel/util/cuda_util.hpp>
33#endif
34
35// includes, FEAT
36#include <vector>
37
38namespace FEAT
39{
40 namespace Solver
41 {
42 namespace VankaGMRES
43 {
44 template<typename DT_, typename IT_>
45 FEAT::Solver::Status cuda_apply_amavanka_gmres_seq(Memory::Arbiter& vec_sol, const Memory::Arbiter& vec_rhs, const CSRHelper::GMRESApplyInfo<DT_, IT_>& apply_info, CSRHelper::GMRESStatus<DT_>& status);
46
47 template<typename DT_, typename IT_>
48 FEAT::Solver::Status cuda_apply_amavanka_gmres_parallel(Memory::Arbiter& vec_sol, const Memory::Arbiter& vec_rhs, const CSRHelper::GMRESApplyInfo<DT_, IT_>& apply_info, CSRHelper::GMRESStatus<DT_>& status);
49 }
50
51 namespace Intern
52 {
53 template<typename, typename = void>
54 static constexpr int dim_vector = 1;
55
56 template<typename T>
57 static constexpr int dim_vector<T,
58 std::void_t<decltype(T::block_size)>> = T::block_size;
59
60 template<typename InMirror_>
62
63 template<typename First_, typename... Rest_>
64 class MirrorHelper<LAFEM::TupleMirror<First_, Rest_...>>
65 {
66 public:
67 typedef LAFEM::TupleMirror<First_, Rest_...> InMirrorType;
68
69 template<typename OutMirror_, typename FVec_, typename RVec_>
70 static std::pair<Index, Index> fill_mirror(OutMirror_& mirror, const InMirrorType& input, const LAFEM::TupleVector<FVec_, RVec_>& tvec, std::pair<Index, Index> offsets = {0u, 0u})
71 {
72 offsets = MirrorHelper<First_>::fill_mirror(mirror, input.first(), tvec.first(), offsets);
73 return MirrorHelper<LAFEM::TupleMirror<Rest_...>>::fill_mirror(mirror, input.rest(), tvec.rest(), offsets);
74 }
75 };
76
77 template<typename First_>
78 class MirrorHelper<LAFEM::TupleMirror<First_>>
79 {
80 public:
82
83 template<typename OutMirror_, typename FVec_>
84 static std::pair<Index, Index> fill_mirror(OutMirror_& mirror, const InMirrorType& input, const LAFEM::TupleVector<FVec_>& tvec, std::pair<Index, Index> offsets = {0u, 0u})
85 {
86 offsets = MirrorHelper<First_>::fill_mirror(mirror, input.first(), tvec.first(), offsets);
87 return offsets;
88 }
89 };
90
91 template<typename DT_, typename IT_>
92 class MirrorHelper<LAFEM::VectorMirror<DT_, IT_>>
93 {
94 public:
96
97 template<typename OutMirror_, typename Vec_>
98 static std::pair<Index, Index> fill_mirror(OutMirror_& mirror, const InMirrorType& input, const Vec_& vec, std::pair<Index, Index> offsets = {0u, 0u})
99 {
100 // get indices (host-side views into the mirror index arrays)
101 const auto indices_view = input.indices_view_r();
102 const auto* indices = indices_view.get_r();
103 const Index& dof_offset = offsets.first;
104 const Index& ptr_offset = offsets.second;
105 auto target_view = mirror.indices_view_w();
106 auto* target = target_view.get_w() + ptr_offset;
107 constexpr int dim = dim_vector<Vec_>;
108 for(Index k = 0; k < input.num_indices(); ++k)
109 {
110 for(int d = 0; d < dim; ++d)
111 {
112 target[k*dim + Index(d)] = IT_(indices[k]*dim + Index(d) + dof_offset);
113 }
114 }
115 offsets.first += vec.size_raw();
116 offsets.second += input.num_indices()*dim;
117 return offsets;
118 }
119 };
120
121 template<typename InFilterType_>
123 {
124 public:
125 template<typename DT_, typename IT_, typename Vec_>
126 static Index add_filter(std::map<IT_, DT_>&, const InFilterType_& DOXY(filter), const Vec_& vec, Index offset = 0u)
127 {
128 // XABORTM("Not implemented");
129 return offset + vec.size_raw();
130 }
131 };
132
133 template<typename First_, typename... Rest_>
134 class FilterHelper<LAFEM::TupleFilter<First_, Rest_...>>
135 {
136 public:
137 typedef LAFEM::TupleFilter<First_, Rest_...> InFilterType;
139 template<typename DT_, typename IT_, typename FVec_, typename RVec_>
140 static Index add_filter(std::map<IT_, DT_>& filter_map, const InFilterType& input, const LAFEM::TupleVector<FVec_, RVec_>& vec, Index offset = 0u)
141 {
142 offset = FilterHelper<First_>::add_filter(filter_map, input.first(), vec.first(), offset);
143 offset = FilterHelper<LAFEM::TupleFilter<Rest_...>>::add_filter(filter_map, input.rest(), vec.rest(), offset);
144 return offset;
145 }
146 };
147
148 template<typename First_>
149 class FilterHelper<LAFEM::TupleFilter<First_>>
150 {
151 public:
154 template<typename DT_, typename IT_, typename FVec_>
155 static Index add_filter(std::map<IT_, DT_>& filter_map, const InFilterType& input, const LAFEM::TupleVector<FVec_>& vec, Index offset = 0u)
156 {
157 offset = FilterHelper<First_>::add_filter(filter_map, input.first(), vec.first(), offset);
158 return offset;
159 }
160 };
161
162 template<typename First_, typename... Rest_>
163 class FilterHelper<LAFEM::FilterChain<First_, Rest_...>>
164 {
165 public:
166 typedef LAFEM::FilterChain<First_, Rest_...> InFilterType;
168 template<typename DT_, typename IT_, typename Vec_>
169 static Index add_filter(std::map<IT_, DT_>& filter_map, const InFilterType& input, const Vec_& vec, Index offset = 0u)
170 {
171 FilterHelper<First_>::add_filter(filter_map, input.first(), vec, offset);
172 return FilterHelper<LAFEM::FilterChain<Rest_...>>::add_filter(filter_map, input.rest(), vec, offset);
173 }
174 };
175
176 template<typename First_>
177 class FilterHelper<LAFEM::FilterChain<First_>>
178 {
179 public:
182 template<typename DT_, typename IT_, typename Vec_>
183 static Index add_filter(std::map<IT_, DT_>& filter_map, const InFilterType& input, const Vec_& vec, Index offset = 0u)
184 {
185 return FilterHelper<First_>::add_filter(filter_map, input.first(), vec, offset);
186 }
187 };
188
189 template<typename FType_>
190 class FilterHelper<LAFEM::FilterSequence<FType_>>
191 {
192 public:
195 template<typename DT_, typename IT_, typename Vec_>
196 static Index add_filter(std::map<IT_, DT_>& filter_map, const InFilterType& input, const Vec_& vec, Index offset = 0u)
197 {
198 Index new_offset = offset;
199 for(auto& pair : input)
200 {
201 new_offset = FilterHelper<FType_>::add_filter(filter_map, pair.second, vec, offset);
202 }
203 return new_offset;
204 }
205 };
206
207 template<typename DTT_, typename ITT_>
208 class FilterHelper<LAFEM::UnitFilter<DTT_, ITT_>>
209 {
210 public:
213 template<typename DT_, typename IT_>
214 static Index add_filter(std::map<IT_, DT_>& filter_map, const InFilterType& input, const LAFEM::DenseVector<DTT_, ITT_>& vec, Index offset = 0u)
215 {
216 if(input.num_nzes() > 0u)
217 {
218 const auto& sv = input.get_filter_vector();
219 const auto idx_view = sv.indices_view_r();
220 const auto val_view = sv.elements_view_r();
221 const auto* svi = idx_view.get_r();
222 const auto* svd = val_view.get_r();
223 for(Index k = 0; k < sv.num_nzes(); ++k)
224 {
225 filter_map.insert_or_assign(IT_(svi[k]+offset), DT_(svd[k]));
226 }
227 }
228 return offset+vec.size();
229 }
230 };
231
232 template<typename DTT_, typename ITT_, int dim_>
233 class FilterHelper<LAFEM::UnitFilterBlocked<DTT_, ITT_, dim_>>
234 {
235 public:
238 template<typename DT_, typename IT_>
239 static Index add_filter(std::map<IT_, DT_>& filter_map, const InFilterType& input, const LAFEM::DenseVectorBlocked<DTT_, ITT_, dim_>& vec, Index offset = 0u)
240 {
241 if(input.num_nzes() > 0u)
242 {
243 const auto& sv = input.get_filter_vector();
244 const auto idx_view = sv.indices_view_r();
245 const auto val_view = sv.elements_view_r();
246 const auto* svi = idx_view.get_r();
247 const auto* svd = val_view.get_r();
248 for(Index k = 0; k < sv.num_nzes(); ++k)
249 {
250 for(int d = 0; d < dim_; ++d)
251 filter_map.insert_or_assign(IT_(dim_)*svi[k]+IT_(d)+IT_(offset), DT_(svd[k][d]));
252 }
253 }
254 return offset+vec.size_raw();
255 }
256 };
257 }
279 template<
280 typename Matrix_,
281 typename Filter_>
283
284 template<
285 typename LocalMatrix_,
286 typename LocalFilter_,
287 typename MirrorRow_,
288 typename MirrorCol_>
289 class AmaVankaGMRES<Global::Matrix<LocalMatrix_, MirrorRow_, MirrorCol_>, Global::Filter<LocalFilter_, MirrorRow_>>:
290 public IterativeSolver<typename Global::Matrix<LocalMatrix_, MirrorRow_, MirrorCol_>::VectorTypeR>
291 {
292 public:
295 typedef typename MatrixType::VectorTypeR VectorType;
296 typedef typename MatrixType::DataType DataType;
297 typedef typename LocalMatrix_::IndexType IndexType;
300
301 // the internal types used
309
310
311 protected:
319 std::shared_ptr<VankaType> _vanka;
328
329
340 DataType _reortho_tol = DataType(0.3);
342 bool _force_reortho = false;
344 std::vector<GlobalVecType> _vec_v;
345 // std::vector<VecType> _vec_v_helper;
346 // arbiters of the krylov basis vectors (the kernel acquires its device views from them)
347 std::vector<Memory::Arbiter*> _vec_v_elements;
348 GlobalVecType _vec_w;
351 // VectorType _helper_v;
353 std::vector<DataType> _c, _s, _q;
355 std::vector<std::vector<DataType>> _h;
357 std::vector<DataType> _corr;
361
362 Index _global_vec_size;
363 Index _global_used_elements;
364 Index _internal_flop_counter;
365
366 bool _use_cuda_gmres;
367 bool _prefetch_data;
368 bool _always_use_parallel_kernel;
369
370 // void _construct_filter(FilType& internal_filter, const LocalFilter_& sys_filter)
371 // {
372 // // construct Local vector
373 // VecType loc_tmp;
374 // {
375 // auto tmp_vec = this->_system_matrix.local().create_vector_r();
376 // tmp_vec.format(DataType(1.8));
377 // sys_filter.filter_def(tmp_vec);
378 // loc_tmp.convert(tmp_vec);
379 // }
380
381 // internal_filter = FilType(loc_tmp.size());
382
383 // const auto* val = loc_tmp.elements();
384 // for(Index k = 0; k < loc_tmp.size(); ++k)
385 // {
386 // if(Math::abs(loc_tmp[k]) < DataType(0.0001))
387 // {
388 // internal_filter.add(k, DataType(0));
389 // }
390 // }
391 // }
392
393 public:
394
413 explicit AmaVankaGMRES(const MatrixType& matrix, const FilterType& filter, std::shared_ptr<VankaType> vanka, Index krylov_dim,
414 DataType inner_res_scale = DataType(0)) :
415 BaseClass("AmaVankaGMRES(" + stringify(krylov_dim) + ")"),
416 _system_matrix(matrix),
417 _system_filter(filter),
418 _comm(_system_matrix.get_comm()),
419 _vanka(std::move(vanka)),
420 _gate(),
421 _internal_system_mat(),
422 _local_vanka_mat(),
423 _internal_filter(),
424 _krylov_dim(krylov_dim),
425 _global_vec_size(),
426 _global_used_elements(),
427 _internal_flop_counter(0u),
428 _use_cuda_gmres(false),
429 _prefetch_data(false),
430 _always_use_parallel_kernel(false)
431 {
432 if(_comm)
433 _gate.set_comm(_comm);
434 // we always need to compute defect norms
435 this->_force_def_norm_calc = true;
436
437 // set communicator by system matrix
438 this->_set_comm_by_matrix(matrix);
439 set_inner_res_scale(inner_res_scale);
440
441 const Index local_mat_rows = _system_matrix.local().num_rows_raw();
442 const Index local_mat_cols = _system_matrix.local().num_cols_raw();
443
444 // construct our internal gate
445 if(matrix.get_row_gate())
446 {
447 const auto& row_gate = *matrix.get_row_gate();
448 const auto& ranks = row_gate.get_ranks();
449 const auto& mirrors = row_gate.get_mirrors();
450 const auto& freqs = row_gate.get_freqs();
451 for(Index k = 0; k < ranks.size(); ++k)
452 {
453 //construct mirror
454 const Index num_indices = mirrors.at(k).buffer_size(freqs);
455 MirrorType mirror(local_mat_rows, num_indices);
456 auto offsets = Intern::MirrorHelper<MirrorRow_>::fill_mirror(mirror, mirrors.at(k), freqs);
457 XASSERTM(offsets.first == local_mat_rows, "Offset does not match overall mirror size");
458 XASSERTM(offsets.second == num_indices, "Offset does not match overall mirror indices");
459
460 this->_gate.push(ranks.at(k), std::move(mirror));
461 this->_gate.set_sync_location(row_gate.get_sync_location());
462 }
463 // convert frequency
464 VecType tmp_freq;
465 tmp_freq.convert(freqs);
466 this->_gate.compile(std::move(tmp_freq));
467
468 // our internal global matrix uses the new gate
469 this->_internal_system_mat = GlobalMatType(&this->_gate, &this->_gate, local_mat_rows, local_mat_cols);
470 this->_internal_filter = FilType(local_mat_rows, 0u);
471 }
472 }
473
478 {
479 }
480
482 virtual String name() const override
483 {
484 return "AmaVankaGMRES";
485 }
486
487 virtual void set_use_cuda_gmres(bool use)
488 {
489 this->_use_cuda_gmres = use;
490 }
491
492 virtual void set_prefetch_data(bool use)
493 {
494 this->_prefetch_data = use;
495 }
496
497 virtual void set_use_parallel_kernel(bool use)
498 {
499 this->_always_use_parallel_kernel = use;
500 }
507 virtual void force_defect_norm_calc(bool DOXY(force)) override
508 {
509 // force is already applied in constructor
510 }
511
512 virtual void init_symbolic() override
513 {
514 BaseClass::init_symbolic();
515
516 // initialize internal matrix representation, for this, first initialize vanka preconditioner
517 this->_vanka->init_symbolic();
518 this->_vanka->init_numeric();
519 {
520 Util::ScopedNvtxRange nvtx("Vanka: Convert Symbolic");
521 this->_local_vanka_mat.convert(this->_vanka->get_vanka_matrix());
522 }
523 this->_vanka->done_numeric();
524
525 // convert the global matrix
526 this->_internal_system_mat.local().convert(_system_matrix.local());
527
528 {
529 // create temp helper vector to assemble filter
530 auto tmp_sys_vec = _system_matrix.local().create_vector_r();
531 std::map<IndexType, DataType> tmp_map;
532 // convert the filter we assume we only require unit defect filter
533 const Index in_size = Intern::FilterHelper<std::decay_t<decltype(this->_system_filter.local())>>::add_filter(tmp_map, this->_system_filter.local(), tmp_sys_vec);
534 this->_internal_filter = FilType(in_size, tmp_map);
535 }
536 this->_local_vanka_mat.init_workspace();
537 this->_internal_system_mat.local().init_workspace();
538
539
540 _c.reserve(_krylov_dim);
541 _s.reserve(_krylov_dim);
542 _q.reserve(_krylov_dim + 1);
543 _h.resize(_krylov_dim);
544
545 for(Index i(0); i < _krylov_dim; ++i)
546 {
547 _h.at(i).resize(i+1);
548 }
549 _corr.resize(_krylov_dim);
550 _dots_arb = Memory::Arbiter((_krylov_dim + 1) * sizeof(DataType));
551
552 _vec_v.reserve(_krylov_dim+1);
553 _vec_v_elements.reserve(_krylov_dim+1);
554
555 _vec_v.emplace_back(this->_internal_system_mat.create_vector_r());
556 _vec_v.back().format();
557 // _vec_v_helper.emplace_back(_vec_v.back().local().clone(LAFEM::CloneMode::Shallow));
558 _vec_v_elements.emplace_back(&_vec_v.back().local().elements_arbiter());
559 _vec_w = this->_internal_system_mat.create_vector_r();
560 _vec_w.format();
561 for(Index i(0); i < _krylov_dim; ++i)
562 {
563 _vec_v.emplace_back(this->_vec_v.front().clone(LAFEM::CloneMode::Layout));
564 _vec_v.back().format();
565 // _vec_v_helper.emplace_back(_vec_v.back().local().clone(LAFEM::CloneMode::Shallow));
566 _vec_v_elements.emplace_back(&_vec_v.back().local().elements_arbiter());
567 }
568 _vec_sol = this->_internal_system_mat.create_vector_l();
569 _vec_rhs = this->_internal_system_mat.create_vector_r();
570
571 this->_global_used_elements = this->_internal_system_mat.num_nzes_raw();
572 this->_global_vec_size = _vec_sol.size();
573 }
574
575 virtual void init_numeric() override
576 {
577 BaseClass::init_numeric();
578 {
579 Util::ScopedNvtxRange nvtx("Vanka: Init Numeric");
580 this->_vanka->init_numeric();
581 }
582 {
583 Util::ScopedNvtxRange nvtx("Vanka: Clone");
584 this->_local_vanka_mat.copy(this->_vanka->get_vanka_matrix());
585 }
586 {
587 Util::ScopedNvtxRange nvtx("Vanka: Done");
588 this->_vanka->done_numeric();
589 }
590 {
591 Util::ScopedNvtxRange nvtx("System: Clone");
592 this->_internal_system_mat.local().copy(_system_matrix.local());
593 }
594
595 this->_dots_arb.format(Memory::Location::main);
596
597 }
598
599 virtual void done_symbolic() override
600 {
601 this->_internal_system_mat.local().reset_workspace();
602 this->_local_vanka_mat.reset_workspace();
603 this->_local_vanka_mat.clear();
604 this->_global_used_elements = 0u;
605 this->_global_vec_size = 0u;
606 _vec_sol.clear();
607 _vec_rhs.clear();
608 _vec_v_elements.clear();
609 // _vec_v_helper.clear();
610 _vec_v.clear();
611 _vec_w.clear();
612 this->_internal_filter.clear();
613 this->_internal_system_mat.local().clear();
614 this->_vanka->done_symbolic();
615 BaseClass::done_symbolic();
616 }
617
618 virtual void done_numeric() override
619 {
620 }
621
629 virtual void set_krylov_dim(Index krylov_dim)
630 {
631 XASSERT(krylov_dim > Index(0));
632 _krylov_dim = krylov_dim;
633 }
634
641 virtual void set_inner_res_scale(DataType inner_res_scale)
642 {
643 XASSERT(inner_res_scale >= DataType(0));
644 _inner_res_scale = inner_res_scale;
645 }
646
658 {
660 || ortho_type == KrylovOrthogonalizerType::cgs2,
661 "AmaVankaGMRES only supports classical_gram_schmidt or cgs2");
662 _ortho_type = ortho_type;
663 }
664
670 virtual void set_reortho_tol(DataType tol)
671 {
672 XASSERT(tol >= DataType(0));
673 _reortho_tol = tol;
674 }
675
681 virtual void set_force_reortho(bool force)
682 {
683 _force_reortho = force;
684 }
685
689 {
690 return _internal_flop_counter;
691 }
692
694 virtual Status apply(VectorType& vec_sol, const VectorType& vec_rhs) override
695 {
696 // marshal the external rhs into the internal vector (replaces the removed set_vec)
697 this->_vec_rhs.local().copy(vec_rhs.local());
698 this->_vec_v.at(0).local().copy(vec_rhs.local());
699
700 // clear solution vector
701 _vec_sol.format();
702
703 // apply
704 this->_status = _apply_intern_dispatch(this->_vec_sol, this->_vec_rhs);
705 // marshal the internal solution back out (replaces the removed set_vec_inv)
706 this->_vec_sol.local().copy_to(vec_sol.local());
707 this->plot_summary();
708 return this->_status;
709 }
710
712 virtual Status correct(VectorType& vec_sol, const VectorType& vec_rhs) override
713 {
714 // marshal the external vectors into the internal ones (replaces the removed set_vec)
715 this->_vec_sol.local().copy(vec_sol.local());
716 this->_vec_rhs.local().copy(vec_rhs.local());
717
718 this->_internal_system_mat.apply(this->_vec_v.at(0), this->_vec_sol, this->_vec_rhs, -DataType(1));
719 this->_internal_filter.filter_def(this->_vec_v.at(0).local());
720
721 // apply
722 this->_status = _apply_intern_dispatch(this->_vec_sol, this->_vec_rhs);
723 // marshal the internal solution back out (replaces the removed set_vec_inv)
724 this->_vec_sol.local().copy_to(vec_sol.local());
725 this->plot_summary();
726 return this->_status;
727 }
728
729 protected:
730 template<typename VecT_>
731 static void _calc_dots(std::vector<DataType>& loc_dots, const VecT_& target, const std::vector<Memory::Arbiter>& vec_arb, const Index num_dots)
732 {
733 FEAT::Util::ScopedNvtxRange _nvtx("Calc Dots");
734 for(Index i = 0; i < num_dots; ++i)
735 {
736 loc_dots[i] = DataType(0);
737 }
738 Intern::template BatchedHelper<VecT_>::batched_dot(loc_dots.data(), target, vec_arb.data(), num_dots, num_dots);
739 }
740
746 DataType _calc_dots_s(std::vector<DataType>& loc_dots, const VecType& vec_target, const std::vector<Memory::Arbiter*>& vec_arb, const Index num_dots)
747 {
748 FEAT::Util::ScopedNvtxRange _nvtx("Calc Dots");
749 // zero the accumulation arbiter (host), run the batched dot (device-accumulates for cuda), read back
750 _dots_arb.format();
751 LAFEM::Arch::BatchedDotProduct::exec<DataType, DataType>(this->_dots_arb, vec_target.elements_arbiter(), vec_target.size(), vec_arb.data(), num_dots + 1u);
752 DataType self_dot(0);
753 {
755 const DataType* dp = dv.get_r();
756 for(Index i = 0; i < num_dots; ++i)
757 loc_dots[i] = dp[i];
758 self_dot = dp[num_dots];
759 }
760 return self_dot;
761 }
762
765 DataType _calc_triple_dots_s(std::vector<DataType>& loc_dots, const VecType& vec_target, const std::vector<Memory::Arbiter*>& vec_arb, const VecType& freqs, const Index num_dots)
766 {
767 FEAT::Util::ScopedNvtxRange _nvtx("Calc Dots");
768 _dots_arb.format();
769 LAFEM::Arch::BatchedTripleDotProduct::exec<DataType, DataType>(this->_dots_arb, vec_target.elements_arbiter(), vec_target.size(), vec_arb.data(), freqs.elements_arbiter(), num_dots + 1u);
770 DataType self_dot(0);
771 {
772 // acquire the host view (device->host copy if needed) and all-reduce projections + self-dot in one go
774 DataType* dp = dv.get_w();
775 this->_comm->allreduce(dp, dp, num_dots + 1u, Dist::op_sum);
776 for(Index i = 0; i < num_dots; ++i)
777 loc_dots[i] = dp[i];
778 self_dot = dp[num_dots];
779 }
780 return self_dot;
781 }
782
793 DataType _orthogonalize_cpu(const Index i)
794 {
795 VecType& target = this->_vec_v.at(i+1).local();
796 const Index num_basis = i + 1u;
797 const bool distributed = this->_comm && (this->_comm->size() > 1);
798
799 // first classical Gram-Schmidt sweep: batched projection dots + appended self-dot
800 DataType self_dot = distributed
801 ? _calc_triple_dots_s(this->_h.at(i), target, this->_vec_v_elements, this->_gate.get_freqs(), num_basis)
802 : _calc_dots_s(this->_h.at(i), target, this->_vec_v_elements, num_basis);
803 _internal_flop_counter += (num_basis + 1u) * 2u * _global_vec_size;
804
805 DataType sum_sqr(0);
806 for(Index k(0); k < num_basis; ++k)
807 sum_sqr += Math::sqr(this->_h.at(i).at(k));
808
809 // subtract the projection in a single batched cumulative axpy: target -= sum_k h[k] * v[k]
810 _add_vecs_s(target, this->_vec_v_elements, this->_h.at(i), num_basis, DataType(-1));
811 _internal_flop_counter += num_basis * 2u * _global_vec_size;
812
813 DataType nrm_sqr = self_dot - sum_sqr;
814
815 // conditional corrective reorthogonalization sweep (cgs2); the second batched reduction
816 // supplies both the corrections and the updated self-dot, so no extra reduction is needed
817 if((this->_ortho_type == KrylovOrthogonalizerType::cgs2)
818 && (this->_force_reortho || (nrm_sqr < Math::sqr(this->_reortho_tol) * self_dot)))
819 {
820 DataType self_dot2 = distributed
821 ? _calc_triple_dots_s(this->_corr, target, this->_vec_v_elements, this->_gate.get_freqs(), num_basis)
822 : _calc_dots_s(this->_corr, target, this->_vec_v_elements, num_basis);
823 _internal_flop_counter += (num_basis + 1u) * 2u * _global_vec_size;
824 DataType sum_sqr2(0);
825 for(Index k(0); k < num_basis; ++k)
826 {
827 this->_h.at(i).at(k) += this->_corr.at(k);
828 sum_sqr2 += Math::sqr(this->_corr.at(k));
829 }
830 _add_vecs_s(target, this->_vec_v_elements, this->_corr, num_basis, DataType(-1));
831 _internal_flop_counter += num_basis * 2u * _global_vec_size;
832 nrm_sqr = self_dot2 - sum_sqr2;
833 }
834
835 // recover the norm algebraically; fall back to an explicit norm2 on heavy cancellation
836 // (guarantees a positive result so the subsequent normalization cannot produce a NaN)
837 if(nrm_sqr <= Math::Limits<DataType>::epsilon() * DataType(100))
838 {
839 _internal_flop_counter += 2u * _global_vec_size;
840 return this->_vec_v.at(i+1).norm2();
841 }
842 return Math::sqrt(nrm_sqr);
843 }
844
845 template<typename VecT_>
846 static void _add_vecs(VecT_& target_vec, const std::vector<Memory::Arbiter*>& vec_arb, const std::vector<DataType>& loc_scales, const Index num_axpy, DataType alpha)
847 {
848 FEAT::Util::ScopedNvtxRange _nvtx("Add vecs");
849 Intern::template BatchedHelper<VecT_>::commulative_axpy(target_vec, vec_arb.data(), loc_scales.data(), num_axpy, alpha, num_axpy);
850 }
851
852 static void _add_vecs_s(VecType& target_vec, const std::vector<Memory::Arbiter*>& vec_arb, const std::vector<DataType>& loc_scales, const Index num_axpy, DataType alpha)
853 {
854 FEAT::Util::ScopedNvtxRange _nvtx("Add vecs");
855 LAFEM::Arch::CumulativeAxpy::exec<DataType>(target_vec.elements_arbiter(), target_vec.size(), vec_arb.data(), loc_scales.data(), num_axpy, alpha);
856 }
857
858 Status _set_initial_defectp(const GlobalVecType& vec_def, const GlobalVecType&)
859 {
860 // reset iteration variables
861 this->_def_init = this->_def_prev = this->_def_cur = DataType(0);
862 this->_num_iter = Index(0);
863 this->_num_stag_iter = Index(0);
864
865 // first, let's see if we have to compute the defect at all
866 bool calc_def = this->_force_def_norm_calc
867 || (this->_min_iter < this->_max_iter)
868 || (this->_plot_iter() || this->_plot_summary())
869 || (this->_min_stag_iter > Index(0));
870
871 // if we don't have to compute the initial defect, we can exit here
872 if(!calc_def)
873 return Status::progress;
874
875 // compute new initial defect
876 this->_def_init = this->_def_cur = this->_def_prev = vec_def.norm2();
877 Statistics::add_solver_expression(std::make_shared<ExpressionDefect>(this->name(), this->_def_init, this->get_num_iter()));
878 _internal_flop_counter += 2u * _global_vec_size;
879
880 // plot iteration line?
881 if(this->_plot_iter())
882 this->_plot_iter_line(Index(0), this->_def_init, this->_def_init);
883
884 // ensure that the defect is neither NaN nor infinity
885 if(!Math::isfinite(this->_def_init))
886 return Status::aborted;
887
888 // check against low absolute tolerance; this may be fulfilled if we have only a handful of dofs
889 if(this->_def_init < this->_tol_abs_low)
890 return Status::success;
891
892 // check if the initial defect is zero; we test against eps^2 here
893 if(this->_def_init <= Math::sqr(Math::eps<DataType>()))
894 return Status::success;
895
896 // continue iterating
897 return Status::progress;
898 }
899
900 Status _set_new_defectp(const GlobalVecType& vec_def, const GlobalVecType&)
901 {
902 // increase iteration count
903 ++this->_num_iter;
904
905 // store previous defect
906 this->_def_prev = this->_def_cur;
907
908 // first, let's see if we have to compute the defect at all
909 bool calc_def = this->_force_def_norm_calc
910 || (this->_min_iter < this->_max_iter)
911 || (this->_plot_iter() || this->_plot_summary())
912 || (this->_min_stag_iter > Index(0));
913
914 // compute new defect
915 if(calc_def)
916 {
917 this->_def_cur = vec_def.norm2();
918 Statistics::add_solver_expression(std::make_shared<ExpressionDefect>(this->name(), this->_def_cur, this->get_num_iter()));
919 _internal_flop_counter += 2u * _global_vec_size;
920 }
921
922 // analyze defect
923 Status status = this->_analyze_defect(this->_num_iter, this->_def_cur, this->_def_prev, true);
924
925 // plot defect?
926 if(this->_plot_iter(status))
927 this->_plot_iter_line(this->_num_iter, this->_def_cur, this->_def_prev);
928
929 // return status
930 return status;
931 }
932
933 void _apply_vanka(GlobalVecType& v, const GlobalVecType& w)
934 {
935 this->_local_vanka_mat.apply(v.local(), w.local());
936 v.sync_1();
937 this->_internal_filter.filter_cor(v.local());
938 _internal_flop_counter += 2u * _global_used_elements;
939 }
940
941 template<typename DT_, typename IT_>
942 CSRHelper::CRSMat<DT_, IT_> _extract_mat(const LAFEM::SparseMatrixCSR<DT_, IT_>& mat)
943 {
944 // hand over the data arbiters; the kernel acquires its device views from them
945 return CSRHelper::CRSMat<DT_, IT_>{&mat.val_arbiter(), &mat.row_ptr_arbiter(), &mat.col_idx_arbiter(), mat.num_cols(), mat.num_cols(), mat.num_nzes()};
946 }
947
948 template<typename DT_, typename IT_>
949 CSRHelper::UnitFilterInfo<DT_, IT_> _extract_filter(const LAFEM::UnitFilter<DT_, IT_>& filter)
950 {
951 return CSRHelper::UnitFilterInfo<DT_, IT_>{&filter.elements_arbiter(), &filter.indices_arbiter(), filter.num_nzes_raw()};
952 }
953
954 Status _apply_intern_dispatch(GlobalVecType& vec_sol, const GlobalVecType& vec_rhs)
955 {
956 _internal_flop_counter = 0u;
957 #ifdef FEAT_HAVE_CUDA
958 if(this->_use_cuda_gmres)
959 {
960 return this->_cuda_apply_intern(vec_sol, vec_rhs);
961 }
962 #endif
963 return this->_apply_intern(vec_sol, vec_rhs);
964 }
965
966 #ifdef FEAT_HAVE_CUDA
967 virtual Status _cuda_apply_intern(GlobalVecType& vec_sol, const GlobalVecType& vec_rhs)
968 {
969 IterationStats pre_iter(*this);
970 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->name()));
971 pre_iter.destroy();
972 CSRHelper::GMRESApplyInfo<DataType, IndexType> apply_info;
973 {
974 apply_info.mat_sys = _extract_mat(this->_internal_system_mat.local());
975 apply_info.mat_vanka = _extract_mat(this->_local_vanka_mat);
976 apply_info.def_filter = _extract_filter(this->_internal_filter);
977 apply_info.vec_v = &this->_vec_v_elements;
978 apply_info.vec_w = &this->_vec_w.local().elements_arbiter();
979 apply_info.gate = &this->_gate;
980 apply_info.size = this->_internal_system_mat.local().num_rows();
981
982 apply_info.res_scale = this->_inner_res_scale;
983 apply_info.abs_tol = this->_tol_abs;
984 apply_info.rel_tol = this->_tol_rel;
985 apply_info.krylov_dim = this->_krylov_dim;
986 apply_info.max_iter = this->_max_iter;
987 apply_info.min_iter = this->_min_iter;
988 apply_info.plot_interval = this->_plot_interval;
989 apply_info.plot_mode = this->_plot_mode;
990 apply_info.prefetch_data = this->_prefetch_data;
991 apply_info.ortho_type = this->_ortho_type;
992 apply_info.reortho_tol = this->_reortho_tol;
993 apply_info.force_reortho = this->_force_reortho;
994 }
995
996 CSRHelper::GMRESStatus<DataType> stat;
997 {
998 stat.def_norm = DataType(0);
999 stat.def_init = DataType(0);
1000 stat.num_iter = Index(0);
1001 }
1002
1003 if((this->_comm->size() == 1) && !this->_always_use_parallel_kernel)
1004 this->_status = VankaGMRES::cuda_apply_amavanka_gmres_seq(vec_sol.local().elements_arbiter(), vec_rhs.local().elements_arbiter(), apply_info, stat);
1005 else
1006 this->_status = VankaGMRES::cuda_apply_amavanka_gmres_parallel(vec_sol.local().elements_arbiter(), vec_rhs.local().elements_arbiter(), apply_info, stat);
1007 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->name(), this->_status, stat.num_iter));
1008 this->_def_cur = stat.def_norm;
1009 this->_def_init = stat.def_init;
1010 this->_num_iter = stat.num_iter;
1011 return this->_status;
1012 }
1013 #endif
1014
1015 virtual Status _apply_intern(GlobalVecType& vec_sol, const GlobalVecType& vec_rhs)
1016 {
1017 FEAT::Util::ScopedNvtxRange _nvtx_total("Internal Apply");
1018 IterationStats pre_iter(*this);
1019 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->name()));
1020 const GlobalMatType& matrix(this->_internal_system_mat);
1021 const FilType& filter(this->_internal_filter);
1022
1023 // compute initial defect
1024 Status status = this->_set_initial_defectp(this->_vec_v.at(0), vec_sol);
1025
1026 pre_iter.destroy();
1027
1028
1029
1030 // outer GMRES loop
1031 while(status == Status::progress)
1032 {
1033 IterationStats stat(*this);
1034
1035 _q.clear();
1036 _s.clear();
1037 _c.clear();
1038 _q.push_back(this->_def_cur);
1039
1040 // normalize v[0]
1041 this->_vec_v.at(0).scale(this->_vec_v.at(0), DataType(1) / _q.back());
1042 _internal_flop_counter += 2u*this->_vec_v.at(0).size_raw();
1043
1044 // inner GMRES loop
1045 Index i(0);
1046 { // "Inner GMRES Loop" scope (i is declared outside so it survives for the Hessenberg solve)
1047 FEAT::Util::ScopedNvtxRange _nvtx_inner("Inner GMRES Loop");
1048 while(i < this->_krylov_dim)
1049 {
1050 // if(i == 0)
1051 // {
1052 // std::cout << "Rank " << _comm->rank() << " :" << this->_vec_v[0].local() << "\n-------------\n";
1053 // }
1054 // apply vanka matrix
1055 {
1056 FEAT::Util::ScopedNvtxRange _nvtx("Solve Vanka");
1057 _apply_vanka(this->_vec_w, this->_vec_v.at(i));
1058 }
1059 // // sync by calculating mean
1060 // if(i == 0)
1061 // {
1062 // std::cout << "Rank " << _comm->rank() << " :" << this->_vec_w.local() << "\n-------------\n";
1063 // }
1064
1065 // v[i+1] := A*w
1066 {
1067 FEAT::Util::ScopedNvtxRange _nvtx("A*w");
1068 matrix.apply(this->_vec_v.at(i+1), this->_vec_w);
1069 filter.filter_def(this->_vec_v.at(i+1).local());
1070 _internal_flop_counter += 2u*_global_used_elements;
1071 }
1072
1073 // Gram-Schmidt process (classical / conditional CGS2), with the self-dot fused into the
1074 // batched reduction so the orthogonalized norm is recovered without a separate norm2
1075 const DataType alpha = _orthogonalize_cpu(i);
1076
1077 // normalize v[i+1]
1078 {
1079 FEAT::Util::ScopedNvtxRange _nvtx("Norm scale");
1080 this->_vec_v.at(i+1).scale(this->_vec_v.at(i+1), DataType(1) / alpha);
1081 _internal_flop_counter += 2u * _global_vec_size;
1082 }
1083
1084 {
1085 FEAT::Util::ScopedNvtxRange _nvtx("Givens Rotation");
1086 // apply Givens rotations
1087 for(Index k(0); k < i; ++k)
1088 {
1089 DataType t(this->_h.at(i).at(k));
1090 this->_h.at(i).at(k ) = this->_c.at(k) * t + this->_s.at(k) * this->_h.at(i).at(k+1);
1091 this->_h.at(i).at(k+1) = this->_s.at(k) * t - this->_c.at(k) * this->_h.at(i).at(k+1);
1092 }
1093 }
1094
1095
1096 {
1097 FEAT::Util::ScopedNvtxRange _nvtx("Push defect");
1098 // compute beta
1099 const DataType beta = Math::sqrt(Math::sqr(this->_h.at(i).at(i)) + Math::sqr(alpha));
1100
1101 // compute next plane rotation
1102 _s.push_back(alpha / beta);
1103 _c.push_back(this->_h.at(i).at(i) / beta);
1104
1105 this->_h.at(i).at(i) = beta;
1106 this->_q.push_back(this->_s.back() * this->_q.at(i));
1107 this->_q.at(i) *= this->_c.back();
1108 }
1109 // push our new defect
1110 if(++i < this->_krylov_dim)
1111 {
1112 // get the absolute defect
1113 DataType def_cur = Math::abs(this->_q.back());
1114
1115 // did we diverge?
1116 if((def_cur > this->_div_abs) || (def_cur > (this->_div_rel * this->_def_init)))
1117 break;
1118
1119 // minimum number of iterations performed?
1120 if(!(this->_num_iter < this->_min_iter))
1121 {
1122 // did we converge?
1123 if((def_cur <= _inner_res_scale * this->_tol_abs) &&
1124 ((def_cur <= _inner_res_scale * (this->_tol_rel * this->_def_init)) || (def_cur <= _inner_res_scale * this->_tol_abs_low) ))
1125 break;
1126
1127 // maximum number of iterations performed?
1128 if(this->_num_iter >= this->_max_iter)
1129 break;
1130 }
1131
1132 // set our pseudo defect
1133 // increase iteration count
1134 ++this->_num_iter;
1135
1136 // compute new defect
1137 this->_def_cur = def_cur;
1138
1139 // plot?
1140 if(this->_plot_iter())
1141 {
1142 String msg = this->_plot_name
1143 + "* " + stringify(this->_num_iter).pad_front(this->_iter_digits)
1144 + " : " + stringify_fp_sci(this->_def_cur);
1145 this->_print_line(msg);
1146 }
1147 }
1148 }
1149
1150 } // close "Inner GMRES Loop" scope
1151
1152
1153 {
1154 const Index n = Math::min(i, this->_krylov_dim);
1155 {
1156 FEAT::Util::ScopedNvtxRange _nvtx("Solve Hessenberg");
1157 // solve H*q = q
1158 for(Index k(n); k > 0;)
1159 {
1160 --k;
1161 this->_q.at(k) /= this->_h.at(k).at(k);
1162 for(Index j(k); j > 0;)
1163 {
1164 --j;
1165 this->_q.at(j) -= this->_h.at(k).at(j) * this->_q.at(k);
1166 }
1167 }
1168 } // "Solve Hessenberg"
1169
1170 // Runtime::SyncGuard sync_guard;
1171 // update solution
1172 this->_vec_w.format();
1173 // _add_vecs(this->_vec_w, this->_vec_v, this->_q, n, DataType(1));
1174 _add_vecs_s(this->_vec_w.local(), this->_vec_v_elements, this->_q, n, DataType(1));
1175 _internal_flop_counter += n * 2u * _global_vec_size;
1176 }
1177
1178 {
1179 FEAT::Util::ScopedNvtxRange _nvtx("Solve Vanka");
1180 _apply_vanka(this->_vec_v.front(), this->_vec_w);
1181 vec_sol.axpy(this->_vec_v.front());
1182 _internal_flop_counter += _global_vec_size;
1183 }
1184
1185 // compute "real" residual
1186 {
1187 FEAT::Util::ScopedNvtxRange _nvtx("Residual Calc");
1188 matrix.apply(this->_vec_v.at(0), vec_sol, vec_rhs, -DataType(1));
1189 filter.filter_def(this->_vec_v.at(0).local());
1190 _internal_flop_counter += 2u*_global_used_elements;
1191 }
1192
1193 // set the current defect
1194 status = this->_set_new_defectp(this->_vec_v.at(0), vec_sol);
1195 }
1196
1197 // finished
1198 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->name(), status, this->get_num_iter()));
1199 return status;
1200 }
1201 }; // class AmaVankaGMRES<...>
1202
1225 template<typename Matrix_, typename Filter_, typename VankaType_>
1226 inline std::shared_ptr<AmaVankaGMRES<Matrix_, Filter_>> new_amavanka_gmres(
1227 const Matrix_& matrix, const Filter_& filter, std::shared_ptr<VankaType_> vanka, Index krylov_dim,
1228 typename Matrix_::DataType inner_res_scale = typename Matrix_::DataType(0))
1229 {
1230 return std::make_shared<AmaVankaGMRES<Matrix_, Filter_>>(matrix, filter, std::move(vanka), krylov_dim, inner_res_scale);
1231 }
1232
1233 } // namespace Solver
1234} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Communicator class.
Definition: dist.hpp:1657
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
Definition: dist.cpp:658
int size() const
Returns the size of this communicator.
Definition: dist.hpp:1814
Global Filter wrapper class template.
Definition: filter.hpp:21
Global gate implementation.
Definition: gate.hpp:78
void compile(LocalVector_ &&vector)
Compiles the gate to finish its setup.
Definition: gate.hpp:370
const LocalVector_ & get_freqs() const
Returns a const reference to the frequencies vector.
Definition: gate.hpp:226
void push(int rank, Mirror_ &&mirror)
Adds a mirror for a neighbor process.
Definition: gate.hpp:348
void set_comm(const Dist::Comm *comm_)
Sets the communicator for this gate.
Definition: gate.hpp:196
const std::vector< int > get_ranks() const
Returns a const reference to the neighbor ranks vector.
Definition: gate.hpp:206
void set_sync_location(SyncLocation sync_location)
Set the sync location to be used.
Definition: gate.hpp:824
Global Matrix wrapper class template.
Definition: matrix.hpp:40
VectorTypeR create_vector_r() const
Creates and returns a new R-compatible global vector object.
Definition: matrix.hpp:217
VectorTypeL create_vector_l() const
Creates and returns a new L-compatible global vector object.
Definition: matrix.hpp:207
const GateRowType * get_row_gate() const
Returns a const pointer to the internal row gate of the matrix.
Definition: matrix.hpp:164
void apply(VectorTypeL &r, const VectorTypeR &x) const
Performs a matrix-vector multiplication: r <- A*x.
Definition: matrix.hpp:337
LocalMatrix_ & local()
Returns a reference to the internal local LAFEM matrix object.
Definition: matrix.hpp:136
Global vector wrapper class template.
Definition: vector.hpp:68
void format(DataType alpha=DataType(0))
Reset all elements of the container to a given value or zero if missing.
Definition: vector.hpp:318
Index size() const
Returns the total number of entries in this distributed vector.
Definition: vector.hpp:255
LocalVector_ & local()
Returns a reference to the internal local LAFEM vector object.
Definition: vector.hpp:122
void clear()
Clears the underlying vector.
Definition: vector.hpp:308
void reset_workspace() const
Resets the workspace allocation.
Definition: container.hpp:877
virtual void clear()
Free all allocated arrays.
Definition: container.hpp:885
Blocked Dense data vector class template.
Index size_raw() const
Returns the size of this vector in scalar data type entries, i.e. its number of entries multiplied by...
Dense data vector class template.
void convert(const DenseVector< DT2_, IT2_ > &other)
Conversion method.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Filter Chainclass template.
Sequence of filters of the same type.
CSR based sparse matrix.
void convert(const SparseMatrixCSR< DT2_, IT2_ > &other)
Conversion method.
void init_workspace() const
Inits persistent workspace.
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
void copy(const MT_ &source)
Copies the values of the input matrix into this matrix.
TupleVector meta-filter class template.
TupleVector meta-mirror class template.
Variadic TupleVector class template.
Unit Filter Blocked class template.
Memory::TypedView< IT_ > indices_view_r(Memory::Location loc=Memory::Location::main) const
Creates a read-only memory view for the indices array for a given memory location.
Index num_nzes() const
Returns the number of non-zero entries in the filter.
Unit Filter class template.
Definition: unit_filter.hpp:31
Index num_nzes() const
Returns the number of non-zero entries in the filter.
void filter_def(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto a defect vector.
void filter_cor(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto a correction vector.
Memory::TypedView< IT_ > indices_view_r(Memory::Location loc=Memory::Location::main) const
Creates a read-only memory view for the indices array for a given memory location.
void clear()
Clears the underlying data (namely the SparseVector)
Handles vector prolongation, restriction and serialization.
Index num_indices() const
Returns the number of indices in the mirror.
Math Limits class template.
Definition: math.hpp:1475
Memory arbiter class.
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
void format(Location mem_loc=Location::none)
Formats the memory block to zero.
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.
AmaVankaGMRES(const MatrixType &matrix, const FilterType &filter, std::shared_ptr< VankaType > vanka, Index krylov_dim, DataType inner_res_scale=DataType(0))
Constructor.
virtual void set_reortho_tol(DataType tol)
Sets the DGKS norm-ratio threshold that triggers a corrective reorthogonalization sweep.
DataType _calc_dots_s(std::vector< DataType > &loc_dots, const VecType &vec_target, const std::vector< Memory::Arbiter * > &vec_arb, const Index num_dots)
Batched dot: computes num_dots projection dots into loc_dots and returns the appended self-dot in th...
std::shared_ptr< VankaType > _vanka
The Amavanka preconditionier we copy our preconditionier matrix from.
std::vector< DataType > _corr
scratch for the cgs2 corrective sweep's dot products, kept separate from the accumulated h[k]
virtual void force_defect_norm_calc(bool force) override
Forces the calculation of defect norms in every iteration (overridden)
DataType _orthogonalize_cpu(const Index i)
Orthogonalizes v[i+1] against v[0..i] and returns its post-orthogonalization norm.
DataType _calc_triple_dots_s(std::vector< DataType > &loc_dots, const VecType &vec_target, const std::vector< Memory::Arbiter * > &vec_arb, const VecType &freqs, const Index num_dots)
Distributed batched (frequency-weighted) dot with appended self-dot; the single all-reduce covers the...
virtual Status apply(VectorType &vec_sol, const VectorType &vec_rhs) override
Solver application method.
virtual void set_orthogonalizer(KrylovOrthogonalizerType ortho_type)
Sets the Krylov subspace orthogonalization strategy.
virtual void set_force_reortho(bool force)
Forces (or unforces) a corrective reorthogonalization sweep in every step.
DataType _inner_res_scale
inner pseudo-residual scaling factor, see the documentation of this class for details
GMRES(k) solver implementation specialization for an Stokes typed GMRES(AmaVanka) implementation.
Additive Macro-wise Matrix-based Vanka preconditioner/smoother.
Definition: amavanka.hpp:65
static Index add_filter(std::map< IT_, DT_ > &filter_map, const InFilterType &input, const Vec_ &vec, Index offset=0u)
by default, add nothing from the filter
static Index add_filter(std::map< IT_, DT_ > &filter_map, const InFilterType &input, const Vec_ &vec, Index offset=0u)
by default, add nothing from the filter
static Index add_filter(std::map< IT_, DT_ > &filter_map, const InFilterType &input, const Vec_ &vec, Index offset=0u)
by default, add nothing from the filter
static Index add_filter(std::map< IT_, DT_ > &filter_map, const InFilterType &input, const LAFEM::TupleVector< FVec_, RVec_ > &vec, Index offset=0u)
by default, add nothing from the filter
static Index add_filter(std::map< IT_, DT_ > &filter_map, const InFilterType &input, const LAFEM::TupleVector< FVec_ > &vec, Index offset=0u)
by default, add nothing from the filter
static Index add_filter(std::map< IT_, DT_ > &filter_map, const InFilterType &input, const LAFEM::DenseVector< DTT_, ITT_ > &vec, Index offset=0u)
by default, add nothing from the filter
static Index add_filter(std::map< IT_, DT_ > &filter_map, const InFilterType &input, const LAFEM::DenseVectorBlocked< DTT_, ITT_, dim_ > &vec, Index offset=0u)
by default, add nothing from the filter
Abstract base-class for iterative solvers.
Definition: iterative.hpp:198
String class implementation.
Definition: string.hpp:47
String pad_front(size_type len, char c=' ') const
Pads the front of the string up to a desired length.
Definition: string.hpp:393
RAII scope guard for an NVTX profiling range.
Definition: cuda_util.hpp:252
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
Definition: dist.hpp:571
T_ sqrt(T_ x)
Returns the square-root of a value.
Definition: math.hpp:300
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
T_ sqr(T_ x)
Returns the square of a value.
Definition: math.hpp:95
T_ min(T_ a, T_ b)
Returns the minimum of two values.
Definition: math.hpp:123
bool isfinite(T_ x)
Checks whether a value is finite.
@ read_write
read-write access
@ read
read-only access
VankaType
Vanka type enumeration.
Definition: vanka.hpp:952
Status
Solver status return codes enumeration.
Definition: base.hpp:47
@ success
solving successful (convergence criterion fulfilled)
@ progress
continue iteration (internal use only)
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)
std::shared_ptr< AmaVankaGMRES< Matrix_, Filter_ > > new_amavanka_gmres(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< VankaType_ > vanka, Index krylov_dim, typename Matrix_::DataType inner_res_scale=typename Matrix_::DataType(0))
Creates a new GMRES solver object.
KrylovOrthogonalizerType
Enumeration of the available Krylov subspace orthogonalization strategies.
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:993
String stringify_fp_sci(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in scientific notation.
Definition: string.hpp:1137
std::uint64_t Index
Index data type.