30#ifndef SPARSEMATSUPERLU_HPP
31#define SPARSEMATSUPERLU_HPP
33#include "../SparseMat.hpp"
34#include "../csc_form.hpp"
36#include <superlu-mt/superlu-mt.h>
39 SuperMatrix A{}, L{}, U{}, B{};
41#ifndef SUANPAN_SUPERLUMT
42 superlu_options_t options{};
46 const int ordering_num = 1;
52 std::vector<int> t_row, t_col, perm_r, perm_c;
54 bool allocated =
false;
61 template<sp_d ET>
void wrap_b(
const Mat<ET>&);
62 template<sp_d ET>
void tri_solve(
int&);
63 template<sp_d ET>
void full_solve(
int&);
65 int solve_trs(Mat<T>&, Mat<T>&&);
84#ifndef SUANPAN_SUPERLUMT
85 set_default_options(&options);
86 options.IterRefine = std::is_same_v<T, float> ? superlu::IterRefine_t::SLU_SINGLE : superlu::IterRefine_t::SLU_DOUBLE;
87 options.Equil = superlu::yes_no_t::NO;
99 t_row = std::vector<int>(in.row_mem(), in.row_mem() + in.n_elem);
100 t_col = std::vector<int>(in.col_mem(), in.col_mem() + in.n_cols + 1);
101 t_val = std::vector<ET>(in.val_mem(), in.val_mem() + in.n_elem);
103 if constexpr(std::is_same_v<ET, double>) {
105 dCreate_CompCol_Matrix(&A, in.n_rows, in.n_cols, in.n_elem, (
E*)t_val.data(), t_row.data(), t_col.data(), Stype_t::SLU_NC, Dtype_t::SLU_D, Mtype_t::SLU_GE);
109 sCreate_CompCol_Matrix(&A, in.n_rows, in.n_cols, in.n_elem, (
E*)t_val.data(), t_row.data(), t_col.data(), Stype_t::SLU_NC, Dtype_t::SLU_S, Mtype_t::SLU_GE);
112 perm_r = std::vector<int>(this->
n_rows + 1);
113 perm_c = std::vector<int>(this->
n_cols + 1);
119 if(!allocated)
return;
121 Destroy_SuperMatrix_Store(&A);
122#ifdef SUANPAN_SUPERLUMT
123 Destroy_SuperNode_SCP(&L);
124 Destroy_CompCol_NCP(&U);
126 Destroy_SuperNode_Matrix(&L);
127 Destroy_CompCol_Matrix(&U);
134 if constexpr(std::is_same_v<ET, float>) {
136 sCreate_Dense_Matrix(&B, (
int)in_mat.n_rows, (
int)in_mat.n_cols, (
E*)in_mat.memptr(), (
int)in_mat.n_rows, Stype_t::SLU_DN, Dtype_t::SLU_S, Mtype_t::SLU_GE);
140 dCreate_Dense_Matrix(&B, (
int)in_mat.n_rows, (
int)in_mat.n_cols, (
E*)in_mat.memptr(), (
int)in_mat.n_rows, Stype_t::SLU_DN, Dtype_t::SLU_D, Mtype_t::SLU_GE);
145#ifdef SUANPAN_SUPERLUMT
146 if(std::is_same_v<ET, float>) sgstrs(NOTRANS, &L, &U, perm_c.data(), perm_r.data(), &B, &stat, &flag);
147 else dgstrs(NOTRANS, &L, &U, perm_c.data(), perm_r.data(), &B, &stat, &flag);
149 superlu::gstrs<ET>(options.Trans, &L, &U, perm_c.data(), perm_r.data(), &B, &stat, &flag);
152 Destroy_SuperMatrix_Store(&B);
156#ifdef SUANPAN_SUPERLUMT
157 get_perm_c(ordering_num, &A, perm_c.data());
158 if(std::is_same_v<ET, float>) psgssv(
SUANPAN_NUM_THREADS, &A, perm_c.data(), perm_r.data(), &L, &U, &B, &flag);
161 superlu::gssv<ET>(&options, &A, perm_c.data(), perm_r.data(), &L, &U, &B, &stat, &flag);
164 Destroy_SuperMatrix_Store(&B);
168 :
SparseMat<
T>(in_row, in_col, in_elem) { init_config(); }
184 if(this->factored)
return solve_trs(out_mat, std::move(in_mat));
186 this->factored =
true;
196 out_mat = std::move(in_mat);
208 out_mat = std::move(in_mat);
A SparseMat class that holds matrices.
Definition SparseMat.hpp:34
A SparseMatSuperLU class that holds matrices.
Definition SparseMatSuperLU.hpp:38
SparseMatSuperLU(SparseMatSuperLU &&) noexcept=delete
int direct_solve(Mat< T > &out_mat, const Mat< T > &in_mat) override
Definition SparseMatSuperLU.hpp:68
int SUANPAN_NUM_THREADS
Definition command.cpp:70