88class DistributedPreconditioner
92 using backend_type = Backend;
93 using BackendType = Backend;
94 typedef typename backend_type::params backend_params;
96 typedef typename backend_type::value_type value_type;
105 template <
class Matrix>
108 params prm = params(),
109 const backend_params& bprm = backend_params())
110 : _class(prm.get(
"class", eDistributedPreconditionerType::amg))
113 init(std::make_shared<matrix>(comm, Astrip, backend::nbRow(Astrip)), prm, bprm);
117 std::shared_ptr<matrix> A,
118 params prm = params(),
119 const backend_params& bprm = backend_params())
120 : _class(prm.get(
"class", eDistributedPreconditionerType::amg))
126 ~DistributedPreconditioner()
129 case eDistributedPreconditionerType::amg: {
130 delete static_cast<AMGPrecondType*
>(handle);
132 case eDistributedPreconditionerType::relaxation: {
136 delete static_cast<Precond*
>(handle);
143 template <
class Matrix>
144 void rebuild(
const Matrix& A,
145 const backend_params& bprm = backend_params())
148 case eDistributedPreconditionerType::amg: {
149 static_cast<AMGPrecondType*
>(handle)->rebuild(A, bprm);
152 std::cerr <<
"rebuild is a noop unless the preconditioner is AMG" << std::endl;
157 template <
class Vec1,
class Vec2>
158 void apply(
const Vec1& rhs, Vec2&& x)
const
161 case eDistributedPreconditionerType::amg: {
162 static_cast<AMGPrecondType*
>(handle)->apply(rhs, x);
164 case eDistributedPreconditionerType::relaxation: {
167 static_cast<Precond*
>(handle)->apply(rhs, x);
170 throw std::invalid_argument(
"Unsupported preconditioner class");
178 case eDistributedPreconditionerType::amg: {
181 case eDistributedPreconditionerType::relaxation: {
187 throw std::invalid_argument(
"Unsupported preconditioner class");
191 const matrix& system_matrix()
const
196 friend std::ostream& operator<<(std::ostream& os,
const DistributedPreconditioner& p)
199 case eDistributedPreconditionerType::amg: {
200 return os << *static_cast<AMGPrecondType*>(p.handle);
202 case eDistributedPreconditionerType::relaxation: {
203 typedef AsDistributedPreconditioner<DistributedRelaxationRuntime<Backend>> Precond;
205 return os << *static_cast<Precond*>(p.handle);
208 throw std::invalid_argument(
"Unsupported preconditioner class");
214 eDistributedPreconditionerType _class;
217 void init(std::shared_ptr<matrix> A, params& prm,
const backend_params& bprm)
219 if (!prm.erase(
"class"))
220 ARCCORE_ALINA_PARAM_MISSING(
"class");
223 case eDistributedPreconditionerType::amg: {
224 handle =
static_cast<void*
>(
new AMGPrecondType(A->comm(), A, prm, bprm));
226 case eDistributedPreconditionerType::relaxation: {
227 typedef AsDistributedPreconditioner<DistributedRelaxationRuntime<Backend>> Precond;
229 handle =
static_cast<void*
>(
new Precond(A->comm(), A, prm, bprm));
232 throw std::invalid_argument(
"Unsupported preconditioner class");
243class DistributedBlockPreconditioner
247 typedef typename Precond::params params;
248 typedef typename Precond::backend_type backend_type;
249 using BackendType = backend_type;
250 typedef typename backend_type::params backend_params;
252 typedef typename backend_type::value_type value_type;
253 typedef typename backend_type::matrix bmatrix;
256 template <
class Matrix>
259 const params& prm = params(),
260 const backend_params& bprm = backend_params())
262 A = std::make_shared<matrix>(comm, Astrip, backend::nbRow(Astrip));
263 P = std::make_shared<Precond>(A->local(), prm, bprm);
264 A->set_local(P->system_matrix_ptr());
265 A->move_to_backend(bprm);
269 std::shared_ptr<matrix> A,
270 const params& prm = params(),
271 const backend_params& bprm = backend_params())
274 P = std::make_shared<Precond>(A->local(), prm, bprm);
275 A->set_local(P->system_matrix_ptr());
276 A->move_to_backend(bprm);
279 std::shared_ptr<matrix> system_matrix_ptr()
const
284 const matrix& system_matrix()
const
289 template <
class Vec1,
class Vec2>
290 void apply(
const Vec1& rhs, Vec2&& x)
const
297 std::shared_ptr<matrix> A;
298 std::shared_ptr<Precond> P;