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"
26#include "arccore/trace/ITraceMng.h"
28#include "arccore/alina/DistributedDirectSolverRuntime.h"
29#include "arccore/alina/Profiler.h"
31#include "AlinaSamplesCommon.h"
33#include <boost/program_options.hpp>
41 auto& prof = Alina::Profiler::globalProfiler();
45 tm->
info() <<
"World size: " << comm.size;
47 namespace po = boost::program_options;
48 po::options_description desc(
"Options");
50 desc.add_options()(
"help,h",
"show help")(
"size,n",
51 po::value<int>()->default_value(128),
53 desc.add_options()(
"prm-file,P",
54 po::value<std::string>(),
55 "Parameter file in json format. ");
56 desc.add_options()(
"prm,p",
57 po::value<std::vector<std::string>>()->multitoken(),
58 "Parameters specified as name=value pairs. "
59 "May be provided multiple times. Examples:\n"
60 " -p solver.tol=1e-3\n"
61 " -p precond.coarse_enough=300");
64 po::store(po::parse_command_line(argc, argv, desc), vm);
67 if (vm.count(
"help")) {
69 std::cout << desc << std::endl;
74 if (vm.count(
"prm-file")) {
75 prm.read_json(vm[
"prm-file"].as<std::string>());
78 if (vm.count(
"prm")) {
79 for (
const std::string& v : vm[
"prm"].as<std::vector<std::string>>()) {
84 const int n = vm[
"size"].as<
int>();
87 int chunk = (n2 + comm.size - 1) / comm.size;
88 int chunk_start = comm.rank * chunk;
89 int chunk_end = std::min(chunk_start + chunk, n2);
91 chunk = chunk_end - chunk_start;
93 std::vector<int> domain(comm.size + 1);
94 MPI_Allgather(&chunk, 1, MPI_INT, &domain[1], 1, MPI_INT, comm);
95 std::partial_sum(domain.begin(), domain.end(), domain.begin());
99 A.set_size(chunk, domain.back(),
true);
100 A.set_nonzeros(chunk * 5);
101 std::vector<double> rhs(chunk, 1);
103 const double h2i = (n - 1) * (n - 1);
104 for (
int idx = chunk_start, row = 0, head = 0; idx < chunk_end; ++idx, ++row) {
109 A.col[head] = idx - n;
115 A.col[head] = idx - 1;
121 A.val[head] = 4 * h2i;
125 A.col[head] = idx + 1;
131 A.col[head] = idx + n;
136 A.ptr[row + 1] = head;
138 A.setNbNonZero(A.ptr[chunk]);
139 prof.toc(
"assemble");
141 std::vector<double> x(chunk);
144 auto t = prof.scoped_tic(
"skyline");
148 tm->
info() <<
"Solver is = " << solve.type();
156#if defined(ARCCORE_ALINA_HAVE_EIGEN)
158 auto t = prof.scoped_tic(
"eigen");
165 std::vector<double> x2(chunk);
170 for (Int32 i = 0; i < chunk; ++i) {
172 Real x_eigen = x2[i];
173 Real abs_sum = std::abs(x_ref);
175 Real diff = std::abs(x_eigen - x_ref);
179 if (diff > 1.0e-12) {
180 tm->
info() <<
"I=" << i <<
" compare skyline=" << x[i] <<
" eigen=" << x2[i] <<
" diff=" << diff;
185 ARCCORE_FATAL(
"Error when comparing Eigen and SkylineLU nb_error={0}", nb_error);
193int main(
int argc,
char* argv[])
195 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.