95class PreconditionerRuntime
99 using backend_type = Backend;
100 using BackendType = Backend;
102 typedef typename Backend::value_type value_type;
103 typedef typename Backend::matrix matrix;
104 typedef typename Backend::vector vector;
109 template <
class Matrix>
112 params prm = params(),
113 const backend_params& bprm = backend_params())
114 : _class(prm.get(
"class", ePreconditionerType::amg))
117 if (!prm.erase(
"class"))
118 ARCCORE_ALINA_PARAM_MISSING(
"class");
119 std::cout <<
"PreconditionerClass=" << _class <<
"\n";
121 case ePreconditionerType::amg: {
123 handle =
new Precond(context, A, prm, bprm);
125 case ePreconditionerType::relaxation: {
127 handle =
new Precond(context, A, prm, bprm);
129 case ePreconditionerType::dummy: {
131 handle =
new Precond(context, A, prm, bprm);
133 case ePreconditionerType::nested: {
135 handle =
new Precond(context, A, prm, bprm);
138 ARCCORE_FATAL(
"Unsupported preconditioner class '{0}'", _class);
142 ~PreconditionerRuntime()
145 case ePreconditionerType::amg: {
147 delete static_cast<Precond*
>(handle);
149 case ePreconditionerType::relaxation: {
151 delete static_cast<Precond*
>(handle);
153 case ePreconditionerType::dummy: {
155 delete static_cast<Precond*
>(handle);
157 case ePreconditionerType::nested: {
159 delete static_cast<Precond*
>(handle);
166 template <
class Matrix>
167 void rebuild(
const Matrix& A,
const backend_params& bprm = backend_params())
170 case ePreconditionerType::amg: {
172 static_cast<Precond*
>(handle)->rebuild(A, bprm);
175 std::cerr <<
"rebuild is a noop unless the preconditioner is AMG" << std::endl;
180 template <
class Vec1,
class Vec2>
181 void apply(
const Vec1& rhs, Vec2& x)
const
184 case ePreconditionerType::amg: {
186 static_cast<Precond*
>(handle)->apply(rhs, x);
188 case ePreconditionerType::relaxation: {
190 static_cast<Precond*
>(handle)->apply(rhs, x);
192 case ePreconditionerType::dummy: {
194 static_cast<Precond*
>(handle)->apply(rhs, x);
196 case ePreconditionerType::nested: {
198 static_cast<Precond*
>(handle)->apply(rhs, x);
201 throw std::invalid_argument(
"Unsupported preconditioner class");
205 std::shared_ptr<matrix> system_matrix_ptr()
const
208 case ePreconditionerType::amg: {
210 return static_cast<Precond*
>(handle)->system_matrix_ptr();
212 case ePreconditionerType::relaxation: {
214 return static_cast<Precond*
>(handle)->system_matrix_ptr();
216 case ePreconditionerType::dummy: {
218 return static_cast<Precond*
>(handle)->system_matrix_ptr();
220 case ePreconditionerType::nested: {
222 return static_cast<Precond*
>(handle)->system_matrix_ptr();
225 throw std::invalid_argument(
"Unsupported preconditioner class");
229 const matrix& system_matrix()
const
231 return *system_matrix_ptr();
236 return backend::nbRow(system_matrix());
242 case ePreconditionerType::amg: {
244 return backend::bytes(*
static_cast<Precond*
>(handle));
246 case ePreconditionerType::relaxation: {
248 return backend::bytes(*
static_cast<Precond*
>(handle));
250 case ePreconditionerType::dummy: {
252 return backend::bytes(*
static_cast<Precond*
>(handle));
254 case ePreconditionerType::nested: {
256 return backend::bytes(*
static_cast<Precond*
>(handle));
259 throw std::invalid_argument(
"Unsupported preconditioner class");
263 friend std::ostream& operator<<(std::ostream& os,
const PreconditionerRuntime& p)
266 case ePreconditionerType::amg: {
268 return os << *static_cast<Precond*>(p.handle);
270 case ePreconditionerType::relaxation: {
272 return os << *static_cast<Precond*>(p.handle);
274 case ePreconditionerType::dummy: {
276 return os << *static_cast<Precond*>(p.handle);
278 case ePreconditionerType::nested: {
280 return os << *static_cast<Precond*>(p.handle);
283 throw std::invalid_argument(
"Unsupported preconditioner class");
289 const ePreconditionerType _class;
291 void* handle =
nullptr;