简体   繁体   English

BLAS 中不包含稀疏 BLAS 吗?

[英]Is sparse BLAS not included in BLAS?

I have a working LAPACK implementation and that, as far as I read, contains BLAS.我有一个有效的 LAPACK 实现,据我所知,它包含 BLAS。

I want to use SPARSE BLAS and as far as I understand this website , SPARSE BLAS is part of BLAS.我想使用 SPARSE BLAS,据我了解这个网站,SPARSE BLAS 是 BLAS 的一部分。

But when I tried to run the code below from the sparse blas manual using但是当我尝试从稀疏的 blas 手册中运行下面的代码时

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

the compiler (or linker?) asked for blas_sparse.h.编译器(或链接器?)要求 blas_sparse.h。 When I put that file in the working directory I got:当我将该文件放入工作目录时,我得到:

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"

What must I do to use SPARSE BLAS with LAPACK?我必须怎么做才能将 SPARSE BLAS 与 LAPACK 一起使用? I could start moving a lot of header files to the working directory, but I gathered I already have them with 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;
}

You quote the Blas Technical Standard, not the LAPACK reference.您引用的是 Blas 技术标准,而不是 LAPACK 参考。 LAPACK does not contain routines for sparse matrices, other than handling some banded matrices .除了处理一些带状矩阵之外,LAPACK 不包含用于稀疏矩阵的例程。 There are other implementations such as spblas and sparse which follow the techincal standard and implement sparse BLAS.还有其他实现,例如spblassparse ,它们遵循技术标准并实现稀疏 BLAS。 Typically, sparse operations are not considered part of BLAS, but an extension.通常,稀疏操作不被视为 BLAS 的一部分,而是一种扩展。

I would recommend using a higher level library, such as eigen because it will save you a significant amount of development time, with usually small performance costs.我建议使用更高级别的库,例如eigen,因为它可以为您节省大量的开发时间,而且性能成本通常很小。 There is also ublas which is part of boost, so if you are using boost as part of your project, you could give it a try, though it's not really optimised for performance.还有ublas ,它是 boost 的一部分,因此如果您将 boost 作为项目的一部分,您可以尝试一下,尽管它并没有真正针对性能进行优化。 You can find a comprehensive list here (again, note that LAPACK is not listed as having support for sparse operations).你可以在这里找到一个完整的列表(再次注意,LAPACK 没有被列为支持稀疏操作)。

It seems that g++ does not find the required header files.似乎 g++ 没有找到所需的头文件。 So you need to add所以你需要添加

-I path_to_header_files/ 

to the command line arguments.到命令行参数。 Ie, the directory where you copied blas_sparse.h to your working directory.即,您将 blas_sparse.h 复制到工作目录的目录。

as mentioned by Paul there is no sparse solver included in the standard BLAS.正如保罗所提到的,标准 BLAS 中不包含稀疏求解器。 However Netlib has different computational routines called sparseblas here .然而,Netlib 有不同的计算例程, 这里称为 sparseblas。

I would recommend two famous direct solver for sparse matrices, which are : SuperLU here and MUMPS here我会推荐两个著名的稀疏矩阵直接求解器,它们是:此处的SuperLU 和此处的MUMPS

you can find a full comparison between both libraries performance in this paper " Analysis and Comparison of Two General Sparse Solvers for Distributed Memory Computers "您可以在本文“分布式内存计算机的两种通用稀疏求解器的分析和比较”中找到两个库性能的完整比较

we did a small scale benchmark between our code and superLu and the results is shown at this figure.我们在我们的代码和 superLu 之间做了一个小规模的基准测试,结果如图所示。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM