Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
DistributedTranspose.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 <iostream>
20#include <vector>
21
22#include <boost/scope_exit.hpp>
23
24#include "arccore/alina/BuiltinBackend.h"
25#include "arccore/alina/Adapters.h"
26#include "arccore/alina/DistributedMatrix.h"
27#include "arccore/alina/IO.h"
28#include "arccore/alina/Profiler.h"
29
30using namespace Arcane;
31
32int main(int argc, char* argv[])
33{
34 MPI_Init(&argc, &argv);
35 BOOST_SCOPE_EXIT(void)
36 {
37 MPI_Finalize();
38 }
39 BOOST_SCOPE_EXIT_END
40
41 Alina::mpi_communicator comm(MPI_COMM_WORLD);
42
43 int n = 16;
44 int chunk_len = (n + comm.size - 1) / comm.size;
45 int chunk_beg = std::min(n, chunk_len * comm.rank);
46 int chunk_end = std::min(n, chunk_len * (comm.rank + 1));
47 int chunk = chunk_end - chunk_beg;
48
49 std::vector<int> ptr;
50 ptr.reserve(chunk + 1);
51 ptr.push_back(0);
52 std::vector<int> col;
53 col.reserve(chunk * 4);
54 std::vector<double> val;
55 val.reserve(chunk * 4);
56
57 for (int i = 0, j = chunk_beg; i < chunk; ++i, ++j) {
58 if (j > 0) {
59 col.push_back(j - 1);
60 val.push_back(-1);
61 }
62
63 col.push_back(j);
64 val.push_back(2);
65
66 if (j + 1 < n) {
67 col.push_back(j + 1);
68 val.push_back(-1);
69 }
70
71 if (j + 5 < n) {
72 col.push_back(j + 5);
73 val.push_back(-0.1);
74 }
75
76 ptr.push_back(col.size());
77 }
78
79 typedef Alina::BuiltinBackend<double> Backend;
81
82 Matrix A(comm, std::tie(chunk, ptr, col, val), chunk);
83
84 {
85 std::ostringstream fname;
86 fname << "A_loc_" << comm.rank << ".mtx";
87 Alina::IO::mm_write(fname.str(), *A.local());
88 }
89
90 {
91 std::ostringstream fname;
92 fname << "A_rem_" << comm.rank << ".mtx";
93 Alina::IO::mm_write(fname.str(), *A.remote());
94 }
95
96 auto B = transpose(A);
97
98 {
99 std::ostringstream fname;
100 fname << "B_loc_" << comm.rank << ".mtx";
101 Alina::IO::mm_write(fname.str(), *B->local());
102 }
103
104 {
105 std::ostringstream fname;
106 fname << "B_rem_" << comm.rank << ".mtx";
107 Alina::IO::mm_write(fname.str(), *B->remote());
108 }
109}
Distributed Matrix using message passing.
Matrix class, to be used by user.
__host__ __device__ Real3x3 transpose(const Real3x3 &t)
Transpose la matrice.
Definition MathUtils.h:258
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Convenience wrapper around MPI_Comm.