suanPan
Loading...
Searching...
No Matches
SparseMatClusterLIS.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (C) 2017-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 ******************************************************************************/
29#ifndef SPARSEMATMPILIS_HPP
30#define SPARSEMATMPILIS_HPP
31
32#include "../SparseMat.hpp"
33
34#include <ezp/ezp/lis.hpp>
35
36template<sp_d T> class SparseMatClusterLIS final : public SparseMat<T> {
37 ezp::lis solver{};
38
40
41 int solve_full(Mat<T>&);
42
43protected:
44 int direct_solve(Mat<T>& X, Mat<T>&& B) override { return this->solve_full(X = std::move(B)); }
45
46 int direct_solve(Mat<T>& X, const Mat<T>& B) override { return this->solve_full(X = B); }
47
48public:
50
51 unique_ptr<MetaMat<T>> make_copy() override { return std::make_unique<SparseMatClusterLIS>(*this); }
52};
53
54#pragma GCC diagnostic push
55#pragma GCC diagnostic ignored "-Wnarrowing"
56template<sp_d T> int SparseMatClusterLIS<T>::solve_full(Mat<T>& X) {
57 la_it info{-1};
58
59 solver.set_option(this->setting.option.c_str());
60
61 if(this->factored) info = solver.solve({X.n_rows, X.n_cols, X.memptr()});
62 else {
63 this->factored = true;
64
65 csr_mat = csr_form<LIS_SCALAR, LIS_INT>(this->triplet_mat, SparseBase::ZERO, false);
66
67 info = solver.solve({csr_mat.n_rows, csr_mat.n_elem, csr_mat.row_mem(), csr_mat.col_mem(), csr_mat.val_mem()}, {X.n_rows, X.n_cols, X.memptr()});
68 }
69
70 if(0 == info) bcast_from_root(X);
71 else suanpan_error("Error code {} received.\n", info);
72
73 return info;
74}
75#pragma GCC diagnostic pop
76
77#endif
78
A SparseMatClusterLIS class that holds matrices.
Definition SparseMatClusterLIS.hpp:36
unique_ptr< MetaMat< T > > make_copy() override
Definition SparseMatClusterLIS.hpp:51
int direct_solve(Mat< T > &X, const Mat< T > &B) override
Definition SparseMatClusterLIS.hpp:46
int direct_solve(Mat< T > &X, Mat< T > &&B) override
Definition SparseMatClusterLIS.hpp:44
A SparseMat class that holds matrices.
Definition SparseMat.hpp:34
Definition csr_form.hpp:25
std::int32_t la_it
Definition MetaMat.hpp:38
void info(const std::string_view format_sv, const T &... args)
Definition suanPan.h:314
auto bcast_from_root(T &&object)
Definition suanPan.h:254
#define suanpan_error(...)
Definition suanPan.h:376