CLA3P v0.3.1
Compact Linear Algebra Parallel Portable Package
Loading...
Searching...
No Matches
ex07b_solving_sparse_linear_systems_llt.cpp
#include <iostream>
#include <cla3p/dense.hpp>
#include <cla3p/sparse.hpp>
#include <cla3p/linsol.hpp>
#include <cla3p/algebra.hpp>
/*-----------------------------------------------------*/
static cla3p::csr::RdMatrix DefaultSymmetricSparseMatrix()
{
static cla3p::int_t rowptr[] = {0, 3, 5, 7, 8, 9};
static cla3p::int_t colidx[] = { 0, 1, 3, 1, 4, 2, 3, 3, 4};
static cla3p::real_t values[] = {10, -2, -4, 50, 8, 40, 2, 70, 50};
return cla3p::csr::RdMatrix(5, 5, rowptr, colidx, values, false, cla3p::Property::SymmetricUpper());
}
/*-----------------------------------------------------*/
int main()
{
const cla3p::csr::RdMatrix A = DefaultSymmetricSparseMatrix();
cla3p::dns::RdVector x; // x will be created in solve
cla3p::dns::RdMatrix X(5, 3); // Preallocate space for X
/*
* Perform analysis & symbolic decomposition on A.
*/
lltSolver.analysis(A);
/*
* Decompose A into LL' product.
*/
lltSolver.decompose(A);
{
/*
* Single column (vector) rhs.
* Calculate x = (A^{-1} * b).
*/
lltSolver.solve(b, x);
std::cout << "Dense Vector rhs::Absolute Error: "
<< (b - A * x).evaluate().normOne() << std::endl;
}
{
/*
* Multiple column (matrix) rhs.
* Calculate X = (A^{-1} * B).
*/
lltSolver.solve(B, X);
std::cout << "Dense Matrix rhs::Absolute Error: "
<< (B - A * X).evaluate().normOne() << std::endl;
}
return 0;
}
void decompose(const T_Matrix &mat)
Performs matrix decomposition.
void analysis(const T_Matrix &mat)
Performs matrix analysis & symbolic decomposition.
void solve(const dns::XxMatrix< T_Scalar > &rhs, dns::XxMatrix< T_Scalar > &sol)
Performs matrix solution.
The definite Cholesky (LL') linear solver for sparse matrices.
Definition pardiso_llt.hpp:35
static Property SymmetricUpper()
Factory method for upper-triangular symmetric property.
static XxMatrix< real_t > random(int_t nr, int_t nc, const Property &pr=Property::General(), T_RScalar lo=T_RScalar(0), T_RScalar hi=T_RScalar(1))
static XxVector< real_t > random(int_t n, T_RScalar lo=T_RScalar(0), T_RScalar hi=T_RScalar(1))
double real_t
Double precision real.
Definition scalar.hpp:44
XxMatrix< real_t > RdMatrix
Double precision real matrix.
Definition dense.hpp:55
XxMatrix< int_t, real_t > RdMatrix
Double precision real CSR (Compressed Sparse Row) matrix.
Definition sparse.hpp:35
XxVector< real_t > RdVector
Double precision real vector.
Definition dense.hpp:31