64 #include "abstract/band_solver.hpp"
71 IT n{-1}, kl{-1}, ku{-1}, max_klu{-1}, lead{-1}, block{-1}, lines{-1};
73 std::vector<DT> a, b, work;
89 auto init_storage(
const IT n,
const IT kl,
const IT ku) {
93 loc.max_klu = std::max(loc.kl, loc.ku);
94 loc.lead = loc.kl + loc.ku + 1;
95 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)));
96 loc.block = std::min(loc.block, loc.n);
97 loc.lines = this->ctx.rows(loc.n, loc.block);
98 loc.desc1d_a = {501, this->trans_ctx.context, loc.n, loc.block, 0, loc.lead, 0, 0, 0};
100 loc.a.resize(loc.lead * loc.lines);
103 using base_t::to_band;
104 using base_t::to_full;
107 explicit pdbsv(
const IT rows = get_env<IT>().size())
119 indexer(
const IT N,
const IT KL,
const IT KU)
124 auto operator()(
const IT i,
const IT j)
const {
125 if(i < 0 || i >= n || j < 0 || j >= n)
return IT{-1};
126 if(i - j > kl || j - i > ku)
return IT{-1};
127 return ku + i + j * (kl + ku);
131 template<band_container_t AT, full_container_t BT> IT solve(AT&& A, BT&& B) {
return solve(to_band(std::forward<AT>(A)), to_full(std::forward<BT>(B))); }
132 template<band_container_t AT> IT solve(AT&& A,
full_mat<DT, IT>&& B) {
return solve(to_band(std::forward<AT>(A)), to_full(std::move(B))); }
134 IT solve(band_mat<DT, IT>&& A, full_mat<DT, IT>&& B)
override {
135 if(!this->ctx.is_valid() || !this->trans_ctx.is_valid())
return 0;
137 if(A.n_rows != A.n_cols || A.n_cols != B.n_rows)
return -1;
139 init_storage(A.n_cols, A.kl, A.ku);
143 this->trans_ctx.scatter(
144 full_mat<DT, IT>(loc.lead, loc.n, A.data, A.distributed),
145 this->trans_ctx.desc_g(loc.lead, loc.n),
147 this->trans_ctx.desc_l(loc.lead, loc.n, loc.lead, loc.block, loc.lead)
150 const IT laf = loc.block * (loc.kl + loc.ku) + 6 * loc.max_klu * loc.max_klu;
151 const IT lwork = loc.max_klu * std::max(2 * B.n_cols - 1, loc.max_klu);
152 loc.work.resize(laf + lwork);
156 if constexpr(std::is_same_v<DT, double>) {
158 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);
160 else if constexpr(std::is_same_v<DT, float>) {
162 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);
164 else if constexpr(std::is_same_v<DT, complex16>) {
166 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);
168 else if constexpr(std::is_same_v<DT, complex8>) {
170 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);
174 if((info = this->trans_ctx.amx(info)) != 0)
return info;
176 return solve(std::move(B));
179 IT solve(full_mat<DT, IT>&& B)
override {
180 static constexpr
char TRANS =
'N';
182 if(B.n_rows != loc.n)
return -1;
184 if(!this->ctx.is_valid() || !this->trans_ctx.is_valid())
return 0;
186 const auto lead_b = std::max(loc.block, loc.lines);
188 loc.b.resize(lead_b * B.n_cols);
190 const auto full_desc_b = this->ctx.desc_g(B.n_rows, B.n_cols);
191 const auto local_desc_b = this->ctx.desc_l(B.n_rows, B.n_cols, loc.block, B.n_cols, lead_b);
193 this->ctx.scatter(B, full_desc_b, loc.b, local_desc_b);
195 const IT laf = loc.block * (loc.kl + loc.ku) + 6 * loc.max_klu * loc.max_klu;
196 const IT lwork = loc.max_klu * std::max(2 * B.n_cols - 1, loc.max_klu);
197 loc.work.resize(laf + lwork);
199 desc<IT> desc1d_b{502, this->trans_ctx.context, loc.n, loc.block, 0, lead_b, 0, 0, 0};
203 if constexpr(std::is_same_v<DT, double>) {
205 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);
207 else if constexpr(std::is_same_v<DT, float>) {
209 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);
211 else if constexpr(std::is_same_v<DT, complex16>) {
213 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);
215 else if constexpr(std::is_same_v<DT, complex8>) {
217 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);
221 if((info = this->trans_ctx.amx(info)) == 0) this->ctx.gather(loc.b, local_desc_b, B, full_desc_b);
Definition: band_solver.hpp:24
Definition: pdbsv.hpp:110
Solver for general band matrices.
Definition: traits.hpp:89
Definition: traits.hpp:85