其他分享
首页 > 其他分享> > c-稀疏BLAS是否不包括在BLAS中?

c-稀疏BLAS是否不包括在BLAS中?

作者:互联网

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

我想使用SPARSE BLAS,据我了解this website,SPARSE 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"

将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;
}

解决方法:

您引用的是Blas技术标准,而不是LAPACK参考. LAPACK除了处理some banded matrices之外,不包含稀疏矩阵的例程.还有其他实现,例如spblassparse,它们遵循技术标准并实现稀疏BLAS.通常,稀疏运算不被视为BLAS的一部分,而是扩展.

我建议使用更高级别的库,例如eigen,因为它可以为您节省大量的开发时间,并且通常具有较小的性能成本.还有ublas是boost的一部分,因此,如果您没有将boost作为性能的一部分进行了优化,则如果您将boost用作项目的一部分,则可以尝试一下.您可以找到一个全面的列表here(同样,请注意,未列出LAPACK支持稀疏操作).

标签:c,lapack,sparse-matrix,blas
来源: https://codeday.me/bug/20191011/1896206.html