稀疏 BLAS 不包含在 BLAS 中吗?

Posted

技术标签:

【中文标题】稀疏 BLAS 不包含在 BLAS 中吗?【英文标题】:Is sparse BLAS not included in BLAS? 【发布时间】:2015-10-17 18:24:09 【问题描述】:

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

我想使用 SPARSE BLAS,据我了解 this website,SPARSE BLAS 是 BLAS 的一部分。

但是当我尝试使用 sparse 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;

【问题讨论】:

【参考方案1】:

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

我会推荐使用更高级别的库,例如eigen,因为它会为您节省大量的开发时间,而且通常会降低性能成本。还有ublas,它是 boost 的一部分,所以如果你在项目中使用 boost,你可以尝试一下,尽管它并没有真正针对性能进行优化。你可以找到一个完整的列表here(再次注意,LAPACK 没有被列为支持稀疏操作)。

【讨论】:

【参考方案2】:

g++ 好像没有找到需要的头文件。所以你需要添加

-I path_to_header_files/ 

到命令行参数。即,您将 blas_sparse.h 复制到工作目录的目录。

【讨论】:

【参考方案3】:

正如 Paul 所说,标准 BLAS 中不包含稀疏求解器。然而,Netlib 有不同的计算例程,称为 sparseblas here。

我会推荐两个著名的稀疏矩阵直接求解器,它们是:SuperLU here 和 MUMPS here

您可以在这篇论文“Analysis and Comparison of Two General Sparse Solvers for Distributed Memory Computers”中找到两个库性能的完整比较

我们在我们的代码和 superLu 之间做了一个小规模的基准测试,结果如下图所示。

【讨论】:

以上是关于稀疏 BLAS 不包含在 BLAS 中吗?的主要内容,如果未能解决你的问题,请参考以下文章

OSX 中 MKL BLAS 和 Accelerate Framework BLAS 之间 DSCAL 的不一致

在 C Mex-File 中使用 BLAS 库

[转]BLAS简介

centos中怎么安装theano

BLAS+多精度+MPI

Armadillo C++ 和 BLAS 和 ATLAS 在 mingw32 下找不到 lapack blas