Ginkgo  Generated from pipelines/2969282958 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
solver_base.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_SOLVER_SOLVER_BASE_HPP_
6 #define GKO_PUBLIC_CORE_SOLVER_SOLVER_BASE_HPP_
7 
8 
9 #include <memory>
10 #include <string>
11 #include <type_traits>
12 #include <typeinfo>
13 #include <utility>
14 
15 #include <ginkgo/core/base/exception.hpp>
16 #include <ginkgo/core/base/lin_op.hpp>
17 #include <ginkgo/core/base/math.hpp>
18 #include <ginkgo/core/base/name_demangling.hpp>
19 #include <ginkgo/core/log/logger.hpp>
20 #include <ginkgo/core/matrix/dense.hpp>
21 #include <ginkgo/core/matrix/identity.hpp>
22 #include <ginkgo/core/preconditioner/nullspace_projection.hpp>
23 #include <ginkgo/core/solver/nullspace.hpp>
24 #include <ginkgo/core/solver/workspace.hpp>
25 #include <ginkgo/core/stop/combined.hpp>
26 #include <ginkgo/core/stop/criterion.hpp>
27 
28 
29 GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
30 
31 
32 namespace gko {
33 namespace solver {
34 
35 
39 enum class initial_guess_mode {
43  zero,
47  rhs,
51  provided
52 };
53 
54 
55 namespace multigrid {
56 namespace detail {
57 
58 
59 class MultigridState;
60 
61 
62 } // namespace detail
63 } // namespace multigrid
64 
65 
72 public:
73  virtual ~ApplyWithInitialGuess() = default;
74 
75 protected:
76  friend class multigrid::detail::MultigridState;
77 
91  virtual void apply_with_initial_guess(const LinOp* b, LinOp* x,
92  initial_guess_mode guess) const = 0;
93 
94  void apply_with_initial_guess(ptr_param<const LinOp> b, ptr_param<LinOp> x,
95  initial_guess_mode guess) const
96  {
97  apply_with_initial_guess(b.get(), x.get(), guess);
98  }
99 
112  virtual void apply_with_initial_guess(const LinOp* alpha, const LinOp* b,
113  const LinOp* beta, LinOp* x,
114  initial_guess_mode guess) const = 0;
115 
116 
117  void apply_with_initial_guess(ptr_param<const LinOp> alpha,
121  initial_guess_mode guess) const
122  {
123  apply_with_initial_guess(alpha.get(), b.get(), beta.get(), x.get(),
124  guess);
125  }
126 
132  initial_guess_mode get_default_initial_guess() const { return guess_; }
133 
140  explicit ApplyWithInitialGuess(
142  : guess_(guess)
143  {}
144 
150  void set_default_initial_guess(initial_guess_mode guess) { guess_ = guess; }
151 
152 private:
153  initial_guess_mode guess_;
154 };
155 
156 
169 template <typename DerivedType>
171 protected:
172  friend class multigrid::detail::MultigridState;
173 
176  : ApplyWithInitialGuess(guess)
177  {}
178 
183  void apply_with_initial_guess(const LinOp* b, LinOp* x,
184  initial_guess_mode guess) const override
185  {
186  self()->template log<log::Logger::linop_apply_started>(self(), b, x);
187  auto exec = self()->get_executor();
188  GKO_ASSERT_CONFORMANT(self(), b);
189  GKO_ASSERT_EQUAL_ROWS(self(), x);
190  GKO_ASSERT_EQUAL_COLS(b, x);
191  this->apply_with_initial_guess_impl(make_temporary_clone(exec, b).get(),
192  make_temporary_clone(exec, x).get(),
193  guess);
194  self()->template log<log::Logger::linop_apply_completed>(self(), b, x);
195  }
196 
201  void apply_with_initial_guess(const LinOp* alpha, const LinOp* b,
202  const LinOp* beta, LinOp* x,
203  initial_guess_mode guess) const override
204  {
205  self()->template log<log::Logger::linop_advanced_apply_started>(
206  self(), alpha, b, beta, x);
207  auto exec = self()->get_executor();
208  GKO_ASSERT_CONFORMANT(self(), b);
209  GKO_ASSERT_EQUAL_ROWS(self(), x);
210  GKO_ASSERT_EQUAL_COLS(b, x);
211  GKO_ASSERT_EQUAL_DIMENSIONS(alpha, dim<2>(1, 1));
212  GKO_ASSERT_EQUAL_DIMENSIONS(beta, dim<2>(1, 1));
213  this->apply_with_initial_guess_impl(
214  make_temporary_clone(exec, alpha).get(),
215  make_temporary_clone(exec, b).get(),
216  make_temporary_clone(exec, beta).get(),
217  make_temporary_clone(exec, x).get(), guess);
218  self()->template log<log::Logger::linop_advanced_apply_completed>(
219  self(), alpha, b, beta, x);
220  }
221 
222  // TODO: should we provide the default implementation?
227  virtual void apply_with_initial_guess_impl(
228  const LinOp* b, LinOp* x, initial_guess_mode guess) const = 0;
229 
234  virtual void apply_with_initial_guess_impl(
235  const LinOp* alpha, const LinOp* b, const LinOp* beta, LinOp* x,
236  initial_guess_mode guess) const = 0;
237 
238  GKO_ENABLE_SELF(DerivedType);
239 };
240 
241 
246 template <typename Solver>
248  // number of vectors used by this workspace
249  static int num_vectors(const Solver&) { return 0; }
250  // number of arrays used by this workspace
251  static int num_arrays(const Solver&) { return 0; }
252  // array containing the num_vectors names for the workspace vectors
253  static std::vector<std::string> op_names(const Solver&) { return {}; }
254  // array containing the num_arrays names for the workspace vectors
255  static std::vector<std::string> array_names(const Solver&) { return {}; }
256  // array containing all scalar vectors (independent of problem size)
257  static std::vector<int> scalars(const Solver&) { return {}; }
258  // array containing all vectors (dependent on problem size)
259  static std::vector<int> vectors(const Solver&) { return {}; }
260 };
261 
262 
278 template <typename DerivedType>
280 public:
287  void set_preconditioner(std::shared_ptr<const LinOp> new_precond) override
288  {
289  auto exec = self()->get_executor();
290  if (new_precond) {
291  GKO_ASSERT_EQUAL_DIMENSIONS(self(), new_precond);
292  GKO_ASSERT_IS_SQUARE_MATRIX(new_precond);
293  if (new_precond->get_executor() != exec) {
294  new_precond = gko::clone(exec, new_precond);
295  }
296  }
298  }
299 
305  {
306  if (&other != this) {
308  }
309  return *this;
310  }
311 
318  {
319  if (&other != this) {
320  set_preconditioner(other.get_preconditioner());
321  other.set_preconditioner(nullptr);
322  }
323  return *this;
324  }
325 
326  EnablePreconditionable() = default;
327 
328  EnablePreconditionable(std::shared_ptr<const LinOp> preconditioner)
329  {
330  set_preconditioner(std::move(preconditioner));
331  }
332 
337  {
338  *this = other;
339  }
340 
346  {
347  *this = std::move(other);
348  }
349 
350 private:
351  DerivedType* self() { return static_cast<DerivedType*>(this); }
352 
353  const DerivedType* self() const
354  {
355  return static_cast<const DerivedType*>(this);
356  }
357 };
358 
359 
360 namespace detail {
361 
362 
371 class SolverBaseLinOp {
372 public:
373  SolverBaseLinOp(std::shared_ptr<const Executor> exec)
374  : workspace_{std::move(exec)}
375  {}
376 
377  virtual ~SolverBaseLinOp() = default;
378 
384  std::shared_ptr<const LinOp> get_system_matrix() const
385  {
386  return system_matrix_;
387  }
388 
389  const LinOp* get_workspace_op(int vector_id) const
390  {
391  return workspace_.get_op(vector_id);
392  }
393 
394  virtual int get_num_workspace_ops() const { return 0; }
395 
396  virtual std::vector<std::string> get_workspace_op_names() const
397  {
398  return {};
399  }
400 
405  virtual std::vector<int> get_workspace_scalars() const { return {}; }
406 
411  virtual std::vector<int> get_workspace_vectors() const { return {}; }
412 
413 protected:
414  void set_system_matrix_base(std::shared_ptr<const LinOp> system_matrix)
415  {
416  system_matrix_ = std::move(system_matrix);
417  }
418 
419  void set_workspace_size(int num_operators, int num_arrays) const
420  {
421  workspace_.set_size(num_operators, num_arrays);
422  }
423 
424  template <typename LinOpType>
425  LinOpType* create_workspace_op(int vector_id, gko::dim<2> size) const
426  {
427  return workspace_.template create_or_get_op<LinOpType>(
428  vector_id,
429  [&] {
430  return LinOpType::create(this->workspace_.get_executor(), size);
431  },
432  typeid(LinOpType), size, size[1]);
433  }
434 
435  template <typename LinOpType>
436  LinOpType* create_workspace_op_with_config_of(int vector_id,
437  const LinOpType* vec) const
438  {
439  return workspace_.template create_or_get_op<LinOpType>(
440  vector_id, [&] { return LinOpType::create_with_config_of(vec); },
441  typeid(*vec), vec->get_size(), vec->get_stride());
442  }
443 
444  template <typename LinOpType>
445  LinOpType* create_workspace_op_with_type_of(int vector_id,
446  const LinOpType* vec,
447  dim<2> size) const
448  {
449  return workspace_.template create_or_get_op<LinOpType>(
450  vector_id,
451  [&] {
452  return LinOpType::create_with_type_of(
453  vec, workspace_.get_executor(), size, size[1]);
454  },
455  typeid(*vec), size, size[1]);
456  }
457 
458  template <typename LinOpType>
459  LinOpType* create_workspace_op_with_type_of(int vector_id,
460  const LinOpType* vec,
461  dim<2> global_size,
462  dim<2> local_size) const
463  {
464  return workspace_.template create_or_get_op<LinOpType>(
465  vector_id,
466  [&] {
467  return LinOpType::create_with_type_of(
468  vec, workspace_.get_executor(), global_size, local_size,
469  local_size[1]);
470  },
471  typeid(*vec), global_size, local_size[1]);
472  }
473 
474  template <typename ValueType>
475  matrix::Dense<ValueType>* create_workspace_scalar(int vector_id,
476  size_type size) const
477  {
478  return workspace_.template create_or_get_op<matrix::Dense<ValueType>>(
479  vector_id,
480  [&] {
482  workspace_.get_executor(), dim<2>{1, size});
483  },
484  typeid(matrix::Dense<ValueType>), gko::dim<2>{1, size}, size);
485  }
486 
487  template <typename ValueType>
488  const matrix::Dense<ValueType>* create_workspace_fixed_scalar(
489  int vector_id, size_type size, ValueType val) const
490  {
491  return workspace_.template create_or_get_op<matrix::Dense<ValueType>>(
492  vector_id,
493  [&] {
495  workspace_.get_executor(), dim<2>{1, size});
496  mat->fill(val);
497  return mat;
498  },
499  typeid(matrix::Dense<ValueType>), gko::dim<2>{1, size}, size);
500  }
501 
502  template <typename ValueType>
503  array<ValueType>& create_workspace_array(int array_id, size_type size) const
504  {
505  return workspace_.template create_or_get_array<ValueType>(array_id,
506  size);
507  }
508 
509  template <typename ValueType>
510  array<ValueType>& create_workspace_array(int array_id) const
511  {
512  return workspace_.template init_or_get_array<ValueType>(array_id);
513  }
514 
515 private:
516  mutable detail::workspace workspace_;
517 
518  std::shared_ptr<const LinOp> system_matrix_;
519 };
520 
521 
522 } // namespace detail
523 
524 
525 template <typename MatrixType>
526 class
527  // clang-format off
528  GKO_DEPRECATED("This class will be replaced by the template-less detail::SolverBaseLinOp in a future release") SolverBase
529  // clang-format on
530  : public detail::SolverBaseLinOp {
531 public:
532  using detail::SolverBaseLinOp::SolverBaseLinOp;
533 
541  std::shared_ptr<const MatrixType> get_system_matrix() const
542  {
543  return std::dynamic_pointer_cast<const MatrixType>(
544  SolverBaseLinOp::get_system_matrix());
545  }
546 
547 protected:
548  void set_system_matrix_base(std::shared_ptr<const MatrixType> system_matrix)
549  {
550  SolverBaseLinOp::set_system_matrix_base(std::move(system_matrix));
551  }
552 };
553 
554 
564 template <typename DerivedType, typename MatrixType = LinOp>
565 class EnableSolverBase : public SolverBase<MatrixType> {
566 public:
572  {
573  if (&other != this) {
574  set_system_matrix(other.get_system_matrix());
575  }
576  return *this;
577  }
578 
584  {
585  if (&other != this) {
586  set_system_matrix(other.get_system_matrix());
587  other.set_system_matrix(nullptr);
588  }
589  return *this;
590  }
591 
592  EnableSolverBase() : SolverBase<MatrixType>{self()->get_executor()} {}
593 
594  EnableSolverBase(std::shared_ptr<const MatrixType> system_matrix)
595  : SolverBase<MatrixType>{self()->get_executor()}
596  {
597  set_system_matrix(std::move(system_matrix));
598  }
599 
604  : SolverBase<MatrixType>{other.self()->get_executor()}
605  {
606  *this = other;
607  }
608 
614  : SolverBase<MatrixType>{other.self()->get_executor()}
615  {
616  *this = std::move(other);
617  }
618 
619  int get_num_workspace_ops() const override
620  {
621  using traits = workspace_traits<DerivedType>;
622  return traits::num_vectors(*self());
623  }
624 
625  std::vector<std::string> get_workspace_op_names() const override
626  {
627  using traits = workspace_traits<DerivedType>;
628  return traits::op_names(*self());
629  }
630 
635  std::vector<int> get_workspace_scalars() const override
636  {
637  using traits = workspace_traits<DerivedType>;
638  return traits::scalars(*self());
639  }
640 
645  std::vector<int> get_workspace_vectors() const override
646  {
647  using traits = workspace_traits<DerivedType>;
648  return traits::vectors(*self());
649  }
650 
651 protected:
652  void set_system_matrix(std::shared_ptr<const MatrixType> new_system_matrix)
653  {
654  auto exec = self()->get_executor();
655  if (new_system_matrix) {
656  GKO_ASSERT_EQUAL_DIMENSIONS(self(), new_system_matrix);
657  GKO_ASSERT_IS_SQUARE_MATRIX(new_system_matrix);
658  if (new_system_matrix->get_executor() != exec) {
659  new_system_matrix = gko::clone(exec, new_system_matrix);
660  }
661  }
662  this->set_system_matrix_base(new_system_matrix);
663  }
664 
665  void setup_workspace() const
666  {
667  using traits = workspace_traits<DerivedType>;
668  this->set_workspace_size(traits::num_vectors(*self()),
669  traits::num_arrays(*self()));
670  }
671 
672 private:
673  DerivedType* self() { return static_cast<DerivedType*>(this); }
674 
675  const DerivedType* self() const
676  {
677  return static_cast<const DerivedType*>(this);
678  }
679 };
680 
681 
689 public:
690  virtual ~IterativeBase() = default;
691 
697  std::shared_ptr<const stop::CriterionFactory> get_stop_criterion_factory()
698  const
699  {
700  return stop_factory_;
701  }
702 
709  std::shared_ptr<const stop::CriterionFactory> new_stop_factory)
710  {
711  stop_factory_ = new_stop_factory;
712  }
713 
714 private:
715  std::shared_ptr<const stop::CriterionFactory> stop_factory_;
716 };
717 
718 
728 template <typename DerivedType>
730 public:
736  {
737  if (&other != this) {
739  }
740  return *this;
741  }
742 
749  {
750  if (&other != this) {
751  set_stop_criterion_factory(other.get_stop_criterion_factory());
752  other.set_stop_criterion_factory(nullptr);
753  }
754  return *this;
755  }
756 
757  EnableIterativeBase() = default;
758 
760  std::shared_ptr<const stop::CriterionFactory> stop_factory)
761  {
762  set_stop_criterion_factory(std::move(stop_factory));
763  }
764 
768  EnableIterativeBase(const EnableIterativeBase& other) { *this = other; }
769 
775  {
776  *this = std::move(other);
777  }
778 
780  std::shared_ptr<const stop::CriterionFactory> new_stop_factory) override
781  {
782  auto exec = self()->get_executor();
783  if (new_stop_factory && new_stop_factory->get_executor() != exec) {
784  // no stopping criterion support clone currently though.
785  new_stop_factory = gko::clone(exec, new_stop_factory);
786  }
788  }
789 
790 private:
791  DerivedType* self() { return static_cast<DerivedType*>(this); }
792 
793  const DerivedType* self() const
794  {
795  return static_cast<const DerivedType*>(this);
796  }
797 };
798 
799 
807 template <typename Solver>
813  static constexpr bool is_supported = false;
814 
819  static constexpr bool requires_hermitian = false;
820 
827  static constexpr bool two_sided_projection = false;
828 };
829 
830 
841 template <typename ValueType, typename DerivedType>
843  : public EnableSolverBase<DerivedType>,
844  public EnableIterativeBase<DerivedType>,
845  public EnablePreconditionable<DerivedType> {
846 public:
848 
850  std::shared_ptr<const LinOp> system_matrix,
851  std::shared_ptr<const stop::CriterionFactory> stop_factory,
852  std::shared_ptr<const LinOp> preconditioner)
853  : EnableSolverBase<DerivedType>(std::move(system_matrix)),
854  EnableIterativeBase<DerivedType>{std::move(stop_factory)},
855  EnablePreconditionable<DerivedType>{std::move(preconditioner)}
856  {}
857 
858  template <typename FactoryParameters>
860  std::shared_ptr<const LinOp> system_matrix,
861  const FactoryParameters& params)
863  system_matrix, stop::combine(params.criteria),
864  generate_preconditioner(system_matrix, params)}
865  {
866  using traits = nullspace_traits<DerivedType>;
867  if ((params.nullspace || params.left_nullspace) &&
868  !traits::is_supported) {
869  throw NotSupported(
870  __FILE__, __LINE__, "nullspace projection",
871  name_demangling::get_type_name(typeid(DerivedType)));
872  }
873  if (system_matrix) {
874  auto exec = get_solver_executor();
875  nullspace_ = detail::prepare_nullspace<ValueType>(
876  params.nullspace, "nullspace", system_matrix.get(),
877  system_matrix->get_size()[1], exec);
878  left_nullspace_ = detail::prepare_nullspace<ValueType>(
879  params.left_nullspace, "left_nullspace", system_matrix.get(),
880  system_matrix->get_size()[0], exec);
881  }
882  if (traits::requires_hermitian) {
883  if (!left_nullspace_) {
884  left_nullspace_ = nullspace_;
885  }
886  if (!nullspace_) {
887  nullspace_ = left_nullspace_;
888  }
889  }
890  if (nullspace_) {
891  // wraps the preconditioner in the nullspace projection
892  this->set_preconditioner(this->get_preconditioner());
893  }
894  }
895 
897  const EnablePreconditionedIterativeSolver&) = default;
898 
900  default;
901 
908  {
909  if (&other != this) {
910  nullspace_ = on_executor(other.nullspace_);
911  left_nullspace_ = on_executor(other.left_nullspace_);
915  }
916  return *this;
917  }
918 
925  {
926  if (&other != this) {
927  nullspace_ = on_executor(std::exchange(other.nullspace_, nullptr));
928  left_nullspace_ =
929  on_executor(std::exchange(other.left_nullspace_, nullptr));
933  }
934  return *this;
935  }
936 
940  std::shared_ptr<const Nullspace<ValueType>> get_nullspace() const
941  {
942  return nullspace_;
943  }
944 
949  std::shared_ptr<const Nullspace<ValueType>> get_left_nullspace() const
950  {
951  return left_nullspace_;
952  }
953 
960  void set_preconditioner(std::shared_ptr<const LinOp> new_precond) override
961  {
962  if (new_precond && nullspace_ &&
963  !removes_nullspaces(new_precond.get())) {
964  new_precond = project_preconditioner(std::move(new_precond));
965  }
967  std::move(new_precond));
968  }
969 
977  std::shared_ptr<const LinOp> get_unprojected_preconditioner() const
978  {
979  auto precond = this->get_preconditioner();
980  if (nullspace_) {
981  if (auto projection = std::dynamic_pointer_cast<
982  const ::gko::preconditioner::NullspaceProjection<
983  ValueType>>(precond)) {
984  return projection->get_preconditioner();
985  }
986  }
987  return precond;
988  }
989 
990 protected:
997  void project_nullspace(ptr_param<LinOp> v) const
998  {
999  if (nullspace_) {
1000  nullspace_->project(v);
1001  }
1002  }
1003 
1015  template <typename VectorType>
1016  const VectorType* get_consistent_rhs(const VectorType* b,
1017  int workspace_id) const
1018  {
1019  if (!left_nullspace_) {
1020  return b;
1021  }
1022  auto rhs = this->create_workspace_op_with_config_of(workspace_id, b);
1023  rhs->copy_from(b);
1024  left_nullspace_->project(rhs);
1025  return rhs;
1026  }
1027 
1032  std::shared_ptr<const LinOp> get_transposed_nullspace(bool conjugate) const
1033  {
1034  assert_nullspace_transposable(conjugate);
1035  return left_nullspace_;
1036  }
1037 
1042  std::shared_ptr<const LinOp> get_transposed_left_nullspace(
1043  bool conjugate) const
1044  {
1045  assert_nullspace_transposable(conjugate);
1046  return nullspace_;
1047  }
1048 
1049 private:
1050  // whether precond already removes the nullspaces this solver needs removed
1051  bool removes_nullspaces(const LinOp* precond) const
1052  {
1053  auto projection = dynamic_cast<
1054  const ::gko::preconditioner::NullspaceProjection<ValueType>*>(
1055  precond);
1056  return projection && projection->get_nullspace() &&
1058  !left_nullspace_ || projection->get_left_nullspace());
1059  }
1060 
1061  // N(A^T) is the complex conjugate of N(A^H), which would need a
1062  // conjugated basis, so only the conjugate transpose supports complex
1063  // nullspaces.
1064  void assert_nullspace_transposable(bool conjugate) const
1065  {
1066  if (!conjugate && is_complex<ValueType>() &&
1067  (nullspace_ || left_nullspace_)) {
1068  throw NotSupported(
1069  __FILE__, __LINE__, "transpose with nullspace",
1070  name_demangling::get_type_name(typeid(DerivedType)));
1071  }
1072  }
1073 
1074  std::shared_ptr<const Executor> get_solver_executor() const
1075  {
1076  return static_cast<const DerivedType*>(this)->get_executor();
1077  }
1078 
1079  std::shared_ptr<const Nullspace<ValueType>> on_executor(
1080  std::shared_ptr<const Nullspace<ValueType>> ns) const
1081  {
1082  auto exec = get_solver_executor();
1083  if (ns && ns->get_executor() != exec) {
1084  return gko::clone(exec, ns);
1085  }
1086  return ns;
1087  }
1088 
1089  // wraps the preconditioner M into P M or, for two-sided solvers, P M Q
1090  std::shared_ptr<const LinOp> project_preconditioner(
1091  std::shared_ptr<const LinOp> precond) const
1092  {
1093  auto projection_params =
1095  .with_generated_preconditioner(std::move(precond))
1096  .with_nullspace(nullspace_);
1098  projection_params.with_left_nullspace(left_nullspace_);
1099  }
1100  return projection_params.on(get_solver_executor())
1101  ->generate(this->get_system_matrix());
1102  }
1103 
1104  template <typename FactoryParameters>
1105  static std::shared_ptr<const LinOp> generate_preconditioner(
1106  std::shared_ptr<const LinOp> system_matrix,
1107  const FactoryParameters& params)
1108  {
1109  if (params.generated_preconditioner) {
1110  return params.generated_preconditioner;
1111  } else if (params.preconditioner) {
1112  return params.preconditioner->generate(system_matrix);
1113  } else {
1115  system_matrix->get_executor(), system_matrix->get_size());
1116  }
1117  }
1118 
1119  std::shared_ptr<const Nullspace<ValueType>> nullspace_{};
1120  std::shared_ptr<const Nullspace<ValueType>> left_nullspace_{};
1121 };
1122 
1123 
1124 template <typename Parameters, typename Factory>
1126  : enable_parameters_type<Parameters, Factory> {
1130  std::vector<std::shared_ptr<const stop::CriterionFactory>>
1131  GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(criteria);
1132 };
1133 
1134 
1135 template <typename Parameters, typename Factory>
1137  : enable_iterative_solver_factory_parameters<Parameters, Factory> {
1142  std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
1144 
1149  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(
1151 
1172  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(nullspace,
1173  nullptr);
1174 
1192  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(left_nullspace,
1193  nullptr);
1194 };
1195 
1196 
1197 } // namespace solver
1198 } // namespace gko
1199 
1200 
1201 GKO_END_DISABLE_DEPRECATION_WARNINGS
1202 
1203 
1204 #endif // GKO_PUBLIC_CORE_SOLVER_SOLVER_BASE_HPP_
gko::solver::EnableIterativeBase::EnableIterativeBase
EnableIterativeBase(const EnableIterativeBase &other)
Creates a shallow copy of the provided stopping criterion.
Definition: solver_base.hpp:768
gko::solver::EnablePreconditionedIterativeSolver::operator=
EnablePreconditionedIterativeSolver & operator=(const EnablePreconditionedIterativeSolver &other)
Copies the solver state, cloning the nullspaces onto this executor if the executors don't match.
Definition: solver_base.hpp:906
gko::solver::EnableSolverBase::EnableSolverBase
EnableSolverBase(const EnableSolverBase &other)
Creates a shallow copy of the provided system matrix.
Definition: solver_base.hpp:603
gko::solver::EnableApplyWithInitialGuess
EnableApplyWithInitialGuess providing default operation for ApplyWithInitialGuess with correct valida...
Definition: solver_base.hpp:170
gko::solver::EnablePreconditionedIterativeSolver::get_left_nullspace
std::shared_ptr< const Nullspace< ValueType > > get_left_nullspace() const
Definition: solver_base.hpp:949
gko::log::profile_event_category::solver
Solver events.
gko::solver::EnableIterativeBase
A LinOp deriving from this CRTP class stores a stopping criterion factory and allows applying with a ...
Definition: solver_base.hpp:729
gko::solver::EnableSolverBase::operator=
EnableSolverBase & operator=(EnableSolverBase &&other)
Moves the provided system matrix, clones it onto this executor if executors don't match.
Definition: solver_base.hpp:583
gko::LinOp
Definition: lin_op.hpp:117
gko::solver::EnableSolverBase::get_workspace_vectors
std::vector< int > get_workspace_vectors() const override
Returns the IDs of all vectors (workspace vectors with system dimension-dependent size,...
Definition: solver_base.hpp:645
gko::Preconditionable
A LinOp implementing this interface can be preconditioned.
Definition: lin_op.hpp:758
gko::solver::enable_iterative_solver_factory_parameters
Definition: solver_base.hpp:1125
gko::solver::nullspace_traits
Traits describing how an iterative solver handles the nullspaces given by the nullspace and left_null...
Definition: solver_base.hpp:808
gko::solver::enable_preconditioned_iterative_solver_factory_parameters::nullspace
std::shared_ptr< const LinOp > nullspace
Right nullspace of the (singular) system matrix, given as a Nullspace<ValueType>.
Definition: solver_base.hpp:1173
gko::matrix::Dense::create
static std::unique_ptr< Dense > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size={}, size_type stride=0)
Creates an uninitialized Dense matrix of the specified size.
gko::solver::enable_preconditioned_iterative_solver_factory_parameters::left_nullspace
std::shared_ptr< const LinOp > left_nullspace
Left nullspace – the orthogonal complement of , given as a Nullspace<ValueType>.
Definition: solver_base.hpp:1193
gko::solver::EnablePreconditionable::operator=
EnablePreconditionable & operator=(const EnablePreconditionable &other)
Creates a shallow copy of the provided preconditioner, clones it onto this executor if executors don'...
Definition: solver_base.hpp:304
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:101
gko::ptr_param::get
T * get() const
Definition: utils_helper.hpp:77
gko::solver::enable_preconditioned_iterative_solver_factory_parameters
Definition: solver_base.hpp:1136
gko::solver::initial_guess_mode::zero
the input is zero
gko::solver::EnablePreconditionedIterativeSolver::get_nullspace
std::shared_ptr< const Nullspace< ValueType > > get_nullspace() const
Definition: solver_base.hpp:940
gko::solver::EnablePreconditionable::EnablePreconditionable
EnablePreconditionable(const EnablePreconditionable &other)
Creates a shallow copy of the provided preconditioner.
Definition: solver_base.hpp:336
gko::NotSupported
NotSupported is thrown in case it is not possible to perform the requested operation on the given obj...
Definition: exception.hpp:119
GKO_FACTORY_PARAMETER_SCALAR
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:469
gko::solver::enable_iterative_solver_factory_parameters::criteria
std::vector< std::shared_ptr< const stop::CriterionFactory > > criteria
Stopping criteria to be used by the solver.
Definition: solver_base.hpp:1131
gko::clone
detail::cloned_type< Pointer > clone(const Pointer &p)
Creates a unique clone of the object pointed to by p.
Definition: utils_helper.hpp:425
gko::solver::EnableSolverBase::get_workspace_scalars
std::vector< int > get_workspace_scalars() const override
Returns the IDs of all scalars (workspace vectors with system dimension-independent size,...
Definition: solver_base.hpp:635
gko::Preconditionable::get_preconditioner
virtual std::shared_ptr< const LinOp > get_preconditioner() const
Returns the preconditioner operator used by the Preconditionable.
Definition: lin_op.hpp:767
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::solver::EnableIterativeBase::set_stop_criterion_factory
void set_stop_criterion_factory(std::shared_ptr< const stop::CriterionFactory > new_stop_factory) override
Sets the stopping criterion of the solver.
Definition: solver_base.hpp:779
gko::solver::EnablePreconditionedIterativeSolver::set_preconditioner
void set_preconditioner(std::shared_ptr< const LinOp > new_precond) override
Sets the preconditioner.
Definition: solver_base.hpp:960
gko::solver::EnablePreconditionable
Mixin providing default operation for Preconditionable with correct value semantics.
Definition: solver_base.hpp:279
gko::solver::EnableSolverBase::operator=
EnableSolverBase & operator=(const EnableSolverBase &other)
Creates a shallow copy of the provided system matrix, clones it onto this executor if executors don't...
Definition: solver_base.hpp:571
gko::dim< 2 >
gko::solver::EnableIterativeBase::operator=
EnableIterativeBase & operator=(EnableIterativeBase &&other)
Moves the provided stopping criterion, clones it onto this executor if executors don't match.
Definition: solver_base.hpp:748
gko::solver::EnablePreconditionable::operator=
EnablePreconditionable & operator=(EnablePreconditionable &&other)
Moves the provided preconditioner, clones it onto this executor if executors don't match.
Definition: solver_base.hpp:317
gko::Preconditionable::set_preconditioner
virtual void set_preconditioner(std::shared_ptr< const LinOp > new_precond)
Sets the preconditioner operator used by the Preconditionable.
Definition: lin_op.hpp:778
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:43
gko::stop::combine
std::shared_ptr< const CriterionFactory > combine(FactoryContainer &&factories)
Combines multiple criterion factories into a single combined criterion factory.
Definition: combined.hpp:105
gko::solver::enable_preconditioned_iterative_solver_factory_parameters::generated_preconditioner
std::shared_ptr< const LinOp > generated_preconditioner
Already generated preconditioner.
Definition: solver_base.hpp:1150
gko::solver::SolverBase
Definition: solver_base.hpp:526
gko::solver::EnablePreconditionedIterativeSolver::operator=
EnablePreconditionedIterativeSolver & operator=(EnablePreconditionedIterativeSolver &&other)
Moves the solver state, cloning the nullspaces onto this executor if the executors don't match.
Definition: solver_base.hpp:923
gko::solver::nullspace_traits::requires_hermitian
static constexpr bool requires_hermitian
Whether the solver requires a Hermitian system matrix.
Definition: solver_base.hpp:819
gko::solver::EnablePreconditionable::set_preconditioner
void set_preconditioner(std::shared_ptr< const LinOp > new_precond) override
Sets the preconditioner operator used by the Preconditionable.
Definition: solver_base.hpp:287
gko::solver::EnablePreconditionedIterativeSolver::get_unprojected_preconditioner
std::shared_ptr< const LinOp > get_unprojected_preconditioner() const
Definition: solver_base.hpp:977
gko::solver::initial_guess_mode::rhs
the input is right hand side
gko::matrix::Identity::create
static std::unique_ptr< Identity > create(std::shared_ptr< const Executor > exec, dim< 2 > size)
Creates an Identity matrix of the specified size.
gko::solver::EnableSolverBase
A LinOp deriving from this CRTP class stores a system matrix.
Definition: solver_base.hpp:565
gko::solver::IterativeBase::set_stop_criterion_factory
virtual void set_stop_criterion_factory(std::shared_ptr< const stop::CriterionFactory > new_stop_factory)
Sets the stopping criterion of the solver.
Definition: solver_base.hpp:708
gko::solver::IterativeBase
A LinOp implementing this interface stores a stopping criterion factory.
Definition: solver_base.hpp:688
gko::solver::EnableSolverBase::EnableSolverBase
EnableSolverBase(EnableSolverBase &&other)
Moves the provided system matrix.
Definition: solver_base.hpp:613
gko::preconditioner::NullspaceProjection
NullspaceProjection wraps a preconditioner with projections onto the complement of a nullspace,...
Definition: nullspace_projection.hpp:50
gko::solver::SolverBase::get_system_matrix
std::shared_ptr< const MatrixType > get_system_matrix() const
Returns the system matrix, with its concrete type, used by the solver.
Definition: solver_base.hpp:541
gko::solver::IterativeBase::get_stop_criterion_factory
std::shared_ptr< const stop::CriterionFactory > get_stop_criterion_factory() const
Gets the stopping criterion factory of the solver.
Definition: solver_base.hpp:697
gko::make_temporary_clone
detail::temporary_clone< detail::pointee< Ptr > > make_temporary_clone(std::shared_ptr< const Executor > exec, Ptr &&ptr)
Creates a temporary_clone.
Definition: temporary_clone.hpp:208
gko::solver::initial_guess_mode
initial_guess_mode
Give a initial guess mode about the input of the apply method.
Definition: solver_base.hpp:39
gko::solver::EnablePreconditionable::EnablePreconditionable
EnablePreconditionable(EnablePreconditionable &&other)
Moves the provided preconditioner.
Definition: solver_base.hpp:345
gko::solver::initial_guess_mode::provided
the input is provided
gko::solver::EnableIterativeBase::EnableIterativeBase
EnableIterativeBase(EnableIterativeBase &&other)
Moves the provided stopping criterion.
Definition: solver_base.hpp:774
gko::solver::workspace_traits
Traits class providing information on the type and location of workspace vectors inside a solver.
Definition: solver_base.hpp:247
gko::enable_parameters_type
The enable_parameters_type mixin is used to create a base implementation of the factory parameters st...
Definition: abstract_factory.hpp:235
gko::solver::EnableIterativeBase::operator=
EnableIterativeBase & operator=(const EnableIterativeBase &other)
Creates a shallow copy of the provided stopping criterion, clones it onto this executor if executors ...
Definition: solver_base.hpp:735
gko::solver::nullspace_traits::two_sided_projection
static constexpr bool two_sided_projection
Whether the solver needs the two-sided projection of its preconditioner , which is symmetric for sym...
Definition: solver_base.hpp:827
gko::solver::ApplyWithInitialGuess
ApplyWithInitialGuess provides a way to give the input guess for apply function.
Definition: solver_base.hpp:71
gko::solver::enable_preconditioned_iterative_solver_factory_parameters::preconditioner
std::shared_ptr< const LinOpFactory > preconditioner
The preconditioner to be used by the iterative solver.
Definition: solver_base.hpp:1143
gko::solver::EnablePreconditionedIterativeSolver
A LinOp implementing this interface stores a system matrix and stopping criterion factory.
Definition: solver_base.hpp:842
gko::solver::nullspace_traits::is_supported
static constexpr bool is_supported
Whether the solver removes the nullspaces.
Definition: solver_base.hpp:813