Arcane  4.2.2.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#include "arccore/alina/AlinaLib.h"
21
22#include "./SampleProblemCommon.h"
23
24#include <gtest/gtest.h>
25
26double constant_deflation(int, ptrdiff_t, void*)
27{
28 return 1;
29}
30
31using namespace Arcane;
32
33TEST(alina_test_mpi, DistributedAlinaLib)
34{
35 Alina::mpi_communicator world(MPI_COMM_WORLD);
36
37 int comm_rank = world.rank;
38 int comm_size = world.size;
39
40 const Int32 n = 64;
41
42 // For 32 bit indexing
43 using ColumnType = Int32;
44 // For 64 bit indexing
45 // using ColumnType = Int64;
46
47 std::vector<ColumnType> ptr;
48 std::vector<ColumnType> col;
49 std::vector<double> val;
50 std::vector<double> rhs;
51
52 Int32 chunk = sample_problem_distributed(comm_rank, comm_size, n, 1, ptr, col, val, rhs);
53
54 // Setup
56
57 prm.setString("local.coarsening.type", "smoothed_aggregation");
58 prm.setString("local.relax.type", "spai0");
59 prm.setString("isolver.type", "bicgstabl");
60 prm.setString("dsolver.type", "skyline_lu");
61
62 UniqueArray<double> x(rhs.size(), 0.0);
63
64 // Solve
65 {
66 AlinaCSRMatrixView matrix_view(chunk, ptr.data(), col.data(), val.data());
67 AlinaDistributedSolver solver(MPI_COMM_WORLD, matrix_view,
68 1, constant_deflation, nullptr, prm);
69 SmallSpan<const double> rhs_view(rhs.data(), rhs.size());
70 AlinaConvergenceInfo cnv = solver.solve(rhs_view, x.smallSpan());
71
72 std::cout << "Iterations: " << cnv.iterations << std::endl
73 << "Error: " << cnv.residual << std::endl;
74 }
75}
CSR Matrix view used in AlinaLib.
Definition AlinaLib.h:98
Distributed solver.
Definition AlinaLib.h:220
Handle parameters for Alina.
Definition AlinaLib.h:60
void setString(const char *name, const char *value)
Set floating point parameter in the parameter list.
Definition AlinaLib.cc:101
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 --
Convenience wrapper around MPI_Comm.