cplusplus.cpp File Reference
Example programs and code

C++ program using the C <rsb.h> interface. Uses rsb_tune_spmm(), rsb_spmv(). More...

## Functions

int | main (void)

## Detailed Description

C++ program using the C <rsb.h> interface. Uses rsb_tune_spmm(), rsb_spmv().

Author
  Michele Martone

See also
  See examples/span.cpp for a C++ example based on the native C++ interface of <rsb.hpp>.

/*
Copyright (C) 2008-2021 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 <https://www.gnu.org/licenses/>.
*/
/*!
\ingroup rsb_doc_examples
@file
@author Michele Martone
@brief C++ program using the C <rsb.h> interface.
Uses #rsb_tune_spmm(), #rsb_spmv().
\see See examples/span.cpp for a C++ example based on the native C++ interface of <rsb.hpp>.
\include cplusplus.cpp
*/
#include <rsb.h> /* librsb header to include */
#include <vector>
#include <stdexcept>
int main(void)
{
/* You can use the C interface of rsb.h in C++ as well. */
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<RSB_DEFAULT_TYPE> VA {1,1,1,1,1,1,2}, X(ncA,1);
std::vector<RSB_DEFAULT_TYPE> Y(nrA,0);
const RSB_DEFAULT_TYPE alpha {2}, beta {1};
const rsb_type_t typecode = RSB_NUMERICAL_TYPE_DEFAULT; // see rsb_types.h
rsb_int_t tn {0};
rsb_real_t sf {0}; // speedup factor
rsb_err_t errval = RSB_ERR_NO_ERROR;
if((errval = rsb_lib_init(RSB_NULL_INIT_OPTIONS)) != RSB_ERR_NO_ERROR)
throw std::runtime_error("failure running rsb_lib_init!");
auto mtxAp = rsb_mtx_alloc_from_coo_const(
VA.data(),IA.data(),JA.data(),nnzA,typecode,nrA,ncA,1,1,
RSB_FLAG_NOFLAGS /* default format will be chosen */
|RSB_FLAG_DUPLICATES_SUM/* duplicates will be summed */
,&errval);
if ( ! mtxAp || errval != RSB_ERR_NO_ERROR)
throw std::runtime_error("failure running rsb_mtx_alloc_from_coo_const!");
errval = rsb_file_mtx_save(mtxAp,nullptr); // rsb_file_mtx_save
if ( ! mtxAp )
throw std::runtime_error("failure running rsb_file_mtx_save!");
errval = rsb_tune_spmm(&mtxAp,&sf,&tn,0,0.0,RSB_TRANSPOSITION_N,&alpha,nullptr,nrhs,RSB_FLAG_WANT_COLUMN_MAJOR_ORDER,X.data(),ncA,&beta,Y.data(),nrA);
if ( ! mtxAp )
throw std::runtime_error("failure running rsb_tune_spmm!");
errval = rsb_spmv(RSB_TRANSPOSITION_N, &alpha, mtxAp, X.data(), 1, &beta, Y.data(), 1); // rsb_spmv
if ( ! mtxAp )
throw std::runtime_error("failure running rsb_spmv!");
rsb_mtx_free(mtxAp);
if((errval = rsb_lib_exit(RSB_NULL_EXIT_OPTIONS)) != RSB_ERR_NO_ERROR)
throw std::runtime_error("failure running rsb_lib_exit!");
}
main
auto main() -> int
Definition assemble.cpp:38
rsb_spmv
rsb_err_t rsb_spmv(rsb_trans_t transA, const void *alphap, const struct rsb_mtx_t *mtxAp, const void *Xp, rsb_coo_idx_t incX, const void *betap, void *Yp, rsb_coo_idx_t incY)
Definition rsb_rsb.c:529
rsb_lib_exit
rsb_err_t rsb_lib_exit(struct rsb_initopts *iop)
Definition rsb_rsb.c:202
rsb_tune_spmm
rsb_err_t rsb_tune_spmm(struct rsb_mtx_t **mtxOpp, rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr, rsb_time_t maxt, rsb_trans_t transA, const void *alphap, const struct rsb_mtx_t *mtxAp, rsb_coo_idx_t nrhs, rsb_flags_t order, const void *Bp, rsb_nnz_idx_t ldB, const void *betap, void *Cp, rsb_nnz_idx_t ldC)
Definition rsb_rsb.c:1777
rsb_mtx_free
struct rsb_mtx_t * rsb_mtx_free(struct rsb_mtx_t *mtxAp)
Definition rsb_rsb.c:301
rsb_file_mtx_save
rsb_err_t rsb_file_mtx_save(const struct rsb_mtx_t *mtxAp, const rsb_char_t *filename)
Definition rsb_rsb.c:948
rsb_lib_init
rsb_err_t rsb_lib_init(struct rsb_initopts *iop)
Definition rsb_rsb.c:56
rsb_mtx_alloc_from_coo_const
struct rsb_mtx_t * rsb_mtx_alloc_from_coo_const(const void *VA, const rsb_coo_idx_t *IA, const rsb_coo_idx_t *JA, rsb_nnz_idx_t nnzA, rsb_type_t typecode, rsb_coo_idx_t nrA, rsb_coo_idx_t ncA, rsb_blk_idx_t brA, rsb_blk_idx_t bcA, rsb_flags_t flagsA, rsb_err_t *errvalp)
Definition rsb_rsb.c:240
rsb.h
This file declares the user interface functions and data structures for the librsb library (see The l...
RSB_FLAG_NOFLAGS
#define RSB_FLAG_NOFLAGS
Definition rsb.h:478
RSB_ERR_NO_ERROR
#define RSB_ERR_NO_ERROR
Definition rsb.h:616
RSB_NULL_EXIT_OPTIONS
#define RSB_NULL_EXIT_OPTIONS
Definition rsb.h:848
rsb_nnz_idx_t
signed int rsb_nnz_idx_t
Definition rsb.h:362
rsb_coo_idx_t
signed int rsb_coo_idx_t
Definition rsb.h:349
rsb_err_t
signed int rsb_err_t
Definition rsb.h:386
RSB_FLAG_WANT_COLUMN_MAJOR_ORDER
#define RSB_FLAG_WANT_COLUMN_MAJOR_ORDER
Definition rsb.h:496
rsb_real_t
double rsb_real_t
Definition rsb.h:403
rsb_type_t
char rsb_type_t
Definition rsb.h:378
RSB_NULL_INIT_OPTIONS
#define RSB_NULL_INIT_OPTIONS
Definition rsb.h:847
rsb_int_t
signed int rsb_int_t
Definition rsb.h:392
RSB_FLAG_DUPLICATES_SUM
#define RSB_FLAG_DUPLICATES_SUM
Definition rsb.h:526
RSB_NUMERICAL_TYPE_DEFAULT
#define RSB_NUMERICAL_TYPE_DEFAULT
A default numerical matrix type.
Definition rsb_types.h:200
RSB_TRANSPOSITION_N
#define RSB_TRANSPOSITION_N
N: Non transposed flag, valid for rsb_trans_t typed variables.
Definition rsb_types.h:138
RSB_DEFAULT_TYPE
#define RSB_DEFAULT_TYPE
The default numerical matrix type (can be used for declarations), used in the example programs.
Definition rsb_types.h:73

## Function Documentation

## main()

int main | ( | void |  | ) |