ezp
Loading...
Searching...
No Matches
full_solver.hpp
1/*******************************************************************************
2 * Copyright (C) 2025 Theodore Chang
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17
18#ifndef FULL_SOLVER_HPP
19#define FULL_SOLVER_HPP
20
21#include "abstract_solver.hpp"
22
23namespace ezp::detail {
24 template<data_t DT, index_t IT, char ODER = 'R'> class full_solver : public abstract_solver<DT, IT, full_mat<DT, IT>> {
26
27 struct full_system {
28 IT n{-1}, block{-1}, rows{-1};
29 desc<IT> desc_a;
30 std::vector<DT> a, b;
31 std::vector<IT> ipiv;
32 };
33
34 protected:
35 full_system loc;
36
38
39 auto init_storage(const IT n) {
40 loc.n = n;
41 loc.block = std::max(IT{1}, static_cast<IT>(std::sqrt(ctx.row_block(loc.n) * ctx.col_block(loc.n))));
42 loc.rows = ctx.rows(loc.n, loc.block);
43 loc.desc_a = ctx.desc_l(loc.n, loc.n, loc.block, loc.rows);
44
45 loc.a.resize(loc.rows * ctx.cols(loc.n, loc.block));
46 loc.ipiv.resize(loc.rows + loc.block);
47 }
48
49 using base_t::to_full;
50
51 public:
53 : base_t()
54 , ctx(ODER) {}
55
56 full_solver(const IT rows, const IT cols)
57 : base_t()
58 , ctx(rows, cols, ODER) {}
59
60 class indexer {
61 IT n;
62
63 public:
64 explicit indexer(const full_mat<DT, IT>& A)
65 : n(A.n) {}
66
67 explicit indexer(const IT N)
68 : n(N) {}
69
70 auto operator()(const IT i, const IT j) const {
71 if(i < 0 || i >= n || j < 0 || j >= n) return IT{-1};
72 return i + j * n;
73 }
74 };
75
76 using base_t::solve;
77
78 template<full_container_t AT, full_container_t BT> IT solve(AT&& A, BT&& B) { return solve(to_full(A), to_full(B)); }
79 };
80} // namespace ezp::detail
81
82#endif // FULL_SOLVER_HPP
Definition abstract_solver.hpp:159
auto desc_l(const IT num_rows, const IT num_cols, const IT row_block, const IT col_block, const IT lead)
Generates a descriptor for a local matrix.
Definition abstract_solver.hpp:272
auto rows(const IT n, const IT nb) const
Computes the number of local rows of the current process.
Definition abstract_solver.hpp:317
auto col_block(const IT n) const
Computes the column block size.
Definition abstract_solver.hpp:305
auto row_block(const IT n) const
Computes the row block size.
Definition abstract_solver.hpp:300
auto cols(const IT n, const IT nb) const
Computes the number of local columns of the current process.
Definition abstract_solver.hpp:329
Definition abstract_solver.hpp:369
Definition full_solver.hpp:60
Definition full_solver.hpp:24
Definition abstract_solver.hpp:68