Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
TestDistributedAlinaLib.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/*---------------------------------------------------------------------------*/
9/*
10 * This file is based on the work on AMGCL library (version march 2026)
11 * which can be found at https://github.com/ddemidov/amgcl.
12 *
13 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
14 * SPDX-License-Identifier: MIT
15 */
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19//#include "arccore/alina/MessagePassingUtils.h"
20
21#include "arccore/common/Array.h"
22
23#include "arccore/message_passing_mpi/StandaloneMpiMessagePassingMng.h"
24
25#include "arccore/alina/AlinaLib.h"
26
27#include "./SampleProblemCommon.h"
28
29#include <gtest/gtest.h>
30
31using namespace Arcane;
32using namespace Arcane::AlinaLib;
33
34TEST(alina_test_mpi, DistributedAlinaLib)
35{
37
38 int comm_rank = mpm->commRank();
39 int comm_size = mpm->commSize();
40
41 const Int32 n = 64;
42
43 // For 32 bit indexing
44 using ColumnType = Int32;
45 // For 64 bit indexing
46 // using ColumnType = Int64;
47
48 std::vector<ColumnType> ptr;
49 std::vector<ColumnType> col;
50 std::vector<double> val;
51 std::vector<double> rhs;
52
53 Int32 chunk = Alina::PoissonProblemGenerator::createDistributedMatrix(comm_rank, comm_size, n, 1, ptr, col, val, rhs);
54
55 // Setup
56 AlinaSolverParameters prm(mpm.get());
57
58 prm.setString("precond.coarsening.type", "smoothed_aggregation");
59 prm.setString("precond.relax.type", "spai0");
60
61 UniqueArray<double> x(rhs.size(), 0.0);
62
63 // Solve
64 {
65 AlinaCSRMatrixView matrix_view(chunk, ptr.data(), col.data(), val.data());
66 AlinaDistributedSolver solver(prm, matrix_view);
67 SmallSpan<const double> rhs_view(rhs.data(), rhs.size());
68 AlinaConvergenceInfo cnv = solver.solve(rhs_view, x.smallSpan());
69
70 std::cout << "Iterations: " << cnv.iterations << std::endl
71 << "Error: " << cnv.residual << std::endl;
72 }
73}
CSR Matrix view used in AlinaLib.
Definition AlinaLib.h:192
Handle parameters for solvers.
Definition AlinaLib.h:130
static Ref< IMessagePassingMng > createRef(MPI_Comm comm, bool clean_comm=false)
Creates a manager associated with the communicator comm.
InstanceType * get() const
Associated instance or nullptr if none.
Reference to an instance.
View of an array of elements of type T.
Definition Span.h:803
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --