19#if defined(ARCCORE_ALINA_HAVE_EIGEN)
21#pragma GCC diagnostic ignored "-Wdeprecated-copy"
22#pragma GCC diagnostic ignored "-Wint-in-bool-context"
23#include "arccore/alina/DistributedEigenSparseLUDirectSolver.h"
24#include "arccore/alina/EigenBackend.h"
27#include "arccore/trace/ITraceMng.h"
29#include "arccore/alina/DistributedDirectSolverRuntime.h"
30#include "arccore/alina/Profiler.h"
32#include "AlinaSamplesCommon.h"
34#include <boost/program_options.hpp>
42 auto& prof = Alina::Profiler::globalProfiler();
46 tm->
info() <<
"World size: " << comm.size;
48 namespace po = boost::program_options;
49 po::options_description desc(
"Options");
51 desc.add_options()(
"help,h",
"show help")(
"size,n",
52 po::value<int>()->default_value(128),
54 desc.add_options()(
"prm-file,P",
55 po::value<std::string>(),
56 "Parameter file in json format. ");
57 desc.add_options()(
"prm,p",
58 po::value<std::vector<std::string>>()->multitoken(),
59 "Parameters specified as name=value pairs. "
60 "May be provided multiple times. Examples:\n"
61 " -p solver.tol=1e-3\n"
62 " -p precond.coarse_enough=300");
65 po::store(po::parse_command_line(argc, argv, desc), vm);
68 if (vm.count(
"help")) {
70 std::cout << desc << std::endl;
75 if (vm.count(
"prm-file")) {
76 prm.read_json(vm[
"prm-file"].as<std::string>());
79 if (vm.count(
"prm")) {
80 for (
const std::string& v : vm[
"prm"].as<std::vector<std::string>>()) {
85 const int n = vm[
"size"].as<
int>();
88 int chunk = (n2 + comm.size - 1) / comm.size;
89 int chunk_start = comm.rank * chunk;
90 int chunk_end = std::min(chunk_start + chunk, n2);
92 chunk = chunk_end - chunk_start;
94 std::vector<int> domain(comm.size + 1);
95 MPI_Allgather(&chunk, 1, MPI_INT, &domain[1], 1, MPI_INT, comm);
96 std::partial_sum(domain.begin(), domain.end(), domain.begin());
100 A.set_size(chunk, domain.back(),
true);
101 A.set_nonzeros(chunk * 5);
102 std::vector<double> rhs(chunk, 1);
104 const double h2i = (n - 1) * (n - 1);
105 for (
int idx = chunk_start, row = 0, head = 0; idx < chunk_end; ++idx, ++row) {
110 A.col[head] = idx - n;
116 A.col[head] = idx - 1;
122 A.val[head] = 4 * h2i;
126 A.col[head] = idx + 1;
132 A.col[head] = idx + n;
137 A.ptr[row + 1] = head;
139 A.setNbNonZero(A.ptr[chunk]);
140 prof.toc(
"assemble");
142 std::vector<double> x(chunk);
145 auto t = prof.scoped_tic(
"skyline");
150 tm->
info() <<
"Solver is = " << solve.type();
158#if defined(ARCCORE_ALINA_HAVE_EIGEN)
160 auto t = prof.scoped_tic(
"eigen");
168 std::vector<double> x2(chunk);
173 for (Int32 i = 0; i < chunk; ++i) {
175 Real x_eigen = x2[i];
176 Real abs_sum = std::abs(x_ref);
178 Real diff = std::abs(x_eigen - x_ref);
182 if (diff > 1.0e-12) {
183 tm->
info() <<
"I=" << i <<
" compare skyline=" << x[i] <<
" eigen=" << x2[i] <<
" diff=" << diff;
188 ARCCORE_FATAL(
"Error when comparing Eigen and SkylineLU nb_error={0}", nb_error);
196int main(
int argc,
char* argv[])
198 return Arcane::Alina::SampleMainContext::execMain(main2, argc, argv);
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Runtime wrapper for distributed direct solvers.
Distributed wrapper for Eigen::SparseLU solver.
Interface du gestionnaire de traces.
virtual TraceMessage info()=0
Flot pour un message d'information.
-*- 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.