33#ifndef SUANPAN_SUPERLUMT
35#include <superlu-mt/superlu-mt.h>
41 inline static char equed =
'N';
43 SuperMatrix A{}, L{}, U{};
46 GlobalLU_t global_setting{};
47 superlu_options_t options{};
50 void* t_val =
nullptr;
54 int* perm_r =
nullptr;
55 int* perm_c =
nullptr;
57 void* scale_r =
nullptr;
58 void* scale_c =
nullptr;
62 static void wrap_b(SuperMatrix*,
const Col<data_t>&);
64 int apply_solver(SuperMatrix*, SuperMatrix*);
66 void apply_row_scale(Col<data_t>&);
67 void apply_column_scale(Col<data_t>&);
79 [[nodiscard]] Col<data_t>
apply(
const Col<data_t>&)
override;
83 if(std::is_same_v<data_t, float>) {
85 sCreate_Dense_Matrix(out, (
int)in.n_rows, (
int)in.n_cols, (E*)in.memptr(), (
int)in.n_rows, Stype_t::SLU_DN, Dtype_t::SLU_S, Mtype_t::SLU_GE);
89 dCreate_Dense_Matrix(out, (
int)in.n_rows, (
int)in.n_cols, (E*)in.memptr(), (
int)in.n_rows, Stype_t::SLU_DN, Dtype_t::SLU_D, Mtype_t::SLU_GE);
96 if(std::is_same_v<data_t, float>) {
98 sgsisx(&options, &A, perm_c, perm_r, etree, &equed, (E*)scale_r, (E*)scale_c, &L, &U,
nullptr, 0, B, X,
nullptr,
nullptr, &global_setting, &usage, &stat, &
info);
102 dgsisx(&options, &A, perm_c, perm_r, etree, &equed, (E*)scale_r, (E*)scale_c, &L, &U,
nullptr, 0, B, X,
nullptr,
nullptr, &global_setting, &usage, &stat, &
info);
115 auto t_size =
sizeof(data_t) * csc_mat.n_elem;
116 t_val = superlu_malloc(t_size);
117 std::memcpy(t_val, (
void*)csc_mat.val_mem(), t_size);
119 t_size =
sizeof(int) * csc_mat.n_elem;
120 t_row = (
int*)superlu_malloc(t_size);
121 std::memcpy(t_row, (
void*)csc_mat.row_mem(), t_size);
123 t_size =
sizeof(int) * (csc_mat.n_cols + 1llu);
124 t_col = (
int*)superlu_malloc(t_size);
125 std::memcpy(t_col, (
void*)csc_mat.col_mem(), t_size);
127 if(std::is_same_v<data_t, float>) {
129 sCreate_CompCol_Matrix(&A, csc_mat.n_rows, csc_mat.n_cols, csc_mat.n_elem, (E*)t_val, t_row, t_col, Stype_t::SLU_NC, Dtype_t::SLU_S, Mtype_t::SLU_GE);
133 dCreate_CompCol_Matrix(&A, csc_mat.n_rows, csc_mat.n_cols, csc_mat.n_elem, (E*)t_val, t_row, t_col, Stype_t::SLU_NC, Dtype_t::SLU_D, Mtype_t::SLU_GE);
136 perm_r = (
int*)superlu_malloc(
sizeof(
int) * (csc_mat.n_rows + 1llu));
137 perm_c = (
int*)superlu_malloc(
sizeof(
int) * (csc_mat.n_cols + 1llu));
138 scale_r = superlu_malloc(
sizeof(data_t) * (csc_mat.n_rows + 1llu));
139 scale_c = superlu_malloc(
sizeof(data_t) * (csc_mat.n_cols + 1llu));
141 etree = (
int*)superlu_malloc(
sizeof(
int) * (csc_mat.n_cols + 1llu));
143 ilu_set_default_options(&options);
155 Destroy_SuperMatrix_Store(&
A);
156 Destroy_SuperNode_Matrix(&L);
157 Destroy_CompCol_Matrix(&
U);
159 if(t_val) superlu_free(t_val);
160 if(t_row) superlu_free(t_row);
161 if(t_col) superlu_free(t_col);
162 if(etree) superlu_free(etree);
163 if(perm_r) superlu_free(perm_r);
164 if(perm_c) superlu_free(perm_c);
165 if(scale_r) superlu_free(scale_r);
166 if(scale_c) superlu_free(scale_c);
170 Col<data_t> in(
A.ncol, 1, fill::none);
171 Col<data_t> out(
A.nrow, 1, fill::none);
174 this->wrap_b(&X, out);
175 this->wrap_b(&B, in);
179 if(
const auto code = this->apply_solver(&X, &B); 0 != code) {
184 Destroy_SuperMatrix_Store(&X);
185 Destroy_SuperMatrix_Store(&B);
187 options.Fact = superlu::FACTORED;
193 Col<data_t> out(arma::size(in), fill::none);
196 this->wrap_b(&X, out);
197 this->wrap_b(&B, in);
199 this->apply_solver(&X, &B);
203 Destroy_SuperMatrix_Store(&X);
204 Destroy_SuperMatrix_Store(&B);
A ILU class.
Definition: ILU.hpp:40
A Preconditioner class.
Definition: Preconditioner.hpp:34
Col< data_t > apply(const Col< data_t > &) override
Definition: ILU.hpp:192
ILU(triplet_form< data_t, index_t > &&)
Definition: ILU.hpp:148
int init() override
Definition: ILU.hpp:169
~ILU() override
Definition: ILU.hpp:154
void info(const std::string_view format_str, const T &... args)
Definition: suanPan.h:249
constexpr auto SUANPAN_SUCCESS
Definition: suanPan.h:172
constexpr auto SUANPAN_FAIL
Definition: suanPan.h:173
#define suanpan_error(...)
Definition: suanPan.h:309