Solver for symmetric band positive definite matrices.
- Note
- Although the
ppbsv solver supports KLU=0, a zero (half) bandwidth would lead to unwanted warning message from ScaLAPACK.
-
See: https://github.com/Reference-ScaLAPACK/scalapack/issues/116
It solves the system of linear equations A * X = B with a symmetric band positive definite matrix A. The band matrix A has KLU sub-diagonals. It shall be stored in the following format. The band storage scheme is illustrated by the following example, when M=N=6, KLU=2.
For ‘UPLO='L’`, the lower half is stored.
Solver for general sparse matrices.
The lead dimension should be KLU+1.
With zero based indexing, for a general band matrix A, the element at row i and column j is stored at A[IDX(i, j)].
const auto IDX = [&](
int i,
int j) {
if(
i <
j) std::swap(
i,
j);
if(
i -
j >
KLU)
return -1;
};
For ‘UPLO='U’`, the upper half is stored.
The lead dimension should be KLU+1.
With zero based indexing, for a general band matrix A, the element at row i and column j is stored at A[IDX(i, j)].
const auto IDX = [&](
int i,
int j) {
if(
i >
j) std::swap(
i,
j);
if(
j -
i >
KLU)
return -1;
return 2 *
j -
i + (
j + 1) *
KLU;
};
The example usage can be seen as follows.
#include <iomanip>
#include <iostream>
const auto& env = ezp::get_env<>();
public:
int_t n_rows{}, n_cols{};
private:
std::vector<double> storage;
public:
auto init(const int_t rows, const int cols) {
n_rows = rows;
n_cols = cols;
storage.resize(rows * cols);
}
explicit general_mat(
const int_t rows = 0,
const int cols = 0) { init(rows, cols); }
auto& operator[](
const int_t
i) {
return storage[
i]; }
auto begin() { return storage.begin(); }
auto end() { return storage.end(); }
};
public:
int_t n_rows{}, n_cols{}, klu{};
private:
std::vector<double> storage;
public:
auto init(
const int_t n,
const int bandwidth) {
n_rows = n;
n_cols = n;
if(0 == env.rank()) storage.resize(n * (klu + 1));
indexer = {n, klu};
}
auto& operator()(
const int_t
i,
const int_t
j) {
return storage[indexer(
i,
j)]; }
auto data() { return storage.data(); }
};
int main() {
constexpr auto N = 6, NRHS = 2,
KLU = 1;
if(0 == env.rank()) {
static constexpr auto M = 5.10156648;
for(
auto I = 0;
I < N; ++
I) {
}
}
const auto info = solver.solve(A,
B);
if(0 == env.rank() && 0 == info) {
std::cout << std::setprecision(10) << "Info: " << info << '\n';
std::cout << "Solution:\n";
}
return info;
}
Definition example.ppbsv.cpp:57
Definition example.ppbsv.cpp:34
- Author
- tlc
- Date
- 07/03/2025
- Version
- 1.0.0