67 IT n{-1}, kl{-1}, ku{-1}, max_klu{-1}, lead{-1}, block{-1}, lines{-1};
69 std::vector<DT> a, b, work;
85 auto init_storage(
const IT n,
const IT kl,
const IT ku) {
89 loc.max_klu = std::max(loc.kl, loc.ku);
90 loc.lead = loc.kl + loc.ku + 1;
91 loc.block = std::max(loc.n / std::max(IT{1}, this->ctx.n_rows - 1) + 1, std::max(2 * loc.max_klu, this->ctx.row_block(loc.n)));
92 loc.block = std::min(loc.block, loc.n);
93 loc.lines = this->ctx.rows(loc.n, loc.block);
94 loc.desc1d_a = {501, this->trans_ctx.context, loc.n, loc.block, 0, loc.lead, 0, 0, 0};
96 loc.a.resize(loc.lead * loc.lines);
99 using base_t::to_band;
100 using base_t::to_full;
103 explicit pdbsv(
const IT rows = get_env<IT>().size())
115 indexer(
const IT N,
const IT KL,
const IT KU)
120 auto operator()(
const IT i,
const IT j)
const {
121 if(i < 0 || i >= n || j < 0 || j >= n)
return IT{-1};
122 if(i - j > kl || j - i > ku)
return IT{-1};
123 return ku + i + j * (kl + ku);
127 template<band_container_t AT, full_container_t BT> IT solve(AT&& A, BT&& B) {
return solve(to_band(A), to_full(B)); }
130 if(!this->ctx.is_valid() || !this->trans_ctx.is_valid())
return 0;
132 if(A.n_rows != A.n_cols || A.n_rows != B.n_rows)
return -1;
134 init_storage(A.n_cols, A.kl, A.ku);
138 this->trans_ctx.scatter(
140 this->trans_ctx.desc_g(loc.lead, loc.n),
142 this->trans_ctx.desc_l(loc.lead, loc.n, loc.lead, loc.block, loc.lead)
145 const IT laf = loc.block * (loc.kl + loc.ku) + 6 * std::pow(loc.max_klu, 2);
146 const IT lwork = loc.max_klu * std::max(2 * B.n_cols - 1, loc.max_klu);
147 loc.work.resize(laf + lwork);
151 if constexpr(std::is_same_v<DT, double>) {
153 pddbtrf(&loc.n, &loc.kl, &loc.ku, (E*)loc.a.data(), &this->ONE, loc.desc1d_a.data(), (E*)loc.work.data(), &laf, (E*)(loc.work.data() + laf), &lwork, &info);
155 else if constexpr(std::is_same_v<DT, float>) {
157 psdbtrf(&loc.n, &loc.kl, &loc.ku, (E*)loc.a.data(), &this->ONE, loc.desc1d_a.data(), (E*)loc.work.data(), &laf, (E*)(loc.work.data() + laf), &lwork, &info);
159 else if constexpr(std::is_same_v<DT, complex16>) {
161 pzdbtrf(&loc.n, &loc.kl, &loc.ku, (E*)loc.a.data(), &this->ONE, loc.desc1d_a.data(), (E*)loc.work.data(), &laf, (E*)(loc.work.data() + laf), &lwork, &info);
163 else if constexpr(std::is_same_v<DT, complex8>) {
165 pcdbtrf(&loc.n, &loc.kl, &loc.ku, (E*)loc.a.data(), &this->ONE, loc.desc1d_a.data(), (E*)loc.work.data(), &laf, (E*)(loc.work.data() + laf), &lwork, &info);
169 if((info = this->trans_ctx.amx(info)) != 0)
return info;
171 return solve(std::move(B));
174 IT solve(full_mat<DT, IT>&& B) {
175 static constexpr char TRANS =
'N';
177 if(B.n_rows != loc.n)
return -1;
179 if(!this->ctx.is_valid() || !this->trans_ctx.is_valid())
return 0;
181 const auto lead_b = std::max(loc.block, loc.lines);
183 loc.b.resize(lead_b * B.n_cols);
185 const auto full_desc_b = this->ctx.desc_g(B.n_rows, B.n_cols);
186 const auto local_desc_b = this->ctx.desc_l(B.n_rows, B.n_cols, loc.block, B.n_cols, lead_b);
188 this->ctx.scatter(B, full_desc_b, loc.b, local_desc_b);
190 const IT laf = loc.block * (loc.kl + loc.ku) + 6 * std::pow(loc.max_klu, 2);
191 const IT lwork = loc.max_klu * std::max(2 * B.n_cols - 1, loc.max_klu);
192 loc.work.resize(laf + lwork);
194 desc<IT> desc1d_b{502, this->trans_ctx.context, loc.n, loc.block, 0, lead_b, 0, 0, 0};
198 if constexpr(std::is_same_v<DT, double>) {
200 pddbtrs(&TRANS, &loc.n, &loc.kl, &loc.ku, &B.n_cols, (E*)loc.a.data(), &this->ONE, loc.desc1d_a.data(), (E*)loc.b.data(), &this->ONE, desc1d_b.data(), (E*)loc.work.data(), &laf, (E*)(loc.work.data() + laf), &lwork, &info);
202 else if constexpr(std::is_same_v<DT, float>) {
204 psdbtrs(&TRANS, &loc.n, &loc.kl, &loc.ku, &B.n_cols, (E*)loc.a.data(), &this->ONE, loc.desc1d_a.data(), (E*)loc.b.data(), &this->ONE, desc1d_b.data(), (E*)loc.work.data(), &laf, (E*)(loc.work.data() + laf), &lwork, &info);
206 else if constexpr(std::is_same_v<DT, complex16>) {
208 pzdbtrs(&TRANS, &loc.n, &loc.kl, &loc.ku, &B.n_cols, (E*)loc.a.data(), &this->ONE, loc.desc1d_a.data(), (E*)loc.b.data(), &this->ONE, desc1d_b.data(), (E*)loc.work.data(), &laf, (E*)(loc.work.data() + laf), &lwork, &info);
210 else if constexpr(std::is_same_v<DT, complex8>) {
212 pcdbtrs(&TRANS, &loc.n, &loc.kl, &loc.ku, &B.n_cols, (E*)loc.a.data(), &this->ONE, loc.desc1d_a.data(), (E*)loc.b.data(), &this->ONE, desc1d_b.data(), (E*)loc.work.data(), &laf, (E*)(loc.work.data() + laf), &lwork, &info);
216 if((info = this->trans_ctx.amx(info)) == 0) this->ctx.gather(loc.b, local_desc_b, B, full_desc_b);