Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
TestDistributedSolver.cc
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#include <gtest/gtest.h>
9
10#include "arccore/alina/BuiltinBackend.h"
11#include "arccore/alina/StaticMatrix.h"
12#include "arccore/alina/Adapters.h"
13#include "arccore/alina/MessagePassingUtils.h"
14#include "arccore/alina/DistributedPreconditionedSolver.h"
15#include "arccore/alina/DistributedPreconditioner.h"
16#include "arccore/alina/DistributedSolverRuntime.h"
17
18#include "./SampleProblemCommon.h"
19
20#include "TestMainMpi.h"
21
22using namespace Arcane;
23
24//---------------------------------------------------------------------------
25
26void solve_scalar(const Alina::AlinaContext& context,
28 ptrdiff_t chunk,
29 const std::vector<ptrdiff_t>& ptr,
30 const std::vector<ptrdiff_t>& col,
31 const std::vector<double>& val,
32 const Alina::PropertyTree& prm,
33 const std::vector<double>& f)
34{
35 auto& prof = Alina::Profiler::globalProfiler();
36 //using Backend = Alina::BuiltinBackend<double>;
37
38 using BackendValueType = double;
40
41 std::cout << "Using scalar solve ptr_size=" << sizeof(ptrdiff_t)
42 << " ptr_type_size=" << sizeof(Backend::ptr_type)
43 << " col_type_size=" << sizeof(Backend::col_type)
44 << " value_type_size=" << sizeof(Backend::value_type)
45 << "\n";
46
48
50 using RelaxationType = Alina::DistributedSPAI0Relaxation<Backend>;
51 // If we want to test dynamic backends:
52 //using CoarseningType = Alina::DistributedCoarseningRuntime<Backend>;
53 //using RelaxationType = Alina::DistributedRelaxationRuntime<Backend>,
54
55 using AMGPrecondType = Alina::DistributedAMG<Backend, CoarseningType, RelaxationType,
58
60
61 typename Backend::params bprm;
62
64
65 std::shared_ptr<DMatrix> A;
66 std::shared_ptr<Solver> solve;
67
68 {
69 auto t = prof.scoped_tic("setup");
70 A = std::make_shared<DMatrix>(comm, std::tie(chunk, ptr, col, val));
71 solve = std::make_shared<Solver>(context, comm, A, prm, bprm);
73 solve->prm.get(prm2);
74 std::cout << "SOLVER parameters=" << prm2 << "\n";
75 }
76
77 if (comm.rank == 0) {
78 std::cout << "SolverInfo:\n";
79 std::cout << *solve << std::endl;
80 }
81
83
84 prof.tic("solve");
85 Alina::SolverResult r = (*solve)(rhs, x);
86 prof.toc("solve");
87
88 if (comm.rank == 0) {
89 std::cout << "Iterations: " << r.nbIteration() << std::endl
90 << "Error: " << r.residual() << std::endl
91 << prof << std::endl;
92 }
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98TEST(alina_test_mpi, BasicSolver)
99{
101 Alina::AlinaCommunicator comm(mpm);
102
103 std::cout << "World size: " << comm.size << "\n";
104
106 Alina::AlinaContext context;
107 std::vector<ptrdiff_t> ptr;
108 std::vector<ptrdiff_t> col;
109 std::vector<double> val;
110 std::vector<double> rhs;
111
112 Int64 matrix_size = 32;
113 std::cout << "Matrix size=" << matrix_size << "\n";
114 ptrdiff_t n = Alina::PoissonProblemGenerator::createDistributedMatrix(comm.rank, comm.size, matrix_size, 1, ptr, col, val, rhs);
115
116 solve_scalar(context, comm, n, ptr, col, val, prm, rhs);
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
Runtime wrapper for distributed direct solvers.
Distributed Matrix using message passing.
Iterative solver wrapper for distributed linear systems.
Class to store parameters as a hierarchical key/value tree.
Definition AlinaUtils.h:113
Result of a solution.
Definition AlinaUtils.h:56
NUMA-aware vector container.
Definition NumaVector.h:42
static Ref< IMessagePassingMng > createWorldRef()
Creates a manager associated with the MPI_WORLD_COMM communicator.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Convenience wrapper around MPI_Comm.
Distributed smoothed aggregation coarsening scheme.
Runtime-configurable wrapper around matrix partitioner.