稀疏BLAS是否包含在BLAS中?

5

我有一个可用的LAPACK实现,据我所知它包含BLAS。

我想要使用SPARSE BLAS,根据这个网站的理解,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"

我该如何使用LAPACK的稀疏BLAS?我可以开始将许多头文件移动到工作目录,但是我想我已经在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;
}
3个回答

9
你引用了Blas技术标准,而不是LAPACK参考。LAPACK不包含稀疏矩阵的例程,除了处理一些带状矩阵。还有其他实现,如spblas和sparse,它们遵循技术标准并实现稀疏BLAS。通常,稀疏操作不被认为是BLAS的一部分,而是一个扩展。
我建议使用更高级的库,比如eigen,因为这将节省大量开发时间,通常只会带来较小的性能损失。还有ublas,它是boost的一部分,因此如果您正在使用boost作为项目的一部分,可以尝试一下,虽然它并没有真正针对性能进行优化。您可以在这里找到一个全面的列表(再次注意,LAPACK没有列出对稀疏操作的支持)。

3
看起来 g++ 没有找到所需的头文件。因此,您需要添加:
-I path_to_header_files/ 

将blas_sparse.h文件复制到您的工作目录中,然后将其目录添加到命令行参数中。


2
如Paul所提到的,标准BLAS中没有包含稀疏求解器。然而,Netlib有不同的计算例程,称为sparseblas(链接1)。
我推荐两个著名的稀疏矩阵直接求解器,它们分别是:SuperLU(链接2)和MUMPS(链接3)。
你可以在这篇论文《分布式内存计算机的两个通用稀疏求解器的分析与比较》中找到对这两个库性能的全面比较。
我们对我们的代码(即普通的C++循环)和SuperLU进行了小规模基准测试,结果显示在这张图片上。 (链接4:enter image description here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接