19#include "arccore/alina/BuiltinBackend.h"
20#include "arccore/alina/MessagePassingUtils.h"
21#include "arccore/alina/DistributedPreconditionedSolver.h"
22#include "arccore/alina/DistributedPreconditioner.h"
23#include "arccore/alina/DistributedSolverRuntime.h"
25#include "arccore/alina/Profiler.h"
27#include "arccore/common/internal/ProgramOptions.h"
29#include "arccore/trace/ITraceMng.h"
31#include "AlinaSamplesCommon.h"
32#include "SampleProblemCommon.h"
41template <
class Backend,
class Matrix>
42std::shared_ptr<Alina::DistributedMatrix<Backend>>
45 Alina::eMatrixPartitionerType ptype,
int block_size = 1)
47 auto& prof = Alina::Profiler::globalProfiler();
48 typedef typename Backend::value_type val_type;
49 typedef typename Alina::math::rhs_of<val_type>::type rhs_type;
52 auto A = std::make_shared<DMatrix>(comm, Astrip);
54 if (comm.size == 1 || ptype == Alina::eMatrixPartitionerType::merge)
57 prof.tic(
"partition");
59 prm.put(
"type", ptype);
62 auto I = part(*A, block_size);
64 A = product(*J, *product(*A, *I));
68 J->move_to_backend(bprm);
70 Alina::backend::spmv(1, *J, rhs, 0, new_rhs);
72 prof.toc(
"partition");
80 const std::vector<ptrdiff_t>& ptr,
81 const std::vector<ptrdiff_t>& col,
82 const std::vector<double>& val,
84 const std::vector<double>& f,
85 Alina::eMatrixPartitionerType ptype)
87 auto& prof = Alina::Profiler::globalProfiler();
90 using BackendValueType = double;
93 std::cout <<
"Using scalar solve ptr_size=" <<
sizeof(ptrdiff_t)
94 <<
" ptr_type_size=" <<
sizeof(Backend::ptr_type)
95 <<
" col_type_size=" <<
sizeof(Backend::col_type)
96 <<
" value_type_size=" <<
sizeof(Backend::value_type)
118 auto get_distributed_matrix = [&]() {
119 auto t = prof.scoped_tic(
"distributed matrix");
120 std::shared_ptr<DMatrix> A;
122 if (ptype != Alina::eMatrixPartitionerType::merge) {
123 A = partition<Backend>(comm,
124 std::tie(chunk, ptr, col, val), rhs, bprm, ptype,
125 prm.get(
"precond.coarsening.aggr.block_size", 1));
126 chunk = A->loc_rows();
129 A = std::make_shared<DMatrix>(comm, std::tie(chunk, ptr, col, val));
135 std::shared_ptr<DMatrix> A;
136 std::shared_ptr<Solver> solve;
139 auto t = prof.scoped_tic(
"setup");
140 A = get_distributed_matrix();
141 solve = std::make_shared<Solver>(comm, A, prm, bprm);
143 solve->prm.get(prm2);
144 std::cout <<
"SOLVER parameters=" << prm2 <<
"\n";
147 if (comm.rank == 0) {
148 std::cout <<
"SolverInfo:\n";
149 std::cout << *solve << std::endl;
152 if (prm.get(
"precond.allow_rebuild",
false)) {
153 if (comm.rank == 0) {
154 std::cout <<
"Rebuilding the preconditioner..." << std::endl;
158 auto t = prof.scoped_tic(
"rebuild");
159 A = get_distributed_matrix();
160 solve->precond().rebuild(A);
163 if (comm.rank == 0) {
164 std::cout << *solve << std::endl;
174 if (comm.rank == 0) {
175 std::cout <<
"Iterations: " << r.nbIteration() << std::endl
176 <<
"Error: " << r.residual() << std::endl
177 << prof << std::endl;
185 auto& prof = Alina::Profiler::globalProfiler();
190 tm->
info() <<
"World size: " << comm.size;
193 namespace po = Arcane::ProgramOptions;
196 auto default_partitioner_type = Alina::eMatrixPartitionerType::merge;
197#if defined(ARCCORE_ALINA_HAVE_PARMETIS)
198 default_partitioner_type = Alina::eMatrixPartitionerType::parmetis;
201 desc.add_options()(
"help,h",
"show help")(
"matrix,A",
202 po::value<std::string>(),
203 "System matrix in the MatrixMarket format. "
204 "When not specified, a Poisson problem in 3D unit cube is assembled. ");
205 desc.add_options()(
"partitioner,r",
206 po::value<Alina::eMatrixPartitionerType>()->default_value(
207 default_partitioner_type),
208 "Repartition the system matrix");
209 desc.add_options()(
"size,n",
210 po::value<ptrdiff_t>()->default_value(32),
212 desc.add_options()(
"prm-file,P", po::value<std::string>(),
213 "Parameter file in json format. ");
214 desc.add_options()(
"prm,p",
215 po::value<std::vector<std::string>>()->multitoken(),
216 "Parameters specified as name=value pairs. "
217 "May be provided multiple times. Examples:\n"
218 " -p solver.tol=1e-3\n"
219 " -p precond.coarse_enough=300");
220 desc.add_options()(
"test-rebuild",
221 po::bool_switch()->default_value(
false),
222 "When specified, try to rebuild the solver before solving. ");
231 if (vm.count(
"help")) {
233 std::cout << desc << std::endl;
238 if (vm.count(
"prm-file")) {
239 prm.read_json(vm[
"prm-file"].as<std::string>());
242 if (vm.count(
"prm")) {
243 for (
const std::string& v : vm[
"prm"].as<std::vector<std::string>>()) {
244 tm->
info() <<
"PUT_KEY_VALUE v=" << v;
250 std::vector<ptrdiff_t> ptr;
251 std::vector<ptrdiff_t> col;
252 std::vector<double> val;
253 std::vector<double> rhs;
255 Alina::eMatrixPartitionerType ptype = vm[
"partitioner"].as<Alina::eMatrixPartitionerType>();
257 prof.tic(
"assemble");
258 Int64 matrix_size = vm[
"size"].as<ptrdiff_t>();
259 tm->
info() <<
"Matrix size=" << matrix_size;
260 n = sample_problem_distributed(comm.rank, comm.size, matrix_size, 1, ptr, col, val, rhs);
261 prof.toc(
"assemble");
263 if (vm[
"test-rebuild"].as<bool>()) {
264 prm.put(
"precond.allow_rebuild",
true);
267 solve_scalar(comm, n, ptr, col, val, prm, rhs, ptype);
274int main(
int argc,
char* argv[])
276 return Arcane::Alina::SampleMainContext::execMain(main2, argc, argv);
Runtime wrapper for distributed direct solvers.
Distributed Matrix using message passing.
Iterative solver wrapper for distributed linear systems.
Class to store parameters as a hierarchical key/value tree.
NUMA-aware vector container.
virtual TraceMessage info()=0
Stream for an information message.
Matrix class, to be used by user.
Fluent command-line parser builder.
Describes a set of command-line options.
Describes positional (non-option) arguments.
Stores parsed option values.
__host__ __device__ Real3x3 transpose(const Real3x3 &t)
Transpose the matrix.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Alina::detail::empty_params params
Distributed smoothed aggregation coarsening scheme.
Runtime-configurable wrapper around matrix partitioner.
Convenience wrapper around MPI_Comm.