BLAS中是否包含稀疏BLAS?

Lud*_*udi 2 c++ blas sparse-matrix lapack

我有一个有效的LAPACK实现,据我所知,它包含BLAS.

我想使用稀疏BLAS而据我了解这个网站,稀疏BLAS是BLAS的一部分.

但是当我尝试使用稀疏blas手册运行下面的代码时

g ++ -o sparse.x sparse_blas_example.c -L/usr/local/lib -lblas && ./sparse_ex.x

编译器(或链接器?)要求blas_sparse.h.当我把那个文件放在工作目录中时,我得到了:

ludi@ludi-M17xR4:~/Desktop/tests$ g++  -o sparse.x sparse_blas_example.c -L/usr/local/lib -lblas && ./sparse_ex.x
In file included from sparse_blas_example.c:3:0:
blas_sparse.h:4:23: fatal error: blas_enum.h: No such file or directory
 #include "blas_enum.h"
Run Code Online (Sandbox Code Playgroud)

使用SPARSE BLAS和LAPACK我该怎么办?我可以开始将很多头文件移动到工作目录中,但我收集了我已经将它们与lapack一起使用了!

/* C example: sparse matrix/vector multiplication */

#include "blas_sparse.h"
int main()
{
const int n = 4;
const int nz = 6;
double val[] = { 1.1, 2.2, 2.4, 3.3, 4.1, 4.4 };
int indx[] = { 0, 1, 1, 2, 3, 3};
int jndx[] = { 0, 1, 4, 2, 0, 3};
double x[] = { 1.0, 1.0, 1.0, 1.0 };
double y[] = { 0.0, 0.0, 0.0, 0.0 };
blas_sparse_matrix A;
double alpha = 1.0;
int i;

/*------------------------------------*/
/* Step 1: Create Sparse BLAS Handle */
/*------------------------------------*/

A = BLAS_duscr_begin( n, n );

/*------------------------------------*/
/* Step 2: insert entries one-by-one */
/*------------------------------------*/

for (i=0; i< nz; i++)
{
BLAS_duscr_insert_entry(A, val[i], indx[i], jndx[i]);
}

/*-------------------------------------------------*/
/* Step 3: Complete construction of sparse matrix */
/*-------------------------------------------------*/
BLAS_uscr_end(A);

/*------------------------------------------------*/
/* Step 4: Compute Matrix vector product y = A*x */
/*------------------------------------------------*/

BLAS_dusmv( blas_no_trans, alpha, A, x, 1, y, 1 );

/*---------------------------------*/
/* Step 5: Release Matrix Handle */
/*---------------------------------*/

BLAS_usds(A);

/*---------------------------*/
/* Step 6: Output Solution */
/*---------------------------*/

for (i=0; i<n; i++) printf("%12.4g ",y[i]);
printf("\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)

pau*_*l-g 5

您引用Blas技术标准,而不是LAPACK参考.除了处理某些带状矩阵之外,LAPACK不包含稀疏矩阵的例程.还有其他实现,如spblassparse,遵循techincal标准并实现稀疏BLAS.通常,稀疏操作不被视为BLAS的一部分,而是扩展.

我建议使用更高级别的库,例如eigen,因为它可以节省大量的开发时间,通常性能成本很低.还有ublas是boost的一部分,所以如果你将boost作为项目的一部分,你可以尝试一下,虽然它并没有真正优化性能.您可以在此处找到全面的列表(再次注意,LAPACK未列为支持稀疏操作).