22#include <boost/scope_exit.hpp>
24#include "arccore/alina/BuiltinBackend.h"
25#include "arccore/alina/Adapters.h"
26#include "arccore/alina/DistributedMatrix.h"
27#include "arccore/alina/Profiler.h"
29#include "arccore/common/internal/ProgramOptions.h"
31#include "DomainPartition.h"
37 const DomainPartition<3>& part;
38 const std::vector<ptrdiff_t>& dom;
40 renumbering(
const DomainPartition<3>& p,
41 const std::vector<ptrdiff_t>& d)
46 ptrdiff_t operator()(ptrdiff_t i, ptrdiff_t j, ptrdiff_t k)
const
48 boost::array<ptrdiff_t, 3> p = { { i, j, k } };
49 std::pair<int, ptrdiff_t> v = part.index(p);
50 return dom[v.first] + v.second;
54int main(
int argc,
char* argv[])
56 auto& prof = Alina::Profiler::globalProfiler();
57 MPI_Init(&argc, &argv);
58 BOOST_SCOPE_EXIT(
void)
67 std::cout <<
"World size: " << world.size << std::endl;
72 namespace po = Arcane::ProgramOptions;
75 desc.add_options()(
"help,h",
"show help")(
77 po::value<ptrdiff_t>(&n)->default_value(n),
81 po::store(po::parse_command_line(argc, argv, desc), vm);
84 if (vm.count(
"help")) {
85 std::cout << desc << std::endl;
89 boost::array<ptrdiff_t, 3> lo = { { 0, 0, 0 } };
90 boost::array<ptrdiff_t, 3> hi = { { n - 1, n - 1, n - 1 } };
92 prof.tic(
"partition");
93 DomainPartition<3> part(lo, hi, world.size);
94 ptrdiff_t chunk = part.size(world.rank);
96 std::vector<ptrdiff_t> domain = world.exclusive_sum(chunk);
98 lo = part.domain(world.rank).min_corner();
99 hi = part.domain(world.rank).max_corner();
102 prof.toc(
"partition");
104 prof.tic(
"assemble");
105 std::vector<ptrdiff_t> ptr;
106 std::vector<ptrdiff_t> col;
107 std::vector<double> val;
108 std::vector<double> rhs;
110 ptr.reserve(chunk + 1);
111 col.reserve(chunk * 7);
112 val.reserve(chunk * 7);
116 const double h2i = (n - 1) * (n - 1);
118 for (ptrdiff_t k = lo[2]; k <= hi[2]; ++k) {
119 for (ptrdiff_t j = lo[1]; j <= hi[1]; ++j) {
120 for (ptrdiff_t i = lo[0]; i <= hi[0]; ++i) {
122 col.push_back(renum(i, j, k - 1));
127 col.push_back(renum(i, j - 1, k));
132 col.push_back(renum(i - 1, j, k));
136 col.push_back(renum(i, j, k));
137 val.push_back(6 * h2i);
140 col.push_back(renum(i + 1, j, k));
145 col.push_back(renum(i, j + 1, k));
150 col.push_back(renum(i, j, k + 1));
154 ptr.push_back(col.size());
158 prof.toc(
"assemble");
163 prof.tic(
"create distributed version");
164 Matrix A(world, std::tie(chunk, ptr, col, val), chunk);
165 prof.toc(
"create distributed version");
167 prof.tic(
"distributed product");
168 auto B = product(A, A);
169 prof.toc(
"distributed product");
171 if (world.rank == 0) {
172 if (world.size == 1) {
174 matrix A(std::tie(chunk, ptr, col, val));
175 prof.tic(
"openmp product");
176 auto B = product(A, A);
177 prof.toc(
"openmp product");
180 std::cout << prof << std::endl;
Distributed Matrix using message passing.
Matrix class, to be used by user.
Describes a set of command-line options.
Stores parsed option values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Sparse matrix stored in CSR (Compressed Sparse Row) format.
Convenience wrapper around MPI_Comm.