22#include "arccore/alina/BuiltinBackend.h"
23#include "arccore/alina/Adapters.h"
24#include "arccore/alina/DistributedMatrix.h"
25#include "arccore/alina/Profiler.h"
27#include "arccore/common/internal/ProgramOptions.h"
29#include "DomainPartition.h"
35 const DomainPartition<3>& part;
36 const UniqueArray<ptrdiff_t>& dom;
38 renumbering(
const DomainPartition<3>& p,
39 const UniqueArray<ptrdiff_t>& d)
44 ptrdiff_t operator()(ptrdiff_t i, ptrdiff_t j, ptrdiff_t k)
const
46 boost::array<ptrdiff_t, 3> p = { { i, j, k } };
47 std::pair<int, ptrdiff_t> v = part.index(p);
48 return dom[v.first] + v.second;
52int main(
int argc,
char* argv[])
54 auto& prof = Alina::Profiler::globalProfiler();
60 std::cout <<
"World size: " << world.size << std::endl;
65 namespace po = Arcane::ProgramOptions;
68 desc.add_options()(
"help,h",
"show help")(
70 po::value<ptrdiff_t>(&n)->default_value(n),
74 po::store(po::parse_command_line(argc, argv, desc), vm);
77 if (vm.count(
"help")) {
78 std::cout << desc << std::endl;
82 boost::array<ptrdiff_t, 3> lo = { { 0, 0, 0 } };
83 boost::array<ptrdiff_t, 3> hi = { { n - 1, n - 1, n - 1 } };
85 prof.tic(
"partition");
86 DomainPartition<3> part(lo, hi, world.size);
87 ptrdiff_t chunk = part.size(world.rank);
91 lo = part.domain(world.rank).min_corner();
92 hi = part.domain(world.rank).max_corner();
95 prof.toc(
"partition");
98 std::vector<ptrdiff_t> ptr;
99 std::vector<ptrdiff_t> col;
100 std::vector<double> val;
101 std::vector<double> rhs;
103 ptr.reserve(chunk + 1);
104 col.reserve(chunk * 7);
105 val.reserve(chunk * 7);
109 const double h2i = (n - 1) * (n - 1);
111 for (ptrdiff_t k = lo[2]; k <= hi[2]; ++k) {
112 for (ptrdiff_t j = lo[1]; j <= hi[1]; ++j) {
113 for (ptrdiff_t i = lo[0]; i <= hi[0]; ++i) {
115 col.push_back(renum(i, j, k - 1));
120 col.push_back(renum(i, j - 1, k));
125 col.push_back(renum(i - 1, j, k));
129 col.push_back(renum(i, j, k));
130 val.push_back(6 * h2i);
133 col.push_back(renum(i + 1, j, k));
138 col.push_back(renum(i, j + 1, k));
143 col.push_back(renum(i, j, k + 1));
147 ptr.push_back(col.size());
151 prof.toc(
"assemble");
156 prof.tic(
"create distributed version");
157 Matrix A(world, std::tie(chunk, ptr, col, val), chunk);
158 prof.toc(
"create distributed version");
160 prof.tic(
"distributed product");
161 auto B = product(A, A);
162 prof.toc(
"distributed product");
164 if (world.rank == 0) {
165 if (world.size == 1) {
167 matrix A(std::tie(chunk, ptr, col, val));
168 prof.tic(
"openmp product");
169 auto B = product(A, A);
170 prof.toc(
"openmp product");
173 std::cout << prof << std::endl;
Distributed Matrix using message passing.
Matrix class, to be used by user.
static Ref< IMessagePassingMng > createAndInitializeMPI(int *argc, char **argv[], int wanted_thread_level)
Initialize MPI and creates a manager associated with the MPI_WORLD_COMM communicator.
Describes a set of command-line options.
Stores parsed option values.
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.
Sparse matrix stored in CSR (Compressed Sparse Row) format.