librsb 1.3.0.2

Data Structures | Macros
rsb.hpp File Reference

Classes `RsbLib` and `RsbMatrix` provide native C++ access to `librsb`. More...

## Data Structures
class | RsbLib
| Class initializing/finalizing `librsb` state. More...
class | RsbMatrix< NT >
| Represent a sparse matrix in RSB format by means of `librsb`. More...

## Macros
#define | RSBP_DEPRECATED
| Internal attribute specifier for deprecated member functions. More...
#define | RSBP_NODISCARD
| Internal attribute. More...
#define | RSBP_WANT_REV 0
| If this is defined to 1 before including <rsb.hpp>, rsb_err_t is the default return type. Otherwise the default is void. More...
#define | RSBP_RVT template <typename Err_t=void>
| No return type. More...
#define | RSBP_MSLVRV 10201
| Minimal supported librsb version (value of RSB_LIBRSB_VER, defined via rsb.h) More...

## Detailed Description

Classes `RsbLib` and `RsbMatrix` provide native C++ access to `librsb`.

Most of the `librsb` functionality is available via C++ classes `RsbLib` and `RsbMatrix`.
These classes are defined in header file `<rsb.hpp>`, which wraps functionality of `librsb's` C interface `<rsb.h>`.
The `RsbMatrix` class can manipulate sparse matrices of several numerical types (same ones as `librsb:` matrix_supported_numerical_types_section).
Before using `RsbMatrix`, the library must be initialized by having a `RsbLib` object.
To avoid problems when including this header, don't define preprocessor macros prefixed with `RSB_` or `RSBP_`.

For a quick start, check out examples/example.cpp or other examples in its directory.

/*
Copyright (C) 2020-2022 Michele Martone
This file is part of librsb.
librsb is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
librsb is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with librsb; see the file COPYING.
If not, see <http://www.gnu.org/licenses/>.
*/
/*!
\ingroup rsb_doc_examples
\file
@author Michele Martone
@brief C++ example based on <rsb.hpp> using RsbMatrix.spmm().
Using a \librsb program via \rsblib does not differ conceptually much \librsb.
Errors caught by \librsb shall not go unnoticed and trigger an exception instead.
Memory management of matrices and the library state itself follow the usual C++ RAII rules:
the \c mtx object is freed first via RsbMatrix's destructor;
then \librsb is finalized via RsbLib()'s destructor .
\include example.cpp
*/
#include <rsb.hpp>
using namespace rsb;
#ifdef RSB_NUMERICAL_TYPE_DOUBLE
#if RSBP_WANT_CPP20
#include <vector>
#include <array>
/* If your compiler is C++20 compatible, the std::span-based interface is available like: */
auto main() -> int {
RsbLib rsblib;
const rsb_nnz_idx_t nnzA { 7 };
const rsb_coo_idx_t nrA { 6 }, ncA { 6 }, nrhs { 2 };
const rsb_coo_idx_t IA [nnzA] {0,1,2,3,4,5,1};
std::array<rsb_coo_idx_t,7> JA {0,1,2,3,4,5,0};
std::vector<double> VA {1,1,1,1,1,1,2}, X(nrhs*ncA,1);
std::vector<double> Y(nrhs*nrA,0);
const double alpha {2}, beta {1};
rsb_int_t tn {0};
rsb_real_t sf {0}; // speedup factor (tune_spmm output)
const rsb_flags_t order {RSB_FLAG_WANT_COLUMN_MAJOR_ORDER};
// IA,JA,VA are respectively from a C array, std::vector, std::array;
// here using the C++20's std::span interface:
RsbMatrix<double> mtx(IA,JA,VA);
mtx.file_save(); // rsb_file_mtx_save
mtx.tune_spmm(sf,RSB_TRANSPOSITION_N,alpha,nrhs,order,X,beta,Y); // rsb_tune_spmm
mtx.spmm(RSB_TRANSPOSITION_N,alpha,nrhs,order,X,beta,Y); // rsb_spmv
}
#else
#include <vector>
/* The pointer-based interface is available as well: */
auto main() -> int {
RsbLib rsblib;
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);
std::vector<double> Y(nrA,0);
const double alpha {2}, beta {1};
rsb_int_t tn {0};
rsb_real_t sf {0}; // speedup factor (tune_spmm output)
RsbMatrix<double> mtx(IA.data(),JA.data(),VA.data(),nnzA);
mtx.file_save(nullptr); // rsb_file_mtx_save
mtx.tune_spmm(&sf,&tn,0,0.0,RSB_TRANSPOSITION_N,alpha,nrhs,RSB_FLAG_WANT_COLUMN_MAJOR_ORDER,X.data(),ncA,beta,Y.data(),nrA); // rsb_tune_spmm
mtx.spmv(RSB_TRANSPOSITION_N, alpha, X.data(), beta, Y.data()); // rsb_spmv
}
#endif
#else
auto main() { }
#endif

Author
  Michele Martone

## Macro Definition Documentation

## ◆ RSBP_DEPRECATED

#define RSBP_DEPRECATED

Internal attribute specifier for deprecated member functions.

Header-only (`rsb.hpp`) wrapper classes for librsb (http://librsb.sf.net).

## ◆ RSBP_MSLVRV

#define RSBP_MSLVRV 10201

Minimal supported librsb version (value of RSB_LIBRSB_VER, defined via rsb.h)

## ◆ RSBP_NODISCARD

#define RSBP_NODISCARD

Internal attribute.

## ◆ RSBP_RVT

#define RSBP_RVT template <typename Err_t=void>

No return type.

## ◆ RSBP_WANT_REV

#define RSBP_WANT_REV 0

If this is defined to 1 before including <rsb.hpp>, rsb_err_t is the default return type. Otherwise the default is void.