Ginkgo  Generated from pipelines/3136675824 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/identity.hpp>
21 #include <ginkgo/core/matrix/multivector.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 AbstractMultiVector* b,
93  initial_guess_mode guess) const = 0;
94 
95  void apply_with_initial_guess(ptr_param<const AbstractMultiVector> b,
97  initial_guess_mode guess) const
98  {
99  apply_with_initial_guess(b.get(), x.get(), guess);
100  }
101 
114  virtual void apply_with_initial_guess(const AbstractMultiVector* alpha,
115  const AbstractMultiVector* b,
116  const AbstractMultiVector* beta,
118  initial_guess_mode guess) const = 0;
119 
120 
121  void apply_with_initial_guess(ptr_param<const AbstractMultiVector> alpha,
125  initial_guess_mode guess) const
126  {
127  apply_with_initial_guess(alpha.get(), b.get(), beta.get(), x.get(),
128  guess);
129  }
130 
136  initial_guess_mode get_default_initial_guess() const { return guess_; }
137 
144  explicit ApplyWithInitialGuess(
146  : guess_(guess)
147  {}
148 
154  void set_default_initial_guess(initial_guess_mode guess) { guess_ = guess; }
155 
156 private:
157  initial_guess_mode guess_;
158 };
159 
160 
173 template <typename DerivedType>
175 protected:
176  friend class multigrid::detail::MultigridState;
177 
180  : ApplyWithInitialGuess(guess)
181  {}
182 
188  void apply_with_initial_guess(const AbstractMultiVector* b,
190  initial_guess_mode guess) const override
191  {
192  self()->template log<log::Logger::linop_apply_started>(self(), b, x);
193  auto exec = self()->get_executor();
194  GKO_ASSERT_CONFORMANT(self(), b);
195  GKO_ASSERT_EQUAL_ROWS(self(), x);
196  GKO_ASSERT_EQUAL_COLS(b, x);
197  this->apply_with_initial_guess_impl(make_temporary_clone(exec, b).get(),
198  make_temporary_clone(exec, x).get(),
199  guess);
200  self()->template log<log::Logger::linop_apply_completed>(self(), b, x);
201  }
202 
208  void apply_with_initial_guess(const AbstractMultiVector* alpha,
209  const AbstractMultiVector* b,
210  const AbstractMultiVector* beta,
212  initial_guess_mode guess) const override
213  {
214  self()->template log<log::Logger::linop_advanced_apply_started>(
215  self(), alpha, b, beta, x);
216  auto exec = self()->get_executor();
217  GKO_ASSERT_CONFORMANT(self(), b);
218  GKO_ASSERT_EQUAL_ROWS(self(), x);
219  GKO_ASSERT_EQUAL_COLS(b, x);
220  GKO_ASSERT_EQUAL_DIMENSIONS(alpha, dim<2>(1, 1));
221  GKO_ASSERT_EQUAL_DIMENSIONS(beta, dim<2>(1, 1));
222  this->apply_with_initial_guess_impl(
223  make_temporary_clone(exec, alpha).get(),
224  make_temporary_clone(exec, b).get(),
225  make_temporary_clone(exec, beta).get(),
226  make_temporary_clone(exec, x).get(), guess);
227  self()->template log<log::Logger::linop_advanced_apply_completed>(
228  self(), alpha, b, beta, x);
229  }
230 
231  // TODO: should we provide the default implementation?
236  virtual void apply_with_initial_guess_impl(
238  initial_guess_mode guess) const = 0;
239 
244  virtual void apply_with_initial_guess_impl(
245  const AbstractMultiVector* alpha, const AbstractMultiVector* b,
247  initial_guess_mode guess) const = 0;
248 
249  GKO_ENABLE_SELF(DerivedType);
250 };
251 
252 
257 template <typename Solver>
259  // number of vectors used by this workspace
260  static int num_vectors(const Solver&) { return 0; }
261  // number of arrays used by this workspace
262  static int num_arrays(const Solver&) { return 0; }
263  // array containing the num_vectors names for the workspace vectors
264  static std::vector<std::string> op_names(const Solver&) { return {}; }
265  // array containing the num_arrays names for the workspace vectors
266  static std::vector<std::string> array_names(const Solver&) { return {}; }
267  // array containing all scalar vectors (independent of problem size)
268  static std::vector<int> scalars(const Solver&) { return {}; }
269  // array containing all vectors (dependent on problem size)
270  static std::vector<int> vectors(const Solver&) { return {}; }
271 };
272 
273 
289 template <typename DerivedType>
291 public:
298  void set_preconditioner(std::shared_ptr<const LinOp> new_precond) override
299  {
300  auto exec = self()->get_executor();
301  if (new_precond) {
302  GKO_ASSERT_EQUAL_DIMENSIONS(self(), new_precond);
303  GKO_ASSERT_IS_SQUARE_MATRIX(new_precond);
304  if (new_precond->get_executor() != exec) {
305  new_precond = gko::clone(exec, new_precond);
306  }
307  }
309  }
310 
316  {
317  if (&other != this) {
319  }
320  return *this;
321  }
322 
329  {
330  if (&other != this) {
331  set_preconditioner(other.get_preconditioner());
332  other.set_preconditioner(nullptr);
333  }
334  return *this;
335  }
336 
337  EnablePreconditionable() = default;
338 
339  EnablePreconditionable(std::shared_ptr<const LinOp> preconditioner)
340  {
341  set_preconditioner(std::move(preconditioner));
342  }
343 
348  {
349  *this = other;
350  }
351 
357  {
358  *this = std::move(other);
359  }
360 
361 private:
362  DerivedType* self() { return static_cast<DerivedType*>(this); }
363 
364  const DerivedType* self() const
365  {
366  return static_cast<const DerivedType*>(this);
367  }
368 };
369 
370 
371 namespace detail {
372 
373 
382 class SolverBaseLinOp {
383 public:
384  SolverBaseLinOp(std::shared_ptr<const Executor> exec)
385  : workspace_{std::move(exec)}
386  {}
387 
388  virtual ~SolverBaseLinOp() = default;
389 
395  std::shared_ptr<const LinOp> get_system_matrix() const
396  {
397  return system_matrix_;
398  }
399 
400  const AbstractMultiVector* get_workspace_op(int vector_id) const
401  {
402  return workspace_.get_vector(vector_id);
403  }
404 
405  virtual int get_num_workspace_ops() const { return 0; }
406 
407  virtual std::vector<std::string> get_workspace_op_names() const
408  {
409  return {};
410  }
411 
416  virtual std::vector<int> get_workspace_scalars() const { return {}; }
417 
422  virtual std::vector<int> get_workspace_vectors() const { return {}; }
423 
424 protected:
425  void set_system_matrix_base(std::shared_ptr<const LinOp> system_matrix)
426  {
427  system_matrix_ = std::move(system_matrix);
428  }
429 
430  void set_workspace_size(int num_operators, int num_arrays) const
431  {
432  workspace_.set_size(num_operators, num_arrays);
433  }
434 
435  template <typename VectorType,
436  typename = std::enable_if_t<
437  std::is_base_of_v<AbstractMultiVector, VectorType>>>
438  VectorType* create_workspace_op(int vector_id, dim<2> size) const
439  {
440  return as<VectorType>(workspace_.create_or_get_vector(
441  vector_id,
442  [&] {
443  return VectorType::create(this->workspace_.get_executor(),
444  size);
445  },
446  typeid(VectorType), size));
447  }
448 
449  AbstractMultiVector* create_workspace_op_with_config_of(
450  int vector_id, const AbstractMultiVector* vec) const
451  {
452  return workspace_.create_or_get_vector(
453  vector_id,
454  [&] { return AbstractMultiVector::create_with_config_of(vec); },
455  typeid(*vec), vec->get_size());
456  }
457 
458  AbstractMultiVector* create_workspace_op_with_type_of(
459  int vector_id, const AbstractMultiVector* vec, dim<2> global_size,
460  dim<2> local_size) const
461  {
462  return workspace_.create_or_get_vector(
463  vector_id,
464  [&] {
466  vec, workspace_.get_executor(), global_size, local_size);
467  },
468  typeid(*vec), global_size);
469  }
470 
471  template <typename ValueType>
472  matrix::MultiVector<ValueType>* create_workspace_scalar(
473  int vector_id, size_type size) const
474  {
475  return as<matrix::MultiVector<ValueType>>(
476  workspace_.create_or_get_vector(
477  vector_id,
478  [&] {
480  workspace_.get_executor(), dim<2>{1, size});
481  },
482  typeid(matrix::MultiVector<ValueType>), gko::dim<2>{1, size}));
483  }
484 
485  template <typename ValueType>
486  const matrix::MultiVector<ValueType>* create_workspace_fixed_scalar(
487  int vector_id, size_type size, ValueType val) const
488  {
489  return as<matrix::MultiVector<ValueType>>(
490  workspace_.create_or_get_vector(
491  vector_id,
492  [&] {
494  workspace_.get_executor(), dim<2>{1, size});
495  mat->fill(val);
496  return mat;
497  },
498  typeid(matrix::MultiVector<ValueType>), gko::dim<2>{1, size}));
499  }
500 
501  template <typename ValueType>
502  array<ValueType>& create_workspace_array(int array_id, size_type size) const
503  {
504  return workspace_.template create_or_get_array<ValueType>(array_id,
505  size);
506  }
507 
508  template <typename ValueType>
509  array<ValueType>& create_workspace_array(int array_id) const
510  {
511  return workspace_.template init_or_get_array<ValueType>(array_id);
512  }
513 
514 private:
515  mutable detail::workspace workspace_;
516 
517  std::shared_ptr<const LinOp> system_matrix_;
518 };
519 
520 
521 } // namespace detail
522 
523 
524 template <typename MatrixType>
525 class
526  // clang-format off
527  GKO_DEPRECATED("This class will be replaced by the template-less detail::SolverBaseLinOp in a future release") SolverBase
528  // clang-format on
529  : public detail::SolverBaseLinOp {
530 public:
531  using detail::SolverBaseLinOp::SolverBaseLinOp;
532 
540  std::shared_ptr<const MatrixType> get_system_matrix() const
541  {
542  return std::dynamic_pointer_cast<const MatrixType>(
543  SolverBaseLinOp::get_system_matrix());
544  }
545 
546 protected:
547  void set_system_matrix_base(std::shared_ptr<const MatrixType> system_matrix)
548  {
549  SolverBaseLinOp::set_system_matrix_base(std::move(system_matrix));
550  }
551 };
552 
553 
563 template <typename DerivedType, typename MatrixType = LinOp>
564 class EnableSolverBase : public SolverBase<MatrixType> {
565 public:
571  {
572  if (&other != this) {
573  set_system_matrix(other.get_system_matrix());
574  }
575  return *this;
576  }
577 
583  {
584  if (&other != this) {
585  set_system_matrix(other.get_system_matrix());
586  other.set_system_matrix(nullptr);
587  }
588  return *this;
589  }
590 
591  EnableSolverBase() : SolverBase<MatrixType>{self()->get_executor()} {}
592 
593  EnableSolverBase(std::shared_ptr<const MatrixType> system_matrix)
594  : SolverBase<MatrixType>{self()->get_executor()}
595  {
596  set_system_matrix(std::move(system_matrix));
597  }
598 
603  : SolverBase<MatrixType>{other.self()->get_executor()}
604  {
605  *this = other;
606  }
607 
613  : SolverBase<MatrixType>{other.self()->get_executor()}
614  {
615  *this = std::move(other);
616  }
617 
618  int get_num_workspace_ops() const override
619  {
620  using traits = workspace_traits<DerivedType>;
621  return traits::num_vectors(*self());
622  }
623 
624  std::vector<std::string> get_workspace_op_names() const override
625  {
626  using traits = workspace_traits<DerivedType>;
627  return traits::op_names(*self());
628  }
629 
634  std::vector<int> get_workspace_scalars() const override
635  {
636  using traits = workspace_traits<DerivedType>;
637  return traits::scalars(*self());
638  }
639 
644  std::vector<int> get_workspace_vectors() const override
645  {
646  using traits = workspace_traits<DerivedType>;
647  return traits::vectors(*self());
648  }
649 
650 protected:
651  void set_system_matrix(std::shared_ptr<const MatrixType> new_system_matrix)
652  {
653  auto exec = self()->get_executor();
654  if (new_system_matrix) {
655  GKO_ASSERT_EQUAL_DIMENSIONS(self(), new_system_matrix);
656  GKO_ASSERT_IS_SQUARE_MATRIX(new_system_matrix);
657  if (new_system_matrix->get_executor() != exec) {
658  new_system_matrix = gko::clone(exec, new_system_matrix);
659  }
660  }
661  this->set_system_matrix_base(new_system_matrix);
662  }
663 
664  void setup_workspace() const
665  {
666  using traits = workspace_traits<DerivedType>;
667  this->set_workspace_size(traits::num_vectors(*self()),
668  traits::num_arrays(*self()));
669  }
670 
671 private:
672  DerivedType* self() { return static_cast<DerivedType*>(this); }
673 
674  const DerivedType* self() const
675  {
676  return static_cast<const DerivedType*>(this);
677  }
678 };
679 
680 
688 public:
689  virtual ~IterativeBase() = default;
690 
696  std::shared_ptr<const stop::CriterionFactory> get_stop_criterion_factory()
697  const
698  {
699  return stop_factory_;
700  }
701 
708  std::shared_ptr<const stop::CriterionFactory> new_stop_factory)
709  {
710  stop_factory_ = new_stop_factory;
711  }
712 
713 private:
714  std::shared_ptr<const stop::CriterionFactory> stop_factory_;
715 };
716 
717 
727 template <typename DerivedType>
729 public:
735  {
736  if (&other != this) {
738  }
739  return *this;
740  }
741 
748  {
749  if (&other != this) {
750  set_stop_criterion_factory(other.get_stop_criterion_factory());
751  other.set_stop_criterion_factory(nullptr);
752  }
753  return *this;
754  }
755 
756  EnableIterativeBase() = default;
757 
759  std::shared_ptr<const stop::CriterionFactory> stop_factory)
760  {
761  set_stop_criterion_factory(std::move(stop_factory));
762  }
763 
767  EnableIterativeBase(const EnableIterativeBase& other) { *this = other; }
768 
774  {
775  *this = std::move(other);
776  }
777 
779  std::shared_ptr<const stop::CriterionFactory> new_stop_factory) override
780  {
781  auto exec = self()->get_executor();
782  if (new_stop_factory && new_stop_factory->get_executor() != exec) {
783  // no stopping criterion support clone currently though.
784  new_stop_factory = gko::clone(exec, new_stop_factory);
785  }
787  }
788 
789 private:
790  DerivedType* self() { return static_cast<DerivedType*>(this); }
791 
792  const DerivedType* self() const
793  {
794  return static_cast<const DerivedType*>(this);
795  }
796 };
797 
798 
806 template <typename Solver>
812  static constexpr bool is_supported = false;
813 
818  static constexpr bool requires_hermitian = false;
819 
826  static constexpr bool two_sided_projection = false;
827 };
828 
829 
840 template <typename ValueType, typename DerivedType>
842  : public EnableSolverBase<DerivedType>,
843  public EnableIterativeBase<DerivedType>,
844  public EnablePreconditionable<DerivedType> {
845 public:
847 
849  std::shared_ptr<const LinOp> system_matrix,
850  std::shared_ptr<const stop::CriterionFactory> stop_factory,
851  std::shared_ptr<const LinOp> preconditioner)
852  : EnableSolverBase<DerivedType>(std::move(system_matrix)),
853  EnableIterativeBase<DerivedType>{std::move(stop_factory)},
854  EnablePreconditionable<DerivedType>{std::move(preconditioner)}
855  {}
856 
857  template <typename FactoryParameters>
859  std::shared_ptr<const LinOp> system_matrix,
860  const FactoryParameters& params)
862  system_matrix, stop::combine(params.criteria),
863  generate_preconditioner(system_matrix, params)}
864  {
865  using traits = nullspace_traits<DerivedType>;
866  if ((params.nullspace || params.left_nullspace) &&
867  !traits::is_supported) {
868  throw NotSupported(
869  __FILE__, __LINE__, "nullspace projection",
870  name_demangling::get_type_name(typeid(DerivedType)));
871  }
872  if (system_matrix) {
873  auto exec = get_solver_executor();
874  nullspace_ = detail::prepare_nullspace<ValueType>(
875  params.nullspace, "nullspace", system_matrix.get(),
876  system_matrix->get_size()[1], exec);
877  left_nullspace_ = detail::prepare_nullspace<ValueType>(
878  params.left_nullspace, "left_nullspace", system_matrix.get(),
879  system_matrix->get_size()[0], exec);
880  }
881  if (traits::requires_hermitian) {
882  if (!left_nullspace_) {
883  left_nullspace_ = nullspace_;
884  }
885  if (!nullspace_) {
886  nullspace_ = left_nullspace_;
887  }
888  }
889  if (nullspace_) {
890  // wraps the preconditioner in the nullspace projection
891  this->set_preconditioner(this->get_preconditioner());
892  }
893  }
894 
896  const EnablePreconditionedIterativeSolver&) = default;
897 
899  default;
900 
907  {
908  if (&other != this) {
909  nullspace_ = on_executor(other.nullspace_);
910  left_nullspace_ = on_executor(other.left_nullspace_);
914  }
915  return *this;
916  }
917 
924  {
925  if (&other != this) {
926  nullspace_ = on_executor(std::exchange(other.nullspace_, nullptr));
927  left_nullspace_ =
928  on_executor(std::exchange(other.left_nullspace_, nullptr));
932  }
933  return *this;
934  }
935 
939  std::shared_ptr<const Nullspace<ValueType>> get_nullspace() const
940  {
941  return nullspace_;
942  }
943 
948  std::shared_ptr<const Nullspace<ValueType>> get_left_nullspace() const
949  {
950  return left_nullspace_;
951  }
952 
959  void set_preconditioner(std::shared_ptr<const LinOp> new_precond) override
960  {
961  if (new_precond && nullspace_ &&
962  !removes_nullspaces(new_precond.get())) {
963  new_precond = project_preconditioner(std::move(new_precond));
964  }
966  std::move(new_precond));
967  }
968 
976  std::shared_ptr<const LinOp> get_unprojected_preconditioner() const
977  {
978  auto precond = this->get_preconditioner();
979  if (nullspace_) {
980  if (auto projection = std::dynamic_pointer_cast<
981  const ::gko::preconditioner::NullspaceProjection<
982  ValueType>>(precond)) {
983  return projection->get_preconditioner();
984  }
985  }
986  return precond;
987  }
988 
989 protected:
996  void project_nullspace(ptr_param<AbstractMultiVector> v) const
997  {
998  if (nullspace_) {
999  nullspace_->project(v);
1000  }
1001  }
1002 
1014  const AbstractMultiVector* get_consistent_rhs(const AbstractMultiVector* b,
1015  int workspace_id) const
1016  {
1017  if (!left_nullspace_) {
1018  return b;
1019  }
1020  auto rhs = this->create_workspace_op_with_config_of(workspace_id, b);
1021  rhs->copy_from(b);
1022  left_nullspace_->project(rhs);
1023  return rhs;
1024  }
1025 
1030  std::shared_ptr<const LinOp> get_transposed_nullspace(bool conjugate) const
1031  {
1032  assert_nullspace_transposable(conjugate);
1033  return left_nullspace_;
1034  }
1035 
1040  std::shared_ptr<const LinOp> get_transposed_left_nullspace(
1041  bool conjugate) const
1042  {
1043  assert_nullspace_transposable(conjugate);
1044  return nullspace_;
1045  }
1046 
1047 private:
1048  // whether precond already removes the nullspaces this solver needs removed
1049  bool removes_nullspaces(const LinOp* precond) const
1050  {
1051  auto projection = dynamic_cast<
1052  const ::gko::preconditioner::NullspaceProjection<ValueType>*>(
1053  precond);
1054  return projection && projection->get_nullspace() &&
1056  !left_nullspace_ || projection->get_left_nullspace());
1057  }
1058 
1059  // N(A^T) is the complex conjugate of N(A^H), which would need a
1060  // conjugated basis, so only the conjugate transpose supports complex
1061  // nullspaces.
1062  void assert_nullspace_transposable(bool conjugate) const
1063  {
1064  if (!conjugate && is_complex<ValueType>() &&
1065  (nullspace_ || left_nullspace_)) {
1066  throw NotSupported(
1067  __FILE__, __LINE__, "transpose with nullspace",
1068  name_demangling::get_type_name(typeid(DerivedType)));
1069  }
1070  }
1071 
1072  std::shared_ptr<const Executor> get_solver_executor() const
1073  {
1074  return static_cast<const DerivedType*>(this)->get_executor();
1075  }
1076 
1077  std::shared_ptr<const Nullspace<ValueType>> on_executor(
1078  std::shared_ptr<const Nullspace<ValueType>> ns) const
1079  {
1080  auto exec = get_solver_executor();
1081  if (ns && ns->get_executor() != exec) {
1082  return gko::clone(exec, ns);
1083  }
1084  return ns;
1085  }
1086 
1087  // wraps the preconditioner M into P M or, for two-sided solvers, P M Q
1088  std::shared_ptr<const LinOp> project_preconditioner(
1089  std::shared_ptr<const LinOp> precond) const
1090  {
1091  auto projection_params =
1093  .with_generated_preconditioner(std::move(precond))
1094  .with_nullspace(nullspace_);
1096  projection_params.with_left_nullspace(left_nullspace_);
1097  }
1098  return projection_params.on(get_solver_executor())
1099  ->generate(this->get_system_matrix());
1100  }
1101 
1102  template <typename FactoryParameters>
1103  static std::shared_ptr<const LinOp> generate_preconditioner(
1104  std::shared_ptr<const LinOp> system_matrix,
1105  const FactoryParameters& params)
1106  {
1107  if (params.generated_preconditioner) {
1108  return params.generated_preconditioner;
1109  } else if (params.preconditioner) {
1110  return params.preconditioner->generate(system_matrix);
1111  } else {
1113  system_matrix->get_executor(), system_matrix->get_size());
1114  }
1115  }
1116 
1117  std::shared_ptr<const Nullspace<ValueType>> nullspace_{};
1118  std::shared_ptr<const Nullspace<ValueType>> left_nullspace_{};
1119 };
1120 
1121 
1122 template <typename Parameters, typename Factory>
1124  : enable_parameters_type<Parameters, Factory> {
1128  std::vector<std::shared_ptr<const stop::CriterionFactory>>
1129  GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(criteria);
1130 };
1131 
1132 
1133 template <typename Parameters, typename Factory>
1135  : enable_iterative_solver_factory_parameters<Parameters, Factory> {
1140  std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
1142 
1147  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(
1149 
1170  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(nullspace,
1171  nullptr);
1172 
1190  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(left_nullspace,
1191  nullptr);
1192 };
1193 
1194 
1195 } // namespace solver
1196 } // namespace gko
1197 
1198 
1199 GKO_END_DISABLE_DEPRECATION_WARNINGS
1200 
1201 
1202 #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:767
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:905
gko::solver::EnableSolverBase::EnableSolverBase
EnableSolverBase(const EnableSolverBase &other)
Creates a shallow copy of the provided system matrix.
Definition: solver_base.hpp:602
gko::solver::EnableApplyWithInitialGuess
EnableApplyWithInitialGuess providing default operation for ApplyWithInitialGuess with correct valida...
Definition: solver_base.hpp:174
gko::AbstractMultiVector::create_with_config_of
static std::unique_ptr< AbstractMultiVector > create_with_config_of(ptr_param< const AbstractMultiVector > other)
Creates an empty multi-vector with the same type, executor, size, stride and precision as other.
gko::solver::EnablePreconditionedIterativeSolver::get_left_nullspace
std::shared_ptr< const Nullspace< ValueType > > get_left_nullspace() const
Definition: solver_base.hpp:948
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:728
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:582
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:644
gko::Preconditionable
A LinOp implementing this interface can be preconditioned.
Definition: lin_op.hpp:862
gko::solver::enable_iterative_solver_factory_parameters
Definition: solver_base.hpp:1123
gko::solver::nullspace_traits
Traits describing how an iterative solver handles the nullspaces given by the nullspace and left_null...
Definition: solver_base.hpp:807
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:1171
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:1191
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:315
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:102
gko::ptr_param::get
T * get() const
Definition: utils_helper.hpp:77
gko::AbstractMultiVector::create_with_type_of
static std::unique_ptr< AbstractMultiVector > create_with_type_of(ptr_param< const AbstractMultiVector > other, std::shared_ptr< const Executor > exec)
Creates an empty multi-vector with the same type as other on exec.
gko::solver::enable_preconditioned_iterative_solver_factory_parameters
Definition: solver_base.hpp:1134
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:939
gko::solver::EnablePreconditionable::EnablePreconditionable
EnablePreconditionable(const EnablePreconditionable &other)
Creates a shallow copy of the provided preconditioner.
Definition: solver_base.hpp:347
gko::NotSupported
NotSupported is thrown in case it is not possible to perform the requested operation on the given obj...
Definition: exception.hpp:120
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:1129
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:634
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:871
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:778
gko::solver::EnablePreconditionedIterativeSolver::set_preconditioner
void set_preconditioner(std::shared_ptr< const LinOp > new_precond) override
Sets the preconditioner.
Definition: solver_base.hpp:959
gko::solver::EnablePreconditionable
Mixin providing default operation for Preconditionable with correct value semantics.
Definition: solver_base.hpp:290
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:570
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:747
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:328
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:882
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:1148
gko::solver::SolverBase
Definition: solver_base.hpp:525
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:922
gko::solver::nullspace_traits::requires_hermitian
static constexpr bool requires_hermitian
Whether the solver requires a Hermitian system matrix.
Definition: solver_base.hpp:818
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:298
gko::solver::EnablePreconditionedIterativeSolver::get_unprojected_preconditioner
std::shared_ptr< const LinOp > get_unprojected_preconditioner() const
Definition: solver_base.hpp:976
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:564
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:707
gko::solver::IterativeBase
A LinOp implementing this interface stores a stopping criterion factory.
Definition: solver_base.hpp:687
gko::solver::EnableSolverBase::EnableSolverBase
EnableSolverBase(EnableSolverBase &&other)
Moves the provided system matrix.
Definition: solver_base.hpp:612
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:540
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:696
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::matrix::MultiVector::create
static std::unique_ptr< MultiVector > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size={}, size_type stride=0)
Creates an uninitialized MultiVector of the specified size.
gko::solver::EnablePreconditionable::EnablePreconditionable
EnablePreconditionable(EnablePreconditionable &&other)
Moves the provided preconditioner.
Definition: solver_base.hpp:356
gko::solver::initial_guess_mode::provided
the input is provided
gko::AbstractMultiVector
Abstract interface class for (multi-)vector types.
Definition: multivector.hpp:81
gko::solver::EnableIterativeBase::EnableIterativeBase
EnableIterativeBase(EnableIterativeBase &&other)
Moves the provided stopping criterion.
Definition: solver_base.hpp:773
gko::solver::workspace_traits
Traits class providing information on the type and location of workspace vectors inside a solver.
Definition: solver_base.hpp:258
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:734
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:826
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:1141
gko::solver::EnablePreconditionedIterativeSolver
A LinOp implementing this interface stores a system matrix and stopping criterion factory.
Definition: solver_base.hpp:841
gko::solver::nullspace_traits::is_supported
static constexpr bool is_supported
Whether the solver removes the nullspaces.
Definition: solver_base.hpp:812