43struct DistributedRelaxationRuntime
45 typedef Backend backend_type;
46 using BackendType = backend_type;
47 typedef typename Backend::params backend_params;
51 void* handle =
nullptr;
54 params prm,
const backend_params& bprm = backend_params())
55 : r(prm.get(
"type", eRelaxationType::spai0))
57 if (!prm.erase(
"type"))
58 ARCCORE_ALINA_PARAM_MISSING(
"type");
62#define ARCCORE_ALINA_RELAX_DISTR(type) \
63 case eRelaxationType::type: \
64 handle = static_cast<void*>(new ::Arcane::Alina::Distributed##type<Backend>(A, prm, bprm)); \
67#define ARCCORE_ALINA_RELAX_LOCAL_DISTR(type) \
68 case eRelaxationType::type: \
69 handle = call_constructor<type>(A, prm, bprm); \
72#define ARCCORE_ALINA_RELAX_LOCAL_LOCAL(type) \
73 case eRelaxationType::type: \
74 handle = call_constructor<type>(*A.local(), prm, bprm); \
87#undef ARCCORE_ALINA_RELAX_LOCAL_LOCAL
88#undef ARCCORE_ALINA_RELAX_LOCAL_DISTR
89#undef ARCCORE_ALINA_RELAX_DISTR
92 throw std::invalid_argument(
"Unsupported relaxation type");
96 ~DistributedRelaxationRuntime()
99#define ARCCORE_ALINA_RELAX_DISTR(type) \
100 case eRelaxationType::type: \
101 delete static_cast<Distributed##type<Backend>*>(handle); \
104#define ARCCORE_ALINA_RELAX_LOCAL(type) \
105 case eRelaxationType::type: \
106 delete static_cast<type<Backend>*>(handle); \
119#undef ARCCORE_ALINA_RELAX_LOCAL
120#undef ARCCORE_ALINA_RELAX_DISTR
127 template <
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
128 void apply_pre(
const Matrix& A,
const VectorRHS& rhs, VectorX& x, VectorTMP& tmp)
const
132#define ARCCORE_ALINA_RELAX_DISTR(type) \
133 case eRelaxationType::type: \
134 static_cast<const Distributed##type<Backend>*>(handle)->apply_pre(A, rhs, x, tmp); \
137#define ARCCORE_ALINA_RELAX_LOCAL_DISTR(type) \
138 case eRelaxationType::type: \
139 call_apply_pre<type>(A, rhs, x, tmp); \
142#define ARCCORE_ALINA_RELAX_LOCAL_LOCAL(type) \
143 case eRelaxationType::type: \
144 call_apply_pre<type>(*A.local_backend(), rhs, x, tmp); \
157#undef ARCCORE_ALINA_RELAX_LOCAL_LOCAL
158#undef ARCCORE_ALINA_RELAX_LOCAL_DISTR
159#undef ARCCORE_ALINA_RELAX_DISTR
162 throw std::invalid_argument(
"Unsupported relaxation type");
166 template <
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
167 void apply_post(
const Matrix& A,
const VectorRHS& rhs, VectorX& x, VectorTMP& tmp)
const
171#define ARCCORE_ALINA_RELAX_DISTR(type) \
172 case eRelaxationType::type: \
173 static_cast<const ::Arcane::Alina::Distributed##type<Backend>*>(handle)->apply_post(A, rhs, x, tmp); \
176#define ARCCORE_ALINA_RELAX_LOCAL_DISTR(type) \
177 case eRelaxationType::type: \
178 call_apply_post<type>(A, rhs, x, tmp); \
181#define ARCCORE_ALINA_RELAX_LOCAL_LOCAL(type) \
182 case eRelaxationType::type: \
183 call_apply_post<type>(*A.local_backend(), rhs, x, tmp); \
196#undef ARCCORE_ALINA_RELAX_LOCAL_LOCAL
197#undef ARCCORE_ALINA_RELAX_LOCAL_DISTR
198#undef ARCCORE_ALINA_RELAX_DISTR
201 throw std::invalid_argument(
"Unsupported relaxation type");
205 template <
class Matrix,
class VectorRHS,
class VectorX>
206 void apply(
const Matrix& A,
const VectorRHS& rhs, VectorX& x)
const
210#define ARCCORE_ALINA_RELAX_DISTR(type) \
211 case eRelaxationType::type: \
212 static_cast<const Distributed##type<Backend>*>(handle)->apply(A, rhs, x); \
215#define ARCCORE_ALINA_RELAX_LOCAL_DISTR(type) \
216 case eRelaxationType::type: \
217 call_apply<type>(A, rhs, x); \
220#define ARCCORE_ALINA_RELAX_LOCAL_LOCAL(type) \
221 case eRelaxationType::type: \
222 call_apply<type>(*A.local_backend(), rhs, x); \
235#undef ARCCORE_ALINA_RELAX_LOCAL_LOCAL
236#undef ARCCORE_ALINA_RELAX_LOCAL_DISTR
237#undef ARCCORE_ALINA_RELAX_DISTR
240 throw std::invalid_argument(
"Unsupported relaxation type");
244 template <
template <
class>
class Relaxation,
class Matrix>
245 typename std::enable_if<backend::relaxation_is_supported<Backend, Relaxation>::value,
void*>::type
246 call_constructor(
const Matrix& A,
const params& prm,
const backend_params& bprm)
248 return static_cast<void*
>(
new Relaxation<Backend>(A, prm, bprm));
251 template <
template <
class>
class Relaxation,
class Matrix>
252 typename std::enable_if<!backend::relaxation_is_supported<Backend, Relaxation>::value,
void*>::type
253 call_constructor(
const Matrix&,
const params&,
const backend_params&)
255 throw std::logic_error(
"The relaxation is not supported by the backend");
258 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
259 typename std::enable_if<backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
260 call_apply_pre(
const Matrix& A,
const VectorRHS& rhs, VectorX& x, VectorTMP& tmp)
const
262 static_cast<Relaxation<Backend>*
>(handle)->apply_pre(A, rhs, x, tmp);
265 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
266 typename std::enable_if<!backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
267 call_apply_pre(
const Matrix&,
const VectorRHS&, VectorX&, VectorTMP&)
const
269 throw std::logic_error(
"The relaxation is not supported by the backend");
272 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
273 typename std::enable_if<backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
274 call_apply_post(
const Matrix& A,
const VectorRHS& rhs, VectorX& x, VectorTMP& tmp)
const
276 static_cast<Relaxation<Backend>*
>(handle)->apply_post(A, rhs, x, tmp);
279 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX,
class VectorTMP>
280 typename std::enable_if<!backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
281 call_apply_post(
const Matrix&,
const VectorRHS&, VectorX&, VectorTMP&)
const
283 throw std::logic_error(
"The relaxation is not supported by the backend");
286 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX>
287 typename std::enable_if<backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
288 call_apply(
const Matrix& A,
const VectorRHS& rhs, VectorX& x)
const
290 static_cast<Relaxation<Backend>*
>(handle)->apply(A, rhs, x);
293 template <
template <
class>
class Relaxation,
class Matrix,
class VectorRHS,
class VectorX>
294 typename std::enable_if<!backend::relaxation_is_supported<Backend, Relaxation>::value,
void>::type
295 call_apply(
const Matrix&,
const VectorRHS&, VectorX&)
const
297 throw std::logic_error(
"The relaxation is not supported by the backend");