Arcane  4.2.2.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(Alina::mpi_communicator comm,
27 ptrdiff_t chunk,
28 const std::vector<ptrdiff_t>& ptr,
29 const std::vector<ptrdiff_t>& col,
30 const std::vector<double>& val,
31 const Alina::PropertyTree& prm,
32 const std::vector<double>& f)
33{
34 auto& prof = Alina::Profiler::globalProfiler();
35 //using Backend = Alina::BuiltinBackend<double>;
36
37 using BackendValueType = double;
39
40 std::cout << "Using scalar solve ptr_size=" << sizeof(ptrdiff_t)
41 << " ptr_type_size=" << sizeof(Backend::ptr_type)
42 << " col_type_size=" << sizeof(Backend::col_type)
43 << " value_type_size=" << sizeof(Backend::value_type)
44 << "\n";
45
47
49 using RelaxationType = Alina::DistributedSPAI0Relaxation<Backend>;
50 // If we want to test dynamic backends:
51 //using CoarseningType = Alina::DistributedCoarseningRuntime<Backend>;
52 //using RelaxationType = Alina::DistributedRelaxationRuntime<Backend>,
53
54 using AMGPrecondType = Alina::DistributedAMG<Backend, CoarseningType, RelaxationType,
57
59
60 typename Backend::params bprm;
61
63
64 std::shared_ptr<DMatrix> A;
65 std::shared_ptr<Solver> solve;
66
67 {
68 auto t = prof.scoped_tic("setup");
69 A = std::make_shared<DMatrix>(comm, std::tie(chunk, ptr, col, val));
70 solve = std::make_shared<Solver>(comm, A, prm, bprm);
72 solve->prm.get(prm2);
73 std::cout << "SOLVER parameters=" << prm2 << "\n";
74 }
75
76 if (comm.rank == 0) {
77 std::cout << "SolverInfo:\n";
78 std::cout << *solve << std::endl;
79 }
80
82
83 prof.tic("solve");
84 Alina::SolverResult r = (*solve)(rhs, x);
85 prof.toc("solve");
86
87 if (comm.rank == 0) {
88 std::cout << "Iterations: " << r.nbIteration() << std::endl
89 << "Error: " << r.residual() << std::endl
90 << prof << std::endl;
91 }
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
97TEST(alina_test_mpi, BasicSolver)
98{
99 Alina::mpi_communicator comm(AlinaTest::global_mpi_comm_world);
100
101 std::cout << "World size: " << comm.size << "\n";
102
104
105 ptrdiff_t n;
106 std::vector<ptrdiff_t> ptr;
107 std::vector<ptrdiff_t> col;
108 std::vector<double> val;
109 std::vector<double> rhs;
110
111 Int64 matrix_size = 32;
112 std::cout << "Matrix size=" << matrix_size << "\n";
113 n = sample_problem_distributed(comm.rank, comm.size, matrix_size, 1, ptr, col, val, rhs);
114
115 solve_scalar(comm, n, ptr, col, val, prm, rhs);
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
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:112
Result of a solution.
Definition AlinaUtils.h:53
NUMA-aware vector container.
Definition NumaVector.h:42
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Distributed smoothed aggregation coarsening scheme.
Runtime-configurable wrapper around matrix partitioner.
Convenience wrapper around MPI_Comm.