88class DistributedPreconditioner
92 using backend_type = Backend;
93 using BackendType = Backend;
96 typedef typename backend_type::value_type value_type;
105 template <
class Matrix>
109 params prm = params(),
110 const backend_params& bprm = backend_params())
111 : _class(prm.get(
"class", eDistributedPreconditionerType::amg))
114 init(context, std::make_shared<matrix>(comm, Astrip, backend::nbRow(Astrip)), prm, bprm);
119 std::shared_ptr<matrix> A,
120 params prm = params(),
121 const backend_params& bprm = backend_params())
122 : _class(prm.get(
"class", eDistributedPreconditionerType::amg))
125 init(context, A, prm, bprm);
128 ~DistributedPreconditioner()
131 case eDistributedPreconditionerType::amg: {
132 delete static_cast<AMGPrecondType*
>(handle);
134 case eDistributedPreconditionerType::relaxation: {
138 delete static_cast<Precond*
>(handle);
145 template <
class Matrix>
146 void rebuild(
const Matrix& A,
147 const backend_params& bprm = backend_params())
150 case eDistributedPreconditionerType::amg: {
151 static_cast<AMGPrecondType*
>(handle)->rebuild(A, bprm);
154 std::cerr <<
"rebuild is a noop unless the preconditioner is AMG" << std::endl;
159 template <
class Vec1,
class Vec2>
160 void apply(
const Vec1& rhs, Vec2&& x)
const
163 case eDistributedPreconditionerType::amg: {
164 static_cast<AMGPrecondType*
>(handle)->apply(rhs, x);
166 case eDistributedPreconditionerType::relaxation: {
169 static_cast<Precond*
>(handle)->apply(rhs, x);
172 throw std::invalid_argument(
"Unsupported preconditioner class");
180 case eDistributedPreconditionerType::amg: {
183 case eDistributedPreconditionerType::relaxation: {
189 throw std::invalid_argument(
"Unsupported preconditioner class");
193 const matrix& system_matrix()
const
198 friend std::ostream& operator<<(std::ostream& os,
const DistributedPreconditioner& p)
201 case eDistributedPreconditionerType::amg: {
202 return os << *static_cast<AMGPrecondType*>(p.handle);
204 case eDistributedPreconditionerType::relaxation: {
205 typedef AsDistributedPreconditioner<DistributedRelaxationRuntime<Backend>> Precond;
207 return os << *static_cast<Precond*>(p.handle);
210 throw std::invalid_argument(
"Unsupported preconditioner class");
216 eDistributedPreconditionerType _class;
219 void init(
const AlinaContext& context, std::shared_ptr<matrix> A, params& prm,
const backend_params& bprm)
221 if (!prm.erase(
"class"))
222 ARCCORE_ALINA_PARAM_MISSING(
"class");
225 case eDistributedPreconditionerType::amg: {
226 handle =
new AMGPrecondType(context, A->comm(), A, prm, bprm);
228 case eDistributedPreconditionerType::relaxation: {
229 typedef AsDistributedPreconditioner<DistributedRelaxationRuntime<Backend>> Precond;
231 handle =
new Precond(context, A->comm(), A, prm, bprm);
234 ARCCORE_FATAL(
"Unsupported preconditioner class '{0}'", _class);
245class DistributedBlockPreconditioner
249 typedef typename Precond::params params;
250 typedef typename Precond::backend_type backend_type;
251 using BackendType = backend_type;
252 typedef typename backend_type::params backend_params;
254 typedef typename backend_type::value_type value_type;
255 typedef typename backend_type::matrix bmatrix;
258 template <
class Matrix>
259 DistributedBlockPreconditioner(
const AlinaContext& context,
262 const params& prm = params(),
263 const backend_params& bprm = backend_params())
265 A = std::make_shared<matrix>(comm, Astrip, backend::nbRow(Astrip));
266 P = std::make_shared<Precond>(context, A->local(), prm, bprm);
267 A->set_local(P->system_matrix_ptr());
268 A->move_to_backend(bprm);
271 DistributedBlockPreconditioner(
const AlinaContext& context,
273 std::shared_ptr<matrix> A,
274 const params& prm = params(),
275 const backend_params& bprm = backend_params())
278 P = std::make_shared<Precond>(context, A->local(), prm, bprm);
279 A->set_local(P->system_matrix_ptr());
280 A->move_to_backend(bprm);
283 std::shared_ptr<matrix> system_matrix_ptr()
const
288 const matrix& system_matrix()
const
293 template <
class Vec1,
class Vec2>
294 void apply(
const Vec1& rhs, Vec2&& x)
const
301 std::shared_ptr<matrix> A;
302 std::shared_ptr<Precond> P;