#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
static int tune_from_file(
char *
const filename,
rsb_int_t wvat)
{
struct rsb_mtx_t *mtxMp = NULL;
const void * alphap = NULL;
const void * betap = NULL;
char ib[200];
const char*is = "RSB_MIF_MATRIX_INFO__TO__CHAR_P";
rsb_type_t typecodea [] = RSB_MATRIX_TYPE_CODES_ARRAY;
int typecodei;
goto err;
goto err;
printf("Loading matrix from file \"%s\".\n",filename);
goto err;
for( typecodei = 0 ; typecodei < RSB_IMPLEMENTED_TYPES; ++typecodei )
{
struct rsb_mtx_t *mtxAp = NULL;
struct rsb_mtx_t *mtxOp = NULL;
sf = 0.0;
tn = 0;
printf("Considering %c clone.\n",typecode);
flagsA);
goto err;
printf("Base matrix:\n");
printf("%s\n\n",ib);
alphap, mtxAp, nrhs, order, NULL, ldB, betap, NULL, ldC);
if(tn == 0)
printf("After %lfs, autotuning routine did not find a better"
" threads count configuration.\n",dt);
else
printf("After %lfs, thread autotuning declared speedup of %lg x,"
" when using threads count of %d.\n",dt,sf,tn);
printf("\n");
mtxOp = mtxAp;
alphap, NULL, nrhs, order, NULL, ldB, betap, NULL, ldC);
goto err;
if( mtxOp == mtxAp )
{
printf("After %lfs, global autotuning found old matrix optimal,"
" with declared speedup %lg x when using %d threads\n",dt,sf,tn);
}
else
{
printf("After %lfs, global autotuning declared speedup of %lg x,"
" when using threads count of %d and a new matrix:\n",dt,sf,tn);
printf("%s\n",ib);
}
printf("\n");
mtxAp = NULL;
}
mtxMp = NULL;
err:
printf("Program terminating with error.\n");
return errval;
}
int main(
const int argc,
char *
const argv[])
{
struct rsb_mtx_t *mtxAp = NULL;
char ib[200];
const char*is = "RSB_MIF_MATRIX_INFO__TO__CHAR_P";
if(argc > 1 && !isdigit(argv[1][0]) )
{
errval = tune_from_file(argv[1],wvat);
goto ret;
}
if(argc > 1)
{
nrA = ncA = atoi(argv[1]);
goto err;
nnzA = (nrA/rd)*(ncA/cd);
ldB = nrA;
ldC = ncA;
}
printf("Creating %d x %d matrix with %d nonzeroes.\n",(int)nrA,
(int)ncA, (int)nnzA);
IA = calloc(nnzA, si);
JA = calloc(nnzA, si);
VA = calloc(nnzA, so);
Bp = calloc(nrhs*ncA ,so);
Cp = calloc(nrhs*nrA ,so);
if( ! ( VA && IA && JA && Bp && Cp ) )
goto err;
for(nrhsi=0;nrhsi<nrhs;++nrhsi)
for(ci=0;ci<ncA/cd;++ci)
Bp[nrhsi*ldC+ci] = 1.0;
for(nrhsi=0;nrhsi<nrhs;++nrhsi)
for(ri=0;ri<nrA/rd;++ri)
Cp[nrhsi*ldC+ri] = 1.0;
ni = 0;
for(ci=0;ci<ncA/cd;++ci)
for(ri=0;ri<nrA/rd;++ri)
{
VA[ni] = nrA * ri + ci,
IA[ni] = ri;
JA[ni] = ci;
ni++;
}
{
printf("Error setting option!\n");
goto err;
}
VA,IA,JA,nnzA,typecode,nrA,ncA,bs,bs,
free(VA);
free(IA);
free(JA);
VA = NULL;
IA = NULL;
JA = NULL;
goto err;
printf("Allocated matrix of %zd nonzeroes:\n",(size_t)nnzA);
printf("%s\n\n",ib);
for(t=0;t<tt;++t)
rsb_spmm(transA,&alpha,mtxAp,nrhs,order,Bp,ldB,&beta,Cp,ldC);
odt = dt;
printf("Before auto-tuning, %d multiplications took %lfs.\n",tt,dt);
printf("Threads autotuning (may take more than %lfs)...\n",
oitmax*tmax);
&alpha, mtxAp, nrhs, order, Bp, ldB, &beta, Cp, ldC);
goto err;
if(tn == 0)
printf("After %lfs, autotuning routine did not find a better"
" threads count configuration.\n",dt);
else
printf("After %lfs, autotuning routine declared speedup of %lg x,"
" when using threads count of %d.\n",dt,sf,tn);
goto err;
printf("%s\n",ib);
for(t=0;t<tt;++t)
rsb_spmm(transA,&alpha,mtxAp,nrhs,order,Bp,ldB,&beta,Cp,ldC);
printf("After threads auto-tuning, %d multiplications took %lfs"
" -- effective speedup of %lg x\n",tt,dt,odt/dt);
odt = dt;
tn = 0;
goto err;
goto err;
printf("Matrix autotuning (may take more than %lfs; using %d"
" threads )...\n", oitmax*tmax, tn);
&alpha, NULL, nrhs, order, Bp, ldB, &beta, Cp, ldC);
goto err;
if(tn == 0)
printf("After %lfs, autotuning routine did not find a better"
" threads count configuration.\n",dt);
else
printf("After %lfs, autotuning routine declared speedup of %lg x,"
" when using threads count of %d.\n",dt,sf,tn);
printf("%s\n",ib);
for(t=0;t<tt;++t)
rsb_spmm(transA,&alpha,mtxAp,nrhs,order,Bp,ldB,&beta,Cp,ldC);
printf("After threads auto-tuning, %d multiplications took %lfs"
" -- further speedup of %lg x\n",tt,dt,odt/dt);
free(Cp);
free(Bp);
{
printf("librsb timer-based profiling is not supported in "
"this build. If you wish to have it, re-configure librsb "
"with its support. So you can safely ignore the error you"
" might just have seen printed out on screen.\n");
}
else
if(etime)
printf("Elapsed program time is %5.2lfs\n",etime);
ret:
goto err;
return EXIT_SUCCESS;
err:
printf("Program terminating with error.\n");
return EXIT_FAILURE;
}
auto main() -> int
Definition: assemble.cpp:38
rsb_err_t rsb_lib_set_opt(enum rsb_opt_t iof, const void *iop)
Definition: rsb_rsb.c:104
rsb_err_t rsb_mtx_get_info_str(const struct rsb_mtx_t *mtxAp, const rsb_char_t *mis, void *minfop, size_t buflen)
Definition: rsb_rsb.c:1630
rsb_err_t rsb_spmm(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:1425
rsb_time_t rsb_time(void)
Definition: rsb_rsb.c:1697
struct rsb_mtx_t * rsb_file_mtx_load(const rsb_char_t *filename, rsb_flags_t flagsA, rsb_type_t typecode, rsb_err_t *errvalp)
Definition: rsb_rsb.c:1026
rsb_err_t rsb_lib_exit(struct rsb_initopts *iop)
Definition: rsb_rsb.c:202
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_err_t rsb_lib_get_opt(enum rsb_opt_t iof, void *iop)
Definition: rsb_rsb.c:128
rsb_err_t rsb_perror(void *stream, rsb_err_t errval)
Definition: rsb_rsb.c:814
struct rsb_mtx_t * rsb_mtx_free(struct rsb_mtx_t *mtxAp)
Definition: rsb_rsb.c:301
rsb_err_t rsb_mtx_clone(struct rsb_mtx_t **mtxBpp, rsb_type_t typecode, rsb_trans_t transA, const void *alphap, const struct rsb_mtx_t *mtxAp, rsb_flags_t flags)
Definition: rsb_rsb.c:323
rsb_err_t rsb_lib_init(struct rsb_initopts *iop)
Definition: rsb_rsb.c:56
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_IO_WANT_VERBOSE_TUNING
Definition: rsb.h:779
@ RSB_IO_WANT_EXECUTING_THREADS
Definition: rsb.h:739
@ RSB_IO_WANT_LIBRSB_ETIME
Definition: rsb.h:775
This file declares the user interface functions and data structures for the librsb library (see The l...
#define RSB_FLAG_NOFLAGS
Definition: rsb.h:478
#define RSB_ERR_NO_ERROR
Definition: rsb.h:616
#define RSB_NULL_EXIT_OPTIONS
Definition: rsb.h:848
#define RSB_MAX_MATRIX_DIM
Definition: rsb.h:442
#define RSB_DEFAULT_BLOCKING
Definition: rsb.h:429
rsb_flags_t rsb_trans_t
Definition: rsb.h:400
signed int rsb_nnz_idx_t
Definition: rsb.h:362
signed int rsb_coo_idx_t
Definition: rsb.h:349
signed int rsb_flags_t
Definition: rsb.h:373
signed int rsb_err_t
Definition: rsb.h:386
#define RSB_FLAG_WANT_COLUMN_MAJOR_ORDER
Definition: rsb.h:496
double rsb_real_t
Definition: rsb.h:403
rsb_real_t rsb_time_t
Definition: rsb.h:411
#define RSB_MIN_MATRIX_DIM
Definition: rsb.h:439
char rsb_type_t
Definition: rsb.h:378
#define RSB_ERR_UNSUPPORTED_FEATURE
Definition: rsb.h:649
#define RSB_NULL_INIT_OPTIONS
Definition: rsb.h:847
signed int rsb_int_t
Definition: rsb.h:392
#define RSB_NUMERICAL_TYPE_DEFAULT
A default numerical matrix type.
Definition: rsb_types.h:200
#define RSB_TRANSPOSITION_N
N: Non transposed flag, valid for rsb_trans_t typed variables.
Definition: rsb_types.h:138
#define RSB_DEFAULT_TYPE
The default numerical matrix type (can be used for declarations), used in the example programs.
Definition: rsb_types.h:73