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>
27#include <kernel/solver/backend_aux/csr_apply_helper.hpp>
29#include <kernel/solver/krylov_orthogonalizer.hpp>
32#include <kernel/util/cuda_util.hpp>
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);
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);
53 template<
typename,
typename =
void>
54 static constexpr int dim_vector = 1;
57 static constexpr int dim_vector<T,
58 std::void_t<
decltype(T::block_size)>> = T::block_size;
60 template<
typename InMirror_>
63 template<
typename First_,
typename... Rest_>
69 template<
typename OutMirror_,
typename FVec_,
typename RVec_>
77 template<
typename First_>
83 template<
typename OutMirror_,
typename FVec_>
91 template<
typename DT_,
typename IT_>
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})
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_>;
110 for(
int d = 0; d < dim; ++d)
112 target[k*dim +
Index(d)] = IT_(indices[k]*dim +
Index(d) + dof_offset);
115 offsets.first += vec.size_raw();
121 template<
typename InFilterType_>
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)
129 return offset + vec.size_raw();
133 template<
typename First_,
typename... Rest_>
139 template<
typename DT_,
typename IT_,
typename FVec_,
typename RVec_>
148 template<
typename First_>
154 template<
typename DT_,
typename IT_,
typename FVec_>
162 template<
typename First_,
typename... Rest_>
168 template<
typename DT_,
typename IT_,
typename Vec_>
176 template<
typename First_>
182 template<
typename DT_,
typename IT_,
typename Vec_>
189 template<
typename FType_>
195 template<
typename DT_,
typename IT_,
typename Vec_>
198 Index new_offset = offset;
199 for(
auto& pair : input)
207 template<
typename DTT_,
typename ITT_>
213 template<
typename DT_,
typename IT_>
218 const auto& sv = input.get_filter_vector();
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)
225 filter_map.insert_or_assign(IT_(svi[k]+offset), DT_(svd[k]));
228 return offset+vec.
size();
232 template<
typename DTT_,
typename ITT_,
int dim_>
238 template<
typename DT_,
typename IT_>
243 const auto& sv = input.get_filter_vector();
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)
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]));
285 typename LocalMatrix_,
286 typename LocalFilter_,
290 public IterativeSolver<typename Global::Matrix<LocalMatrix_, MirrorRow_, MirrorCol_>::VectorTypeR>
296 typedef typename MatrixType::DataType DataType;
297 typedef typename LocalMatrix_::IndexType IndexType;
340 DataType _reortho_tol = DataType(0.3);
342 bool _force_reortho =
false;
347 std::vector<Memory::Arbiter*> _vec_v_elements;
353 std::vector<DataType>
_c, _s, _q;
355 std::vector<std::vector<DataType>>
_h;
362 Index _global_vec_size;
363 Index _global_used_elements;
364 Index _internal_flop_counter;
366 bool _use_cuda_gmres;
368 bool _always_use_parallel_kernel;
414 DataType inner_res_scale = DataType(0)) :
416 _system_matrix(matrix),
417 _system_filter(filter),
418 _comm(_system_matrix.get_comm()),
419 _vanka(std::move(vanka)),
421 _internal_system_mat(),
424 _krylov_dim(krylov_dim),
426 _global_used_elements(),
427 _internal_flop_counter(0u),
428 _use_cuda_gmres(false),
429 _prefetch_data(false),
430 _always_use_parallel_kernel(false)
435 this->_force_def_norm_calc =
true;
438 this->_set_comm_by_matrix(matrix);
439 set_inner_res_scale(inner_res_scale);
441 const Index local_mat_rows = _system_matrix.
local().num_rows_raw();
442 const Index local_mat_cols = _system_matrix.
local().num_cols_raw();
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)
454 const Index num_indices = mirrors.at(k).buffer_size(freqs);
455 MirrorType mirror(local_mat_rows, num_indices);
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");
460 this->_gate.
push(ranks.at(k), std::move(mirror));
466 this->_gate.
compile(std::move(tmp_freq));
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);
484 return "AmaVankaGMRES";
487 virtual void set_use_cuda_gmres(
bool use)
489 this->_use_cuda_gmres = use;
492 virtual void set_prefetch_data(
bool use)
494 this->_prefetch_data = use;
497 virtual void set_use_parallel_kernel(
bool use)
499 this->_always_use_parallel_kernel = use;
514 BaseClass::init_symbolic();
517 this->_vanka->init_symbolic();
518 this->_vanka->init_numeric();
521 this->_local_vanka_mat.
convert(this->_vanka->get_vanka_matrix());
523 this->_vanka->done_numeric();
526 this->_internal_system_mat.
local().convert(_system_matrix.
local());
530 auto tmp_sys_vec = _system_matrix.
local().create_vector_r();
531 std::map<IndexType, DataType> tmp_map;
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);
537 this->_internal_system_mat.
local().init_workspace();
540 _c.reserve(_krylov_dim);
541 _s.reserve(_krylov_dim);
542 _q.reserve(_krylov_dim + 1);
543 _h.resize(_krylov_dim);
545 for(
Index i(0); i < _krylov_dim; ++i)
547 _h.at(i).resize(i+1);
549 _corr.resize(_krylov_dim);
552 _vec_v.reserve(_krylov_dim+1);
553 _vec_v_elements.reserve(_krylov_dim+1);
556 _vec_v.back().format();
558 _vec_v_elements.emplace_back(&_vec_v.back().local().elements_arbiter());
561 for(
Index i(0); i < _krylov_dim; ++i)
564 _vec_v.back().format();
566 _vec_v_elements.emplace_back(&_vec_v.back().local().elements_arbiter());
571 this->_global_used_elements = this->_internal_system_mat.num_nzes_raw();
572 this->_global_vec_size = _vec_sol.
size();
577 BaseClass::init_numeric();
580 this->_vanka->init_numeric();
584 this->_local_vanka_mat.
copy(this->_vanka->get_vanka_matrix());
588 this->_vanka->done_numeric();
592 this->_internal_system_mat.
local().copy(_system_matrix.
local());
601 this->_internal_system_mat.
local().reset_workspace();
603 this->_local_vanka_mat.
clear();
604 this->_global_used_elements = 0u;
605 this->_global_vec_size = 0u;
608 _vec_v_elements.clear();
612 this->_internal_filter.
clear();
613 this->_internal_system_mat.
local().clear();
614 this->_vanka->done_symbolic();
615 BaseClass::done_symbolic();
632 _krylov_dim = krylov_dim;
643 XASSERT(inner_res_scale >= DataType(0));
644 _inner_res_scale = inner_res_scale;
661 "AmaVankaGMRES only supports classical_gram_schmidt or cgs2");
662 _ortho_type = ortho_type;
683 _force_reortho = force;
690 return _internal_flop_counter;
698 this->_vec_v.at(0).local().copy(vec_rhs.
local());
704 this->_status = _apply_intern_dispatch(this->_vec_sol, this->_vec_rhs);
706 this->_vec_sol.
local().copy_to(vec_sol.
local());
707 this->plot_summary();
708 return this->_status;
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());
722 this->_status = _apply_intern_dispatch(this->_vec_sol, this->_vec_rhs);
724 this->_vec_sol.
local().copy_to(vec_sol.
local());
725 this->plot_summary();
726 return this->_status;
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)
734 for(
Index i = 0; i < num_dots; ++i)
736 loc_dots[i] = DataType(0);
738 Intern::template BatchedHelper<VecT_>::batched_dot(loc_dots.data(), target, vec_arb.data(), num_dots, num_dots);
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)
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);
755 const DataType* dp = dv.
get_r();
756 for(
Index i = 0; i < num_dots; ++i)
758 self_dot = dp[num_dots];
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);
774 DataType* dp = dv.
get_w();
776 for(
Index i = 0; i < num_dots; ++i)
778 self_dot = dp[num_dots];
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);
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;
806 for(
Index k(0); k < num_basis; ++k)
807 sum_sqr +=
Math::sqr(this->_h.at(i).at(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;
813 DataType nrm_sqr = self_dot - sum_sqr;
818 && (this->_force_reortho || (nrm_sqr <
Math::sqr(this->_reortho_tol) * self_dot)))
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)
827 this->_h.at(i).at(k) += this->_corr.at(k);
828 sum_sqr2 +=
Math::sqr(this->_corr.at(k));
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;
839 _internal_flop_counter += 2u * _global_vec_size;
840 return this->_vec_v.at(i+1).norm2();
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)
849 Intern::template BatchedHelper<VecT_>::commulative_axpy(target_vec, vec_arb.data(), loc_scales.data(), num_axpy, alpha, num_axpy);
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)
855 LAFEM::Arch::CumulativeAxpy::exec<DataType>(target_vec.elements_arbiter(), target_vec.size(), vec_arb.data(), loc_scales.data(), num_axpy, alpha);
858 Status _set_initial_defectp(
const GlobalVecType& vec_def,
const GlobalVecType&)
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);
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));
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;
881 if(this->_plot_iter())
882 this->_plot_iter_line(
Index(0), this->_def_init, this->_def_init);
889 if(this->_def_init < this->_tol_abs_low)
893 if(this->_def_init <=
Math::sqr(Math::eps<DataType>()))
900 Status _set_new_defectp(
const GlobalVecType& vec_def,
const GlobalVecType&)
906 this->_def_prev = this->_def_cur;
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));
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;
923 Status status = this->_analyze_defect(this->_num_iter, this->_def_cur, this->_def_prev,
true);
926 if(this->_plot_iter(status))
927 this->_plot_iter_line(this->_num_iter, this->_def_cur, this->_def_prev);
933 void _apply_vanka(GlobalVecType& v,
const GlobalVecType& w)
935 this->_local_vanka_mat.
apply(v.local(), w.local());
938 _internal_flop_counter += 2u * _global_used_elements;
941 template<
typename DT_,
typename IT_>
942 CSRHelper::CRSMat<DT_, IT_> _extract_mat(
const LAFEM::SparseMatrixCSR<DT_, IT_>& mat)
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()};
948 template<
typename DT_,
typename IT_>
949 CSRHelper::UnitFilterInfo<DT_, IT_> _extract_filter(
const LAFEM::UnitFilter<DT_, IT_>& filter)
951 return CSRHelper::UnitFilterInfo<DT_, IT_>{&filter.elements_arbiter(), &filter.indices_arbiter(), filter.num_nzes_raw()};
954 Status _apply_intern_dispatch(GlobalVecType& vec_sol,
const GlobalVecType& vec_rhs)
956 _internal_flop_counter = 0u;
957 #ifdef FEAT_HAVE_CUDA
958 if(this->_use_cuda_gmres)
960 return this->_cuda_apply_intern(vec_sol, vec_rhs);
963 return this->_apply_intern(vec_sol, vec_rhs);
966 #ifdef FEAT_HAVE_CUDA
967 virtual Status _cuda_apply_intern(GlobalVecType& vec_sol,
const GlobalVecType& vec_rhs)
969 IterationStats pre_iter(*
this);
970 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->name()));
972 CSRHelper::GMRESApplyInfo<DataType, IndexType> apply_info;
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();
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;
996 CSRHelper::GMRESStatus<DataType> stat;
998 stat.def_norm = DataType(0);
999 stat.def_init = DataType(0);
1000 stat.num_iter =
Index(0);
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);
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;
1015 virtual Status _apply_intern(GlobalVecType& vec_sol,
const GlobalVecType& vec_rhs)
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);
1024 Status status = this->_set_initial_defectp(this->_vec_v.at(0), vec_sol);
1033 IterationStats stat(*
this);
1038 _q.push_back(this->_def_cur);
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();
1048 while(i < this->_krylov_dim)
1057 _apply_vanka(this->_vec_w, this->_vec_v.at(i));
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;
1075 const DataType alpha = _orthogonalize_cpu(i);
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;
1087 for(
Index k(0); k < i; ++k)
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);
1102 _s.push_back(alpha / beta);
1103 _c.push_back(this->_h.at(i).at(i) / beta);
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();
1110 if(++i < this->_krylov_dim)
1113 DataType def_cur =
Math::abs(this->_q.back());
1116 if((def_cur > this->_div_abs) || (def_cur > (this->_div_rel * this->_def_init)))
1120 if(!(this->_num_iter < this->_min_iter))
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) ))
1128 if(this->_num_iter >= this->_max_iter)
1137 this->_def_cur = def_cur;
1140 if(this->_plot_iter())
1142 String msg = this->_plot_name
1145 this->_print_line(msg);
1158 for(
Index k(n); k > 0;)
1161 this->_q.at(k) /= this->_h.at(k).at(k);
1162 for(
Index j(k); j > 0;)
1165 this->_q.at(j) -= this->_h.at(k).at(j) * this->_q.at(k);
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;
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;
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;
1194 status = this->_set_new_defectp(this->_vec_v.at(0), vec_sol);
1198 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->name(), status, this->get_num_iter()));
1225 template<
typename Matrix_,
typename Filter_,
typename VankaType_>
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))
1230 return std::make_shared<AmaVankaGMRES<Matrix_, Filter_>>(matrix, filter, std::move(vanka), krylov_dim, inner_res_scale);
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
int size() const
Returns the size of this communicator.
Global Filter wrapper class template.
Global gate implementation.
void compile(LocalVector_ &&vector)
Compiles the gate to finish its setup.
const LocalVector_ & get_freqs() const
Returns a const reference to the frequencies vector.
void push(int rank, Mirror_ &&mirror)
Adds a mirror for a neighbor process.
void set_comm(const Dist::Comm *comm_)
Sets the communicator for this gate.
const std::vector< int > get_ranks() const
Returns a const reference to the neighbor ranks vector.
void set_sync_location(SyncLocation sync_location)
Set the sync location to be used.
Global Matrix wrapper class template.
VectorTypeR create_vector_r() const
Creates and returns a new R-compatible global vector object.
VectorTypeL create_vector_l() const
Creates and returns a new L-compatible global vector object.
const GateRowType * get_row_gate() const
Returns a const pointer to the internal row gate of the matrix.
void apply(VectorTypeL &r, const VectorTypeR &x) const
Performs a matrix-vector multiplication: r <- A*x.
LocalMatrix_ & local()
Returns a reference to the internal local LAFEM matrix object.
Global vector wrapper class template.
void format(DataType alpha=DataType(0))
Reset all elements of the container to a given value or zero if missing.
Index size() const
Returns the total number of entries in this distributed vector.
LocalVector_ & local()
Returns a reference to the internal local LAFEM vector object.
void clear()
Clears the underlying vector.
void reset_workspace() const
Resets the workspace allocation.
virtual void clear()
Free all allocated arrays.
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.
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.
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.
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.
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.
SparseMatType _local_vanka_mat
Our internal vanka matrix.
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...
FilType _internal_filter
our local filter object
virtual void set_krylov_dim(Index krylov_dim)
Sets the inner Krylov space dimension.
std::shared_ptr< VankaType > _vanka
The Amavanka preconditionier we copy our preconditionier matrix from.
virtual Status correct(VectorType &vec_sol, const VectorType &vec_rhs) override
std::vector< DataType > _corr
scratch for the cgs2 corrective sweep's dot products, kept separate from the accumulated h[k]
virtual void set_inner_res_scale(DataType inner_res_scale)
Sets the inner residual scale.
virtual void init_symbolic() override
Symbolic initialization method.
const MatrixType & _system_matrix
the matrix for the solver
std::vector< GlobalVecType > _vec_v
krylov basis vector
GateType _gate
Our internal gate.
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.
Memory::Arbiter _dots_arb
virtual void set_orthogonalizer(KrylovOrthogonalizerType ortho_type)
Sets the Krylov subspace orthogonalization strategy.
virtual void done_numeric() override
Numeric finalization method.
virtual ~AmaVankaGMRES()
Empty virtual destructor.
std::vector< std::vector< DataType > > _h
Hessenberg matrix.
GlobalMatType _internal_system_mat
Our internal system matrix.
GlobalVecType _vec_sol
helper vectors
std::vector< DataType > _c
Givens rotation coefficients.
virtual void init_numeric() override
Numeric initialization method.
virtual void set_force_reortho(bool force)
Forces (or unforces) a corrective reorthogonalization sweep in every step.
const FilterType & _system_filter
the filter for the solver
const Dist::Comm * _comm
the communicator used
Index _krylov_dim
krylov dimension
virtual String name() const override
Returns a descriptive string.
virtual void done_symbolic() override
Symbolic finalization method.
DataType _inner_res_scale
inner pseudo-residual scaling factor, see the documentation of this class for details
Index get_global_flops() const
GMRES(k) solver implementation specialization for an Stokes typed GMRES(AmaVanka) implementation.
Additive Macro-wise Matrix-based Vanka preconditioner/smoother.
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.
String class implementation.
String pad_front(size_type len, char c=' ') const
Pads the front of the string up to a desired length.
RAII scope guard for an NVTX profiling range.
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
T_ sqrt(T_ x)
Returns the square-root of a value.
T_ abs(T_ x)
Returns the absolute value.
T_ sqr(T_ x)
Returns the square of a value.
T_ min(T_ a, T_ b)
Returns the minimum of two values.
bool isfinite(T_ x)
Checks whether a value is finite.
@ read_write
read-write access
VankaType
Vanka type enumeration.
Status
Solver status return codes enumeration.
@ 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.
String stringify(const T_ &item)
Converts an item into a String.
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.
std::uint64_t Index
Index data type.