Arcane  4.1.11.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
DistributedDirectSolverRuntime.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* DistributedDirectSolverRuntime.h (C) 2000-2026 */
9/* */
10/* Runtime wrapper for distributed direct solvers. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_MPI_DISTRIBUTEDDIRECTSOLVERRUNTIME_H
13#define ARCCORE_ALINA_MPI_DISTRIBUTEDDIRECTSOLVERRUNTIME_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16/*
17 * This file is based on the work on AMGCL library (version march 2026)
18 * which can be found at https://github.com/ddemidov/amgcl.
19 *
20 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
21 * SPDX-License-Identifier: MIT
22 */
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26#include "arccore/alina/DistributedSkylineLUDirectSolver.h"
27
28#include "arccore/base/NotSupportedException.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane::Alina
34{
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38enum class eDistributedDirectSolverType
39{
40 skyline_lu
41};
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46inline std::ostream& operator<<(std::ostream& os, eDistributedDirectSolverType s)
47{
48 switch (s) {
49 case eDistributedDirectSolverType::skyline_lu:
50 return os << "skyline_lu";
51 default:
52 return os << "???";
53 }
54}
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
59inline std::istream& operator>>(std::istream& in, eDistributedDirectSolverType& s)
60{
61 std::string val;
62 in >> val;
63
64 if (val == "skyline_lu")
65 s = eDistributedDirectSolverType::skyline_lu;
66 else
67 ARCCORE_FATAL("Invalid direct solver value. Valid choices are: 'skyline_lu'");
68 return in;
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
76template <typename Backend>
77class DistributedDirectSolverRuntime
78{
79 public:
80
81 typedef typename Backend::value_type value_type;
82 typedef Alina::PropertyTree params;
83 using SkylineSolverType = DistributedSkylineLUDirectSolver<Backend>;
84
85 template <class Matrix>
86 DistributedDirectSolverRuntime(Alina::mpi_communicator comm, const Matrix& A, params prm = params())
87 : s(prm.get("type", eDistributedDirectSolverType::skyline_lu))
88 {
89 if (!prm.erase("type"))
90 ARCCORE_ALINA_PARAM_MISSING("type");
91
92 switch (s) {
93 case eDistributedDirectSolverType::skyline_lu: {
94 handle = static_cast<void*>(new SkylineSolverType(comm, A, prm));
95 } break;
96 default:
97 ARCCORE_THROW(NotSupportedException, "Invalid solver type '{0}'", s);
98 }
99 }
100
101 static size_t coarse_enough()
102 {
104 }
105
106 template <class Vec1, class Vec2>
107 void operator()(const Vec1& rhs, Vec2& x) const
108 {
109 switch (s) {
110 case eDistributedDirectSolverType::skyline_lu: {
111 static_cast<const SkylineSolverType*>(handle)->operator()(rhs, x);
112 } break;
113 default:
114 ARCCORE_THROW(NotSupportedException, "Invalid solver type '{0}'", s);
115 }
116 }
117
118 ~DistributedDirectSolverRuntime()
119 {
120 switch (s) {
121 case eDistributedDirectSolverType::skyline_lu: {
122 delete static_cast<SkylineSolverType*>(handle);
123 } break;
124 default:
125 break;
126 }
127 }
128
129 public:
130
131 eDistributedDirectSolverType type() const { return s; }
132
133 private:
134
135 eDistributedDirectSolverType s;
136 void* handle = nullptr;
137
138 template <class S, class V, class Matrix>
139 typename std::enable_if<std::is_same<V, float>::value || std::is_same<V, double>::value, void>::type
140 do_construct(Alina::mpi_communicator comm, const Matrix& A, const params& prm)
141 {
142 handle = static_cast<void*>(new S(comm, A, prm));
143 }
144
145 template <class S, class V, class Matrix>
146 typename std::enable_if<!std::is_same<V, float>::value && !std::is_same<V, double>::value, void>::type
147 do_construct(Alina::mpi_communicator, const Matrix&, const params&)
148 {
149 throw std::logic_error("The direct solver does not support the value type");
150 }
151
152 template <class S, class V, class Vec1, class Vec2>
153 typename std::enable_if<std::is_same<V, float>::value || std::is_same<V, double>::value, void>::type
154 do_solve(const Vec1& rhs, Vec2& x) const
155 {
156 static_cast<const S*>(handle)->operator()(rhs, x);
157 }
158
159 template <class S, class V, class Vec1, class Vec2>
160 typename std::enable_if<!std::is_same<V, float>::value && !std::is_same<V, double>::value, void>::type
161 do_solve(const Vec1&, Vec2&) const
162 {
163 throw std::logic_error("The direct solver does not support the value type");
164 }
165
166 template <class S, class V>
167 typename std::enable_if<std::is_same<V, float>::value || std::is_same<V, double>::value, void>::type
168 do_destruct()
169 {
170 delete static_cast<S*>(handle);
171 }
172
173 template <class S, class V>
174 typename std::enable_if<!std::is_same<V, float>::value && !std::is_same<V, double>::value, void>::type
175 do_destruct()
176 {
177 }
178};
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183} // namespace Arcane::Alina
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188#endif
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ARCCORE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
Provides distributed direct solver interface for Skyline LU solver.
Matrix class, to be used by user.
Exception lorsqu'une opération n'est pas supportée.
Number of rows for statically sized matrix types.
Convenience wrapper around MPI_Comm.