RsbMatrix< NT >(3) | librsb | RsbMatrix< NT >(3) |
RsbMatrix - Represent a sparse matrix in RSB format by means of librsb.
#include <rsb.hpp>
enum RsbSym { IsGen = RSB_FLAG_NOFLAGS, IsHer
= RSB_FLAG_HERMITIAN, IsSym = RSB_FLAG_SYMMETRIC, IsTri =
RSB_FLAG_TRIANGULAR }
RsbMatrix (rsb_coo_idx_t nrA, rsb_coo_idx_t
ncA, const RsbSym sym=IsGen)
RsbMatrix (rsb_coo_idx_t nrA, const rsb_coo_idx_t *RP,
const rsb_coo_idx_t *JA, const NT *VA, const RsbSym
sym=IsGen)
RsbMatrix (const rsb_coo_idx_t *IA, const rsb_coo_idx_t
*JA, const NT *VA, rsb_nnz_idx_t nnzA, const rsb_flags_t
flagsA=RSB_FLAG_NOFLAGS)
RsbMatrix (const rsb_char_t *filename, const RsbSym
sym=IsGen)
RsbMatrix (const RsbMatrix &A_Rsb, bool do_trans=false,
rsb_flags_t flagsA=RSB_FLAG_NOFLAGS)
RsbMatrix (RsbMatrix &&other)
~RsbMatrix (void)
RSBP_RVT RSBP_DEPRECATED Err_t _add (rsb_coo_idx_t
i, rsb_coo_idx_t j, NT val)
RSBP_RVT Err_t close (void)
RSBP_RVT RSBP_DEPRECATED Err_t _close (void)
RSBP_RVT RSBP_DEPRECATED Err_t spmv (rsb_trans_t
transA, const NT *alphap, const NT *Xp, rsb_coo_idx_t incX, const NT
*betap, NT *Yp, rsb_coo_idx_t incY) const
RSBP_RVT Err_t spmv (rsb_trans_t transA, const NT alpha,
const NT *Xp, rsb_coo_idx_t incX, const NT beta, NT *Yp,
rsb_coo_idx_t incY) const
RSBP_RVT Err_t spmv (rsb_trans_t transA, const NT alpha,
const NT *Xp, const NT beta, NT *Yp) const
RSBP_RVT Err_t spmv (NT *y, const NT *x, bool do_trans=false)
const
RSBP_RVT RSBP_DEPRECATED Err_t spmm (rsb_trans_t
transA, const NT *alphap, rsb_coo_idx_t nrhs, rsb_flags_t
order, const NT *Bp, rsb_nnz_idx_t ldB, const NT *betap, NT *Cp,
rsb_nnz_idx_t ldC) const
RSBP_RVT Err_t spmm (rsb_trans_t transA, const NT alpha,
rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp,
rsb_nnz_idx_t ldB, const NT beta, NT *Cp, rsb_nnz_idx_t ldC)
const
RSBP_RVT Err_t spmm (rsb_trans_t transA, const NT alpha,
rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp, const NT
beta, NT *Cp) const
RSBP_RVT RSBP_DEPRECATED Err_t spsm (rsb_trans_t
transT, const NT *alphap, rsb_coo_idx_t nrhs, rsb_flags_t
order, const NT *betap, const NT *Bp, rsb_nnz_idx_t ldB, NT *Cp,
rsb_nnz_idx_t ldC) const
RSBP_RVT Err_t spsm (rsb_trans_t transT, const NT alpha,
rsb_coo_idx_t nrhs, rsb_flags_t order, const NT beta, const NT
*Bp, rsb_nnz_idx_t ldB, NT *Cp, rsb_nnz_idx_t ldC) const
RSBP_RVT Err_t spsm (rsb_trans_t transT, const NT alpha,
rsb_coo_idx_t nrhs, const NT *Bp, NT *Cp) const
RSBP_RVT Err_t spsm (NT *y, const NT *x, rsb_coo_idx_t
nrhs, bool do_trans=false) const
RSBP_RVT Err_t spsm (NT *y, rsb_coo_idx_t nrhs, bool
do_trans=false) const
RSBP_RVT RSBP_DEPRECATED Err_t spsv (rsb_trans_t
transT, const NT *alphap, const NT *Xp, rsb_coo_idx_t incX, NT *Yp,
rsb_coo_idx_t incY) const
RSBP_RVT Err_t spsv (rsb_trans_t transT, const NT alpha,
const NT *Xp, NT *Yp) const
RSBP_RVT Err_t spsv (NT *y, const NT *x, bool do_trans=false)
const
RSBP_RVT Err_t spsv (NT *y, bool do_trans=false) const
size_t get_info_size_t (enum rsb_mif_t mif) const
rsb_flags_t get_info_rsb_flags_t (enum rsb_mif_t mif)
const
rsb_blk_idx_t get_info_blk_t (enum rsb_mif_t mif) const
rsb_nnz_idx_t get_info_nnz_t (enum rsb_mif_t mif) const
rsb_flags_t get_flags_t (enum rsb_mif_t mif) const
rsb_type_t get_type_t (enum rsb_mif_t mif) const
rsb_coo_idx_t get_info_coo_t (enum rsb_mif_t mif) const
size_t _get_index_storage_bytes (void) const
size_t _get_storage_bytes (void) const
rsb_nnz_idx_t nnz (void) const
rsb_blk_idx_t blocks (void) const
rsb_coo_idx_t rows (void) const
rsb_coo_idx_t cols (void) const
RSBP_RVT Err_t get_vals (NT *VA, const rsb_coo_idx_t *IA,
const rsb_coo_idx_t *JA, rsb_nnz_idx_t nnz,
rsb_flags_t flags) const
NT get_val (const rsb_coo_idx_t i, const rsb_coo_idx_t j,
rsb_flags_t flags=RSB_FLAG_NOFLAGS) const
RSBP_RVT Err_t set_val (const NT val, const rsb_coo_idx_t
i, const rsb_coo_idx_t j, rsb_flags_t
flags=RSB_FLAG_NOFLAGS)
RSBP_RVT Err_t set_vals (const NT *VA, const
rsb_coo_idx_t *IA, const rsb_coo_idx_t *JA,
rsb_nnz_idx_t nnz, rsb_flags_t flags)
RSBP_RVT Err_t get_vec (NT *Dp, enum rsb_extff_t flags)
const
RSBP_RVT RSBP_DEPRECATED Err_t get_coo
(rsb_trans_t transA, NT *VA, rsb_coo_idx_t *IA,
rsb_coo_idx_t *JA, rsb_flags_t flags) const
RSBP_RVT RSBP_DEPRECATED Err_t get_csr
(rsb_trans_t transA, NT *VA, rsb_coo_idx_t *RP,
rsb_coo_idx_t *JA, rsb_flags_t flags) const
RSBP_RVT RSBP_DEPRECATED Err_t get_rows_sparse
(rsb_trans_t transA, const NT *alphap, NT *VA, rsb_coo_idx_t
*IA, rsb_coo_idx_t *JA, rsb_coo_idx_t frA,
rsb_coo_idx_t lrA, rsb_nnz_idx_t *rnzp, rsb_flags_t
flags) const
RSBP_RVT Err_t upd_vals (enum rsb_elopf_t elop_flags,
const NT &omega)
RSBP_RVT Err_t upd_vals (enum rsb_elopf_t elop_flags,
const NT *omegap)
RSBP_RVT Err_t get_nrm (NT *Np, enum rsb_extff_t flags)
const
rsb_type_t rsbtype (void) const
rsb_flags_t rsbflags (void) const
rsb_string_t get_info_str (const char *key) const
RSBP_RVT Err_t get_info (enum rsb_mif_t miflags, void
*minfop) const
rsb_string_t _info (void) const
RSBP_RVT RSBP_DEPRECATED Err_t tune_spsm_threads
(rsb_real_t *sfp=RSBP_NULL, rsb_int_t *tnp=RSBP_NULL,
rsb_int_t maxr=0, rsb_time_t maxt=0, rsb_trans_t
transA=RSB_TRANSPOSITION_N, const NT *alphap=RSBP_NULL,
rsb_coo_idx_t nrhs=1, rsb_flags_t
order=RSB_FLAG_WANT_COLUMN_MAJOR_ORDER, const NT *Bp=RSBP_NULL,
rsb_nnz_idx_t ldB=0, const NT *betap=RSBP_NULL, NT *Cp=RSBP_NULL,
rsb_nnz_idx_t ldC=0) const
RSBP_RVT RSBP_DEPRECATED Err_t tune_spmm_threads
(rsb_real_t *sfp=RSBP_NULL, rsb_int_t *tnp=RSBP_NULL,
rsb_int_t maxr=0, rsb_time_t maxt=0, rsb_trans_t
transA=RSB_TRANSPOSITION_N, const NT *alphap=RSBP_NULL,
rsb_coo_idx_t nrhs=1, rsb_flags_t
order=RSB_FLAG_WANT_COLUMN_MAJOR_ORDER, const NT *Bp=RSBP_NULL,
rsb_nnz_idx_t ldB=0, const NT *betap=RSBP_NULL, NT *Cp=RSBP_NULL,
rsb_nnz_idx_t ldC=0) const
RSBP_RVT RSBP_DEPRECATED Err_t tune_spmm
(rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr,
rsb_time_t maxt, rsb_trans_t transA, const NT *alphap,
rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp,
rsb_nnz_idx_t ldB, const NT *betap, NT *Cp, rsb_nnz_idx_t ldC)
RSBP_RVT RSBP_DEPRECATED Err_t tune_spmm
(rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr,
rsb_time_t maxt, rsb_trans_t transA, const NT alpha,
rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp,
rsb_nnz_idx_t ldB, const NT beta, NT *Cp, rsb_nnz_idx_t ldC)
RSBP_RVT Err_t tune_spmm (rsb_real_t &sf,
rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs,
rsb_flags_t order, const NT *Bp, const NT beta, NT *Cp)
RSBP_RVT RSBP_DEPRECATED Err_t tune_spsm
(rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr,
rsb_time_t maxt, rsb_trans_t transA, const NT *alphap,
rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp,
rsb_nnz_idx_t ldB, const NT *betap, NT *Cp, rsb_nnz_idx_t ldC)
RSBP_RVT Err_t file_save (const rsb_char_t
*filename=RSBP_NULL) const
RsbMatrix & operator= (const RsbMatrix &A_Rsb)
bool _is_complex (void) const
bool operator== (const RsbMatrix &B_Rsb) const
bool operator!= (const RsbMatrix &B_Rsb) const
NT normOne (void) const
NT normInf (void) const
RSBP_RVT Err_t rndr (const rsb_char_t
*filename=RSBP_NULL, rsb_coo_idx_t pmWidth=512, rsb_coo_idx_t
pmHeight=512, rsb_marf_t rflags=RSB_MARF_EPS) const
class RsbMatrix< NT >"Represent a sparse matrix in RSB format by means of librsb.
Manage construction, destruction, and std::move of numerical
matrices.
Most of the member functions here translate directly to a single function call
to librsb (rsb.h), and pass the parameters as they
are, so the error checking is done by librsb.
While most of librsb C functions use void* pointers instead of
numerical data, RsbMatrix is templated by a type
parameter. This introduces type safety at compile time.
Users of member functions can choose among several overloads. So in additional to the more direct overloads passing e.g. $ alpha $ and $ beta $ by reference, here a user can pass them by value.
Parameters
Note
One may turn on return error value as default at build time by defining RSBP_WANT_REV=1 .
Warning
Todo
Matrix structure: either general, symmetric, hermitian, or triangular (also see rsb_flags_t).
Enumerator
Begin assembling a sparse matrix of given dimensions and type.
Then you can use set_val() or set_vals() repeatedly to populate
the matrix.
After populating the matrix, use close() to terminate its assembly.
Example snip from examples/assemble.cpp:
const rsb_coo_idx_t nrA { 4 }, ncA { 4 };
RsbMatrix<double> mtx(nrA,ncA); // begin matrix assembly
// insert elements of a tridiagonal matrix, one by one
for (auto i = 0; i < nrA; ++i )
for (auto j = i-1; j <= i+1; ++j )
if ( i >= 0 && i < nrA )
if ( j >= 0 && j < ncA )
mtx.set_val((i+1)*100+(j+1),i,j); // add entry
mtx.close(); // finish matrix assembly
assert(mtx.nnz() == 3 * nrA - 2);
Note
Assemble a sparse matrix given CSR input.
Note
Assemble a sparse matrix given COO input.
Example snip from examples/misc.cpp:
const rsb_nnz_idx_t nnzA { 7 };
const rsb_coo_idx_t nrA { 6 }, ncA { 6 }, nrhs { 1 };
const std::vector<rsb_coo_idx_t> IA {0,1,2,3,4,5,1}, JA {0,1,2,3,4,5,0};
const std::vector<double> VA {1,1,1,1,1,1,2}, X(ncA,1);
RsbMatrix<double> mtx(IA.data(),JA.data(),VA.data(),nnzA);
Note
Assemble a sparse matrix given filename input.
Note
Copy a sparse matrix given example input.
Can either clone it, or transpose it or change flags (structure) in the
process.
Move constructor.
The moved matrix object will be invalid afterwards.
Example snip from examples/misc.cpp:
assert( mtx1.nnz() == nnzA );
RsbMatrix<double> mtx3 { std::move(mtx1) };
assert( mtx3.nnz() == nnzA );
Destructor.
Frees matrix object memory.
Note
Deprecated
Deprecated
Warning
Warning
Warning
Warning
Terminate assembly of a previously started and populated matrix.
Shall be called once.
Example snip from examples/assemble.cpp:
const rsb_coo_idx_t nrA { 4 }, ncA { 4 };
RsbMatrix<double> mtx(nrA,ncA); // begin matrix assembly
// insert elements of a tridiagonal matrix, one by one
for (auto i = 0; i < nrA; ++i )
for (auto j = i-1; j <= i+1; ++j )
if ( i >= 0 && i < nrA )
if ( j >= 0 && j < ncA )
mtx.set_val((i+1)*100+(j+1),i,j); // add entry
mtx.close(); // finish matrix assembly
assert(mtx.nnz() == 3 * nrA - 2);
See also
Note
Example snip from examples/twonnz.cpp:
std::cout << "# Matrix sized " << mtx.rows() << "x" << mtx.cols() << ", " << nnzA << " nnz built in " << dt << " s and occupies " << mtxocc << " bytes " << std::endl;
Note
Example snip from examples/misc.cpp:
mtx.file_save(); // print to stdout
Note
Warning
Deprecated
Note
Warning
Deprecated
Note
Note
Note
Note
Note
Note
Note
Note
Note
Note
Deprecated
Note
Note
Note
Note
Example snip from examples/misc.cpp:
assert( mtx1 == mtx2 );
assert( !(mtx1 != mtx2) );
See also
A copy constructor. Will clone the input matrix contents.
Deep comparison: compare if the two matrices have same dimensions, nonzeroes count, nonzeroes pattern and value. Meant for very sporadic use. Inefficient: it can involve matrices copying.
Example snip from examples/misc.cpp:
assert( mtx1 == mtx2 );
assert( !(mtx1 != mtx2) );
Note
Example snip from examples/render.cpp:
mtx.rndr(psfilename.c_str());
Example snip from examples/twonnz.cpp:
std::cout << "# Matrix sized " << mtx.rows() << "x" << mtx.cols() << ", " << nnzA << " nnz built in " << dt << " s and occupies " << mtxocc << " bytes " << std::endl;
Example snip from examples/twonnz.cpp:
std::cout << "# type=" << mtx.rsbtype() << " nt=1," << rnt << " n=" << n << " nrhs=" << nrhs << " order=" << oc << " alpha=" << alpha << " beta=" << beta << " dt=" << dta[0] << ".." << dta[1] << " spmm-scalability=" << dta[0]/dta[1] << " nnz/s=" << nnzA/dta[0] << ".." << nnzA/dta[1] << " flops=" << flops_c/dta[0] << ".." << flops_c/dta[1] << " occ.=" << opocc << " " << std::endl;
Note
Example snip from examples/assemble.cpp:
const rsb_coo_idx_t nrA { 4 }, ncA { 4 };
RsbMatrix<double> mtx(nrA,ncA); // begin matrix assembly
// insert elements of a tridiagonal matrix, one by one
for (auto i = 0; i < nrA; ++i )
for (auto j = i-1; j <= i+1; ++j )
if ( i >= 0 && i < nrA )
if ( j >= 0 && j < ncA )
mtx.set_val((i+1)*100+(j+1),i,j); // add entry
mtx.close(); // finish matrix assembly
assert(mtx.nnz() == 3 * nrA - 2);
See also
Add a single entry during the assembly of a matrix created empty.
Use close() to terminate matrix assembly.
Example snip from examples/assemble.cpp:
const rsb_coo_idx_t nrA { 4 }, ncA { 4 };
RsbMatrix<double> mtx(nrA,ncA); // begin matrix assembly
// insert elements of a tridiagonal matrix, one by one
for (auto i = 0; i < nrA; ++i )
for (auto j = i-1; j <= i+1; ++j )
if ( i >= 0 && i < nrA )
if ( j >= 0 && j < ncA )
mtx.set_val((i+1)*100+(j+1),i,j); // add entry
mtx.close(); // finish matrix assembly
assert(mtx.nnz() == 3 * nrA - 2);
Note
Note
Deprecated
Note
Example snip from examples/bench.cpp:
mtx.spmm(transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC);
Note
Note
Example snip from examples/span.cpp:
mtx.tune_spmm(nullptr,&tn,0,0.0,RSB_TRANSPOSITION_N,alpha,nrhs,RSB_FLAG_WANT_COLUMN_MAJOR_ORDER,X,ncA,beta,Y,nrA);
mtx.spmv(RSB_TRANSPOSITION_N, alpha, X, beta, Y);
Note
Deprecated
Note
Example snip from examples/span.cpp:
mtx.tune_spmm(nullptr,&tn,0,0.0,RSB_TRANSPOSITION_N,alpha,nrhs,RSB_FLAG_WANT_COLUMN_MAJOR_ORDER,X,ncA,beta,Y,nrA);
mtx.spmv(RSB_TRANSPOSITION_N, alpha, X, beta, Y);
Note
Example snip from examples/span.cpp:
mtx.tune_spmm(nullptr,&tn,0,0.0,RSB_TRANSPOSITION_N,alpha,nrhs,RSB_FLAG_WANT_COLUMN_MAJOR_ORDER,X,ncA,beta,Y,nrA);
mtx.spmv(RSB_TRANSPOSITION_N, alpha, X, beta, Y);
Note
Note
Note
Deprecated
Note
Note
Note
Note
Note
Deprecated
Note
Note
Example snip from examples/autotune.cpp:
tt = -rsb_time();
mtx.tune_spmm(&sf,&tn,maxr,tmax,transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC);
tt += rsb_time();
auto nnsmA {mtx.blocks()};
std::cout << "Tuning took " << tt << " s ( " << tt / dt << " ops ) and changed " << nsmA << " to " << nnsmA << " blocks" << std::endl;
mtx.spmm(transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC); // caches warmup
Note
Example snip from examples/autotune.cpp:
tt = -rsb_time();
mtx.tune_spmm(&sf,&tn,maxr,tmax,transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC);
tt += rsb_time();
auto nnsmA {mtx.blocks()};
std::cout << "Tuning took " << tt << " s ( " << tt / dt << " ops ) and changed " << nsmA << " to " << nnsmA << " blocks" << std::endl;
mtx.spmm(transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC); // caches warmup
Deprecated
Note
Example snip from examples/autotune.cpp:
tt = -rsb_time();
mtx.tune_spmm(&sf,&tn,maxr,tmax,transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC);
tt += rsb_time();
auto nnsmA {mtx.blocks()};
std::cout << "Tuning took " << tt << " s ( " << tt / dt << " ops ) and changed " << nsmA << " to " << nnsmA << " blocks" << std::endl;
mtx.spmm(transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC); // caches warmup
Note
Example snip from examples/autotune.cpp:
tt = -rsb_time();
mtx.tune_spmm(&sf,&tn,maxr,tmax,transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC);
tt += rsb_time();
auto nnsmA {mtx.blocks()};
std::cout << "Tuning took " << tt << " s ( " << tt / dt << " ops ) and changed " << nsmA << " to " << nnsmA << " blocks" << std::endl;
mtx.spmm(transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC); // caches warmup
Deprecated
Note
Deprecated
Note
Deprecated
Note
Example snip from examples/bench.cpp:
mtx.upd_vals(RSB_ELOPF_POW,nt_t{0.0}); // set matrix values to ones
Note
Deprecated
Generated automatically by Doxygen for librsb from the source code.
Sun Jan 1 2023 | Version 1.3.0.2 |