19#include "arccore/alina/BuiltinBackend.h"
20#include "arccore/alina/MessagePassingUtils.h"
21#include "arccore/alina/DistributedPreconditionedSolver.h"
22#include "arccore/alina/DistributedPreconditioner.h"
23#include "arccore/alina/DistributedSolverRuntime.h"
25#include "arccore/alina/Profiler.h"
27#include "arccore/common/internal/ProgramOptions.h"
29#include "arccore/trace/ITraceMng.h"
31#include "AlinaSamplesCommon.h"
32#include "SampleProblemCommon.h"
41template <
class Backend,
class Matrix>
42std::shared_ptr<Alina::DistributedMatrix<Backend>>
45 Alina::eMatrixPartitionerType ptype,
int block_size = 1)
47 auto& prof = Alina::Profiler::globalProfiler();
48 typedef typename Backend::value_type val_type;
49 typedef typename Alina::math::rhs_of<val_type>::type rhs_type;
52 auto A = std::make_shared<DMatrix>(comm, Astrip);
54 if (comm.size == 1 || ptype == Alina::eMatrixPartitionerType::merge)
57 prof.tic(
"partition");
59 prm.put(
"type", ptype);
62 auto I = part(*A, block_size);
64 A = product(*J, *product(*A, *I));
68 J->move_to_backend(bprm);
70 Alina::backend::spmv(1, *J, rhs, 0, new_rhs);
72 prof.toc(
"partition");
81 const std::vector<ptrdiff_t>& ptr,
82 const std::vector<ptrdiff_t>& col,
83 const std::vector<double>& val,
85 const std::vector<double>& f,
86 Alina::eMatrixPartitionerType ptype)
88 auto& prof = Alina::Profiler::globalProfiler();
91 using BackendValueType = double;
94 std::cout <<
"Using scalar solve ptr_size=" <<
sizeof(ptrdiff_t)
95 <<
" ptr_type_size=" <<
sizeof(Backend::ptr_type)
96 <<
" col_type_size=" <<
sizeof(Backend::col_type)
97 <<
" value_type_size=" <<
sizeof(Backend::value_type)
119 auto get_distributed_matrix = [&]() {
120 auto t = prof.scoped_tic(
"distributed matrix");
121 std::shared_ptr<DMatrix> A;
123 if (ptype != Alina::eMatrixPartitionerType::merge) {
124 A = partition<Backend>(comm,
125 std::tie(chunk, ptr, col, val), rhs, bprm, ptype,
126 prm.get(
"precond.coarsening.aggr.block_size", 1));
127 chunk = A->loc_rows();
130 A = std::make_shared<DMatrix>(comm, std::tie(chunk, ptr, col, val));
136 std::shared_ptr<DMatrix> A;
137 std::shared_ptr<Solver> solve;
140 auto t = prof.scoped_tic(
"setup");
141 A = get_distributed_matrix();
142 solve = std::make_shared<Solver>(context, comm, A, prm, bprm);
144 solve->prm.get(prm2);
145 std::cout <<
"SOLVER parameters=" << prm2 <<
"\n";
148 if (comm.rank == 0) {
149 std::cout <<
"SolverInfo:\n";
150 std::cout << *solve << std::endl;
153 if (prm.get(
"precond.allow_rebuild",
false)) {
154 if (comm.rank == 0) {
155 std::cout <<
"Rebuilding the preconditioner..." << std::endl;
159 auto t = prof.scoped_tic(
"rebuild");
160 A = get_distributed_matrix();
161 solve->precond().rebuild(A);
164 if (comm.rank == 0) {
165 std::cout << *solve << std::endl;
175 if (comm.rank == 0) {
176 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
177 <<
"Error: " << r.residual() << std::endl
178 << prof << std::endl;
186 auto& prof = Alina::Profiler::globalProfiler();
190 tm->
info() <<
"World size: " << comm.size;
193 namespace po = Arcane::ProgramOptions;
196 auto default_partitioner_type = Alina::eMatrixPartitionerType::merge;
197#if defined(ARCCORE_ALINA_HAVE_PARMETIS)
198 default_partitioner_type = Alina::eMatrixPartitionerType::parmetis;
201 desc.add_options()(
"help,h",
"affiche l'aide")(
"matrix,A",
202 po::value<std::string>(),
203 "Matrice système au format MatrixMarket. "
204 "Si non spécifié, un problème de Poisson dans un cube unitaire 3D est assemblé. ");
205 desc.add_options()(
"partitioner,r",
206 po::value<Alina::eMatrixPartitionerType>()->default_value(
207 default_partitioner_type),
208 "Répartition de la matrice système");
209 desc.add_options()(
"size,n",
210 po::value<ptrdiff_t>()->default_value(32),
211 "taille du domaine");
212 desc.add_options()(
"prm-file,P", po::value<std::string>(),
213 "Fichier de paramètres au format json. ");
214 desc.add_options()(
"prm,p",
215 po::value<std::vector<std::string>>()->multitoken(),
216 "Paramètres spécifiés sous forme de paires nom=valeur. "
217 "Peut être fourni plusieurs fois. Exemples :\n"
218 " -p solver.tol=1e-3\n"
219 " -p precond.coarse_enough=300");
220 desc.add_options()(
"test-rebuild",
221 po::bool_switch()->default_value(
false),
222 "Lorsqu'il est spécifié, tente de reconstruire le solveur avant de résoudre. ");
231 if (vm.count(
"help")) {
233 std::cout << desc << std::endl;
238 if (vm.count(
"prm-file")) {
239 prm.read_json(vm[
"prm-file"].as<std::string>());
242 if (vm.count(
"prm")) {
243 for (
const std::string& v : vm[
"prm"].as<std::vector<std::string>>()) {
244 tm->
info() <<
"PUT_KEY_VALUE v=" << v;
250 std::vector<ptrdiff_t> ptr;
251 std::vector<ptrdiff_t> col;
252 std::vector<double> val;
253 std::vector<double> rhs;
255 Alina::eMatrixPartitionerType ptype = vm[
"partitioner"].as<Alina::eMatrixPartitionerType>();
257 prof.tic(
"assemble");
258 Int64 matrix_size = vm[
"size"].as<ptrdiff_t>();
259 tm->
info() <<
"Taille de la matrice=" << matrix_size;
260 n = Alina::PoissonProblemGenerator::createDistributedMatrix(comm.rank, comm.size, matrix_size, 1, ptr, col, val, rhs);
261 prof.toc(
"assemble");
263 if (vm[
"test-rebuild"].as<bool>()) {
264 prm.put(
"precond.allow_rebuild",
true);
267 solve_scalar(context, comm, n, ptr, col, val, prm, rhs, ptype);
274int main(
int argc,
char* argv[])
276 return Arcane::Alina::SampleMainContext::execMain(main2, argc, argv);
Runtime wrapper for distributed direct solvers.
Distributed Matrix using message passing.
Iterative solver wrapper for distributed linear systems.
Classe pour stocker les paramètres sous forme d'arbre hiérarchique clé/valeur.
NUMA-aware vector container.
Interface du gestionnaire de traces.
virtual TraceMessage info()=0
Flot pour un message d'information.
Matrix class, to be used by user.
Constructeur d'analyseur d'arguments en ligne de commande fluide.
Décrit un ensemble d'options en ligne de commande.
Décrit les arguments positionnels (non-options).
Stocke les valeurs d'options analysées.
__host__ __device__ Real3x3 transpose(const Real3x3 &t)
Transpose la matrice.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Wrapper de commodité autour de MPI_Comm.
Alina::detail::empty_params params
Distributed smoothed aggregation coarsening scheme.
Runtime-configurable wrapper around matrix partitioner.