Class to represent a sequential/threaded Hierarchically Semi-Separable matrix. More...
#include <HSSMatrix.hpp>
Public Member Functions | |
HSSMatrix () | |
HSSMatrix (const DenseM_t &A, const opts_t &opts) | |
HSSMatrix (std::size_t m, std::size_t n, const opts_t &opts) | |
HSSMatrix (const structured::ClusterTree &t, const opts_t &opts) | |
HSSMatrix (kernel::Kernel< real_t > &K, const opts_t &opts) | |
HSSMatrix (const HSSMatrix< scalar_t > &other) | |
HSSMatrix< scalar_t > & | operator= (const HSSMatrix< scalar_t > &other) |
HSSMatrix (HSSMatrix< scalar_t > &&other)=default | |
HSSMatrix< scalar_t > & | operator= (HSSMatrix< scalar_t > &&other)=default |
std::unique_ptr< HSSMatrixBase< scalar_t > > | clone () const override |
const HSSMatrix< scalar_t > * | child (int c) const |
HSSMatrix< scalar_t > * | child (int c) |
void | compress (const DenseM_t &A, const opts_t &opts) |
void | compress (const std::function< void(DenseM_t &Rr, DenseM_t &Rc, DenseM_t &Sr, DenseM_t &Sc)> &Amult, const std::function< void(const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DenseM_t &B)> &Aelem, const opts_t &opts) |
void | compress_with_coordinates (const DenseMatrix< real_t > &coords, const std::function< void(const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DenseM_t &B)> &Aelem, const opts_t &opts) |
void | reset () override |
void | factor () override |
void | partial_factor () |
void | solve (DenseM_t &b) const override |
void | forward_solve (WorkSolve< scalar_t > &w, const DenseM_t &b, bool partial) const override |
void | backward_solve (WorkSolve< scalar_t > &w, DenseM_t &x) const override |
DenseM_t | apply (const DenseM_t &b) const |
void | mult (Trans op, const DenseM_t &x, DenseM_t &y) const override |
DenseM_t | applyC (const DenseM_t &b) const |
scalar_t | get (std::size_t i, std::size_t j) const |
DenseM_t | extract (const std::vector< std::size_t > &I, const std::vector< std::size_t > &J) const |
void | extract_add (const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DenseM_t &B) const |
std::size_t | rank () const override |
std::size_t | memory () const override |
std::size_t | nonzeros () const override |
std::size_t | levels () const override |
void | print_info (std::ostream &out=std::cout, std::size_t roff=0, std::size_t coff=0) const override |
DenseM_t | dense () const |
void | shift (scalar_t sigma) override |
void | draw (std::ostream &of, std::size_t rlo=0, std::size_t clo=0) const override |
void | write (const std::string &fname) const |
const HSSFactors< scalar_t > & | ULV () |
Public Member Functions inherited from strumpack::HSS::HSSMatrixBase< scalar_t > | |
HSSMatrixBase (std::size_t m, std::size_t n, bool active) | |
virtual | ~HSSMatrixBase ()=default |
HSSMatrixBase (const HSSMatrixBase< scalar_t > &other) | |
HSSMatrixBase< scalar_t > & | operator= (const HSSMatrixBase< scalar_t > &other) |
HSSMatrixBase (HSSMatrixBase &&h)=default | |
HSSMatrixBase & | operator= (HSSMatrixBase &&h)=default |
virtual std::unique_ptr< HSSMatrixBase< scalar_t > > | clone () const =0 |
std::pair< std::size_t, std::size_t > | dims () const |
std::size_t | rows () const override |
std::size_t | cols () const override |
bool | leaf () const |
virtual std::size_t | factor_nonzeros () const |
const HSSMatrixBase< scalar_t > & | child (int c) const |
HSSMatrixBase< scalar_t > & | child (int c) |
bool | is_compressed () const |
bool | is_untouched () const |
bool | active () const |
virtual std::size_t | levels () const =0 |
virtual void | print_info (std::ostream &out=std::cout, std::size_t roff=0, std::size_t coff=0) const =0 |
void | set_openmp_task_depth (int depth) |
virtual void | shift (scalar_t sigma) override=0 |
virtual void | draw (std::ostream &of, std::size_t rlo, std::size_t clo) const |
virtual void | forward_solve (WorkSolveMPI< scalar_t > &w, const DistM_t &b, bool partial) const |
virtual void | backward_solve (WorkSolveMPI< scalar_t > &w, DistM_t &x) const |
virtual const BLACSGrid * | grid () const |
virtual const BLACSGrid * | grid (const BLACSGrid *local_grid) const |
virtual const BLACSGrid * | grid_local () const |
virtual int | Ptotal () const |
virtual int | Pactive () const |
virtual void | to_block_row (const DistM_t &A, DenseM_t &sub_A, DistM_t &leaf_A) const |
virtual void | allocate_block_row (int d, DenseM_t &sub_A, DistM_t &leaf_A) const |
virtual void | from_block_row (DistM_t &A, const DenseM_t &sub_A, const DistM_t &leaf_A, const BLACSGrid *lg) const |
Public Member Functions inherited from strumpack::structured::StructuredMatrix< scalar_t > | |
virtual | ~StructuredMatrix ()=default |
virtual std::size_t | rows () const =0 |
virtual std::size_t | cols () const =0 |
virtual std::size_t | memory () const =0 |
virtual std::size_t | nonzeros () const =0 |
virtual std::size_t | rank () const =0 |
virtual std::size_t | local_rows () const |
virtual std::size_t | begin_row () const |
virtual std::size_t | end_row () const |
virtual const std::vector< int > & | dist () const |
virtual const std::vector< int > & | rdist () const |
virtual const std::vector< int > & | cdist () const |
virtual void | mult (Trans op, const DenseMatrix< scalar_t > &x, DenseMatrix< scalar_t > &y) const |
void | mult (Trans op, int m, const scalar_t *x, int ldx, scalar_t *y, int ldy) const |
virtual void | mult (Trans op, const DistributedMatrix< scalar_t > &x, DistributedMatrix< scalar_t > &y) const |
virtual void | factor () |
virtual void | solve (DenseMatrix< scalar_t > &b) const |
virtual void | solve (int nrhs, scalar_t *b, int ldb) const |
virtual void | solve (DistributedMatrix< scalar_t > &b) const |
virtual void | shift (scalar_t s) |
Static Public Member Functions | |
static HSSMatrix< scalar_t > | read (const std::string &fname) |
Friends | |
class | HSSMatrixMPI< scalar_t > |
template<typename T > | |
void | apply_HSS (Trans ta, const HSSMatrix< T > &a, const DenseMatrix< T > &b, T beta, DenseMatrix< T > &c) |
template<typename T > | |
void | draw (const HSSMatrix< T > &H, const std::string &name) |
Class to represent a sequential/threaded Hierarchically Semi-Separable matrix.
This is for non-symmetric matrices, but can be used with symmetric matrices as well. This class inherits from HSSMatrixBase. An HSS matrix is represented recursively, using 2 children which are also HSSMatrix objects, except at the lowest level (the leafs), where the HSSMatrix has no children. Hence, the tree representing the HSS matrix is always a binary tree, but not necessarily a complete binary tree.
scalar_t | Can be float, double, std:complex<float> or std::complex<double>. |
strumpack::HSS::HSSMatrix< scalar_t >::HSSMatrix | ( | ) |
Default constructor, constructs an empty 0 x 0 matrix.
strumpack::HSS::HSSMatrix< scalar_t >::HSSMatrix | ( | const DenseM_t & | A, |
const opts_t & | opts | ||
) |
Construct an HSS representation for a dense matrix A. The HSS tree will be constructed by splitting the row/column set evenly and recursively until the leafs in the HSS tree are smaller than opts.leaf_size(). Alternative constructors can be used to specify a specific HSS partitioning tree. Internally, this will call the appropriate compress routine to construct the HSS representation, using the options (such as compression tolerance, adaptive compression scheme etc) as specified in the HSSOptions opts object.
A | dense matrix (unmodified) to compress as HSS |
opts | object containing a number of options for HSS compression |
strumpack::HSS::HSSMatrix< scalar_t >::HSSMatrix | ( | std::size_t | m, |
std::size_t | n, | ||
const opts_t & | opts | ||
) |
Construct an HSS representation for an m x n matrix. The HSS tree will be constructed by splitting the row/column set evenly and recursively until the leafs in the HSS tree are smaller than opts.leaf_size(). After construction, the HSS matrix will be empty, and can be filled by calling one of the compress member routines. Alternative constructors can be used to specify a specific HSS partitioning tree.
m | number of rows in the constructed HSS matrix |
n | number of rows in the constructed HSS matrix |
opts | object containing a number of options for HSS compression |
strumpack::HSS::HSSMatrix< scalar_t >::HSSMatrix | ( | const structured::ClusterTree & | t, |
const opts_t & | opts | ||
) |
Construct an HSS matrix using a specified HSS tree. After construction, the HSS matrix will be empty, and can be filled by calling one of the compress member routines.
t | tree specifying the HSS matrix partitioning |
opts | object containing a number of options for HSS compression |
strumpack::HSS::HSSMatrix< scalar_t >::HSSMatrix | ( | kernel::Kernel< real_t > & | K, |
const opts_t & | opts | ||
) |
Construct an HSS approximation for the kernel matrix K.
K | Kernel matrix object. The data associated with this kernel will be permuted according to the clustering algorithm selected by the HSSOptions objects. The permutation will be stored in the kernel object. |
opts | object containing a number of HSS options |
strumpack::HSS::HSSMatrix< scalar_t >::HSSMatrix | ( | const HSSMatrix< scalar_t > & | other | ) |
|
default |
Move constructor.
other | HSS matrix to be moved from, will be emptied |
DenseM_t strumpack::HSS::HSSMatrix< scalar_t >::apply | ( | const DenseM_t & | b | ) | const |
Multiply this HSS matrix with a dense matrix (vector), ie, compute x = this * b.
b | Matrix to multiply with, from the left. |
DenseM_t strumpack::HSS::HSSMatrix< scalar_t >::applyC | ( | const DenseM_t & | b | ) | const |
Multiply the transpose or complex conjugate of this HSS matrix with a dense matrix (vector), ie, compute x = this^C * b.
b | Matrix to multiply with, from the left. |
|
overridevirtual |
Perform only the backward phase of the ULV linear solve. This is for advanced use only, typically to be used in combination with partial_factor. You should really just use factor/solve when possible.
w | temporary working storage, to pass information from forward_solve to backward_solve |
b | on input, the vector obtained from forward_solve, on output the solution of A x = b (with A this HSS matrix). The vector b should be b.rows() == cols(). |
Reimplemented from strumpack::HSS::HSSMatrixBase< scalar_t >.
|
inline |
|
inline |
|
overridevirtual |
Create a clone of this matrix. TODO remove this!!???
Implements strumpack::HSS::HSSMatrixBase< scalar_t >.
void strumpack::HSS::HSSMatrix< scalar_t >::compress | ( | const DenseM_t & | A, |
const opts_t & | opts | ||
) |
Initialize this HSS matrix as the compressed HSS representation of a given dense matrix. The HSS matrix should have been constructed with the proper sizes, i.e., rows() == A.rows() and cols() == A.cols(). Internaly, this will call the appropriate compress routine to construct the HSS representation, using the options (such as compression tolerance, adaptive compression scheme etc) as specified in the HSSOptions opts object.
A | dense matrix (unmodified) to compress as HSS |
opts | object containing a number of options for HSS compression |
void strumpack::HSS::HSSMatrix< scalar_t >::compress | ( | const std::function< void(DenseM_t &Rr, DenseM_t &Rc, DenseM_t &Sr, DenseM_t &Sc)> & | Amult, |
const std::function< void(const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DenseM_t &B)> & | Aelem, | ||
const opts_t & | opts | ||
) |
Initialize this HSS matrix as the compressed HSS representation. The compression uses the matrix-(multiple)vector multiplication routine Amult, and the element (sub-matrix) extraction routine Aelem, both provided by the user. The HSS matrix should have been constructed with the proper sizes, i.e., rows() == A.rows() and cols() == A.cols(). Internaly, this will call the appropriate compress routine to construct the HSS representation, using the options (such as compression tolerance, adaptive compression scheme etc) as specified in the HSSOptions opts object.
Amult | matrix-(multiple)vector product routine. This can be a functor, or a lambda function for instance. |
Rr | Parameter to the matvec routine. Random matrix. This will be set by the compression routine. |
Rc | Parameter to the matvec routine. Random matrix. This will be set by the compression routine. |
Sr | Parameter to the matvec routine. Random sample matrix, to be computed by the matrix-(multiple)vector multiplication routine as A*Rr. This will aready be allocated by the compression routine and should be Sr.rows() == this->rows() and Sr.cols() == Rr.cols(). |
Sc | random sample matrix, to be computed by the matrix-(multiple)vector multiplication routine as A^T*Rc, or A^C*Rc. This will aready be allocated by the compression routine and should be Sc.rows() == this->cols() and Sc.cols() == Rc.cols(). |
Aelem | element extraction routine. This can be a functor, or a lambda function for instance. |
I | Parameter in the element extraction routine. Set of row indices of elements to extract. |
J | Parameter in the element extraction routine. Set of column indices of elements to extract. |
B | Parameter in the element extraction routine. Matrix where to place extracted elements. This matrix will already be allocated. It will have B.rows() == I.size() and B.cols() == J.size(). |
opts | object containing a number of options for HSS compression |
void strumpack::HSS::HSSMatrix< scalar_t >::compress_with_coordinates | ( | const DenseMatrix< real_t > & | coords, |
const std::function< void(const std::vector< std::size_t > &I, const std::vector< std::size_t > &J, DenseM_t &B)> & | Aelem, | ||
const opts_t & | opts | ||
) |
Initialize this HSS matrix as the compressed HSS representation. The compression uses nearest neighbor information (coordinates provided by the user). The HSS matrix should have been constructed with the proper sizes, i.e., rows() == A.rows() and cols() == A.cols().
coords | matrix with coordinates for the underlying geometry that defined the HSS matrix. This should be a d x n matrix (d rows, n columns), where d is the dimension of the coordinates and n is rows() and cols() of this matrix. |
Aelem | element extraction routine. This can be a functor, or a lambda function for instance. |
I | Parameter in the element extraction routine. Set of row indices of elements to extract. |
J | Parameter in the element extraction routine. Set of column indices of elements to extract. |
B | Parameter in the element extraction routine. Matrix where to place extracted elements. This matrix will already be allocated. It will have B.rows() == I.size() and B.cols() == J.size(). |
opts | object containing a number of options for HSS compression |
DenseM_t strumpack::HSS::HSSMatrix< scalar_t >::dense | ( | ) | const |
Return a full/dense representation of this HSS matrix.
|
overridevirtual |
Internal routine to draw this HSS matrix. Do not use this directly. Use HSS::draw.
Reimplemented from strumpack::HSS::HSSMatrixBase< scalar_t >.
DenseM_t strumpack::HSS::HSSMatrix< scalar_t >::extract | ( | const std::vector< std::size_t > & | I, |
const std::vector< std::size_t > & | J | ||
) | const |
void strumpack::HSS::HSSMatrix< scalar_t >::extract_add | ( | const std::vector< std::size_t > & | I, |
const std::vector< std::size_t > & | J, | ||
DenseM_t & | B | ||
) | const |
Compute a submatrix this(I,J) from this HSS matrix and add it to a given matrix B.
|
overridevirtual |
Compute a ULV factorization of this matrix.
Reimplemented from strumpack::structured::StructuredMatrix< scalar_t >.
|
overridevirtual |
Perform only the forward phase of the ULV linear solve. This is for advanced use only, typically to be used in combination with partial_factor. You should really just use factor/solve when possible.
w | temporary working storage, to pass information from forward_solve to backward_solve |
b | on input, the right hand side vector, on output the intermediate solution. The vector b should be b.rows() == cols(). |
partial | denotes wether the matrix was fully or partially factored |
Reimplemented from strumpack::HSS::HSSMatrixBase< scalar_t >.
scalar_t strumpack::HSS::HSSMatrix< scalar_t >::get | ( | std::size_t | i, |
std::size_t | j | ||
) | const |
|
overridevirtual |
Return the number of levels in the HSS matrix.
Implements strumpack::HSS::HSSMatrixBase< scalar_t >.
|
overridevirtual |
Return the total amount of memory used by this matrix, in bytes.
Implements strumpack::structured::StructuredMatrix< scalar_t >.
|
overridevirtual |
Multiply this HSS matrix with a dense matrix (vector), ie, compute y = op(this) * x. Overrides from the StructuredMatrix class method.
op | Transpose or complex conjugate |
x | right hand side matrix to multiply with, from the left, rows(x) == cols(op(this)) |
y | result of op(this) * b, cols(y) == cols(x), rows(r) = rows(op(this)) |
Reimplemented from strumpack::structured::StructuredMatrix< scalar_t >.
|
overridevirtual |
Return the total number of nonzeros stored by this matrix.
Implements strumpack::structured::StructuredMatrix< scalar_t >.
HSSMatrix< scalar_t > & strumpack::HSS::HSSMatrix< scalar_t >::operator= | ( | const HSSMatrix< scalar_t > & | other | ) |
|
default |
Move assignment operator.
other | HSS matrix to be moved from, will be emptied |
void strumpack::HSS::HSSMatrix< scalar_t >::partial_factor | ( | ) |
Compute a partial ULV factorization of this matrix. Only the left child is factored. This is not similar to calling child(0)->factor(), except that the HSSFactors resulting from calling partial_factor can be used to compute the Schur complement.
|
overridevirtual |
Print info about this HSS matrix, such as tree info, ranks, etc.
out | Stream to print to, defaults to std::cout |
roff | Row offset of top left corner, defaults to 0. This is used to recursively print the tree, you can leave this at the default. |
coff | Column offset of top left corner, defaults to 0. This is used to recursively print the tree, you can leave this at the default. |
Implements strumpack::HSS::HSSMatrixBase< scalar_t >.
|
overridevirtual |
Return the maximum rank of this matrix over all low-rank compressed blocks.
Implements strumpack::structured::StructuredMatrix< scalar_t >.
|
static |
Read an HSSMatrix<scalar_t> from a binary file, called fname.
|
override |
Reset the matrix to an empty, 0 x 0 matrix, freeing up all it's memory.
|
overridevirtual |
Apply a shift to the diagonal of this matrix. Ie, this += sigma * I, with I the identity matrix. Call this after compression.
sigma | Shift to be applied to the diagonal. |
Implements strumpack::HSS::HSSMatrixBase< scalar_t >.
|
overridevirtual |
Solve a linear system with the ULV factorization of this HSSMatrix. The right hand side vector (or matrix) b is overwritten with the solution x of Ax=b.
ULV | ULV factorization of this matrix |
b | on input, the right hand side vector, on output the solution of A x = b (with A this HSS matrix). The vector b should be b.rows() == cols(). |
Reimplemented from strumpack::structured::StructuredMatrix< scalar_t >.
void strumpack::HSS::HSSMatrix< scalar_t >::write | ( | const std::string & | fname | ) | const |
Write this HSSMatrix<scalar_t> to a binary file, called fname.
|
friend |
|
friend |