Arcane  v4.1.10.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 <class value_type>
77class DistributedDirectSolverRuntime
78{
79 public:
80
81 typedef Alina::PropertyTree params;
82
83 template <class Matrix>
84 DistributedDirectSolverRuntime(Alina::mpi_communicator comm, const Matrix& A, params prm = params())
85 : s(prm.get("type", eDistributedDirectSolverType::skyline_lu))
86 {
87 if (!prm.erase("type"))
88 ARCCORE_ALINA_PARAM_MISSING("type");
89
90 switch (s) {
91 case eDistributedDirectSolverType::skyline_lu: {
93 handle = static_cast<void*>(new S(comm, A, prm));
94 } break;
95 default:
96 ARCCORE_THROW(NotSupportedException, "Invalid solver type '{0}'", s);
97 }
98 }
99
100 static size_t coarse_enough()
101 {
103 }
104
105 template <class Vec1, class Vec2>
106 void operator()(const Vec1& rhs, Vec2& x) const
107 {
108 switch (s) {
109 case eDistributedDirectSolverType::skyline_lu: {
111 static_cast<const S*>(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: {
123 delete static_cast<S*>(handle);
124 } break;
125 default:
126 break;
127 }
128 }
129
130 public:
131
132 eDistributedDirectSolverType type() const { return s; }
133
134 private:
135
136 eDistributedDirectSolverType s;
137 void* handle = nullptr;
138
139 template <class S, class V, class Matrix>
140 typename std::enable_if<std::is_same<V, float>::value || std::is_same<V, double>::value, void>::type
141 do_construct(Alina::mpi_communicator comm, const Matrix& A, const params& prm)
142 {
143 handle = static_cast<void*>(new S(comm, A, prm));
144 }
145
146 template <class S, class V, class Matrix>
147 typename std::enable_if<!std::is_same<V, float>::value && !std::is_same<V, double>::value, void>::type
148 do_construct(Alina::mpi_communicator, const Matrix&, const params&)
149 {
150 throw std::logic_error("The direct solver does not support the value type");
151 }
152
153 template <class S, class V, class Vec1, class Vec2>
154 typename std::enable_if<std::is_same<V, float>::value || std::is_same<V, double>::value, void>::type
155 do_solve(const Vec1& rhs, Vec2& x) const
156 {
157 static_cast<const S*>(handle)->operator()(rhs, x);
158 }
159
160 template <class S, class V, class Vec1, class Vec2>
161 typename std::enable_if<!std::is_same<V, float>::value && !std::is_same<V, double>::value, void>::type
162 do_solve(const Vec1&, Vec2&) const
163 {
164 throw std::logic_error("The direct solver does not support the value type");
165 }
166
167 template <class S, class V>
168 typename std::enable_if<std::is_same<V, float>::value || std::is_same<V, double>::value, void>::type
169 do_destruct()
170 {
171 delete static_cast<S*>(handle);
172 }
173
174 template <class S, class V>
175 typename std::enable_if<!std::is_same<V, float>::value && !std::is_same<V, double>::value, void>::type
176 do_destruct()
177 {
178 }
179};
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184} // namespace Arcane::Alina
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189#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.