24#include <boost/program_options.hpp>
26#include "arccore/alina/BuiltinBackend.h"
27#include "arccore/alina/ValueTypeComplex.h"
28#include "arccore/alina/Adapters.h"
30#include "arccore/alina/DistributedPreconditionedSolver.h"
31#include "arccore/alina/DistributedPreconditioner.h"
32#include "arccore/alina/DistributedSolverRuntime.h"
34#include "arccore/alina/IO.h"
35#include "arccore/alina/Profiler.h"
38using namespace Arcane::Alina;
40namespace math = Alina::math;
45 ptrdiff_t n,
int block_size,
46 std::vector<ptrdiff_t>& ptr,
47 std::vector<ptrdiff_t>& col,
48 std::vector<std::complex<double>>& val,
49 std::vector<std::complex<double>>& rhs)
51 ptrdiff_t n3 = n * n * n;
53 ptrdiff_t chunk = (n3 + comm.size - 1) / comm.size;
54 if (chunk % block_size != 0) {
55 chunk += block_size - chunk % block_size;
57 ptrdiff_t row_beg = std::min(n3, chunk * comm.rank);
58 ptrdiff_t row_end = std::min(n3, row_beg + chunk);
59 chunk = row_end - row_beg;
62 ptr.reserve(chunk + 1);
64 col.reserve(chunk * 7);
66 val.reserve(chunk * 7);
69 std::fill(rhs.begin(), rhs.end(), 1.0);
71 const double h2i = (n - 1) * (n - 1);
74 for (ptrdiff_t idx = row_beg; idx < row_end; ++idx) {
75 ptrdiff_t k = idx / (n * n);
76 ptrdiff_t j = (idx / n) % n;
77 ptrdiff_t i = idx % n;
80 col.push_back(idx - n * n);
85 col.push_back(idx - n);
90 col.push_back(idx - 1);
95 val.push_back(6 * h2i);
98 col.push_back(idx + 1);
103 col.push_back(idx + n);
108 col.push_back(idx + n * n);
112 ptr.push_back(col.size());
121 const std::vector<ptrdiff_t>& ptr,
122 const std::vector<ptrdiff_t>& col,
123 const std::vector<std::complex<double>>& val,
125 const std::vector<std::complex<double>>& rhs)
127 auto& prof = Alina::Profiler::globalProfiler();
134 Solver solve(comm, std::tie(chunk, ptr, col, val), prm);
137 if (comm.rank == 0) {
138 std::cout << solve << std::endl;
141 std::vector<std::complex<double>> x(chunk);
147 if (comm.rank == 0) {
148 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
149 <<
"Error: " << r.residual() << std::endl
150 << prof << std::endl;
155int main(
int argc,
char* argv[])
157 auto& prof = Alina::Profiler::globalProfiler();
162 std::cout <<
"World size: " << comm.size << std::endl;
165 namespace po = boost::program_options;
166 po::options_description desc(
"Options");
168 desc.add_options()(
"help,h",
"show help")(
170 po::value<ptrdiff_t>()->default_value(128),
171 "domain size")(
"prm-file,P",
172 po::value<std::string>(),
173 "Parameter file in json format. ")(
175 po::value<std::vector<std::string>>()->multitoken(),
176 "Parameters specified as name=value pairs. "
177 "May be provided multiple times. Examples:\n"
178 " -p solver.tol=1e-3\n"
179 " -p precond.coarse_enough=300");
181 po::positional_options_description p;
184 po::variables_map vm;
185 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
188 if (vm.count(
"help")) {
190 std::cout << desc << std::endl;
195 if (vm.count(
"prm-file")) {
196 prm.read_json(vm[
"prm-file"].as<std::string>());
199 if (vm.count(
"prm")) {
200 for (
const std::string& v : vm[
"prm"].as<std::vector<std::string>>()) {
206 std::vector<ptrdiff_t> ptr;
207 std::vector<ptrdiff_t> col;
208 std::vector<std::complex<double>> val;
209 std::vector<std::complex<double>> rhs;
211 prof.tic(
"assemble");
212 n = assemble_poisson3d(comm, vm[
"size"].as<ptrdiff_t>(), 1, ptr, col, val, rhs);
213 prof.toc(
"assemble");
215 solve_scalar(comm, n, ptr, col, val, prm, rhs);
Iterative solver wrapper for distributed linear systems.
Espace de nom pour les fonctions mathématiques.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Convenience wrapper around MPI_Comm.
Convenience wrapper around MPI_Init_threads/MPI_Finalize.