我有一个正在工作的LAPACK实现,据我所读,它包含BLAS。
我想使用稀疏BLAS,据我所理解的本网站,稀疏BLAS是BLAS的一部分。
但是,当我试图从稀疏的blas手册运行下面的代码时,使用
g++ -o spemse.x sparse_blas_example.c -L/usr/local/lib -lblas && /稀疏_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?我可以开始将很多头文件移到工作目录中,但是我发现我已经有了它们!
/* 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;
}发布于 2015-10-18 10:39:34
您引用的是Blas技术标准,而不是LAPACK参考。除了处理一些带状矩阵之外,LAPACK不包含稀疏矩阵的例程。还有其他实现,如斯巴拉斯和稀疏,它们遵循技术标准并实现稀疏BLAS。通常,稀疏操作不被视为BLAS的一部分,而是一个扩展。
我建议使用更高级别的库,如本征,因为它将节省大量的开发时间,通常性能成本较小。还有乌布拉斯,它是boost的一部分,所以如果您使用boost作为项目的一部分,您可以尝试一下,尽管它并没有真正优化性能。您可以找到一个全面的list 这里 (同样,请注意,LAPACK不支持稀疏操作)。
发布于 2015-10-17 18:54:25
g++似乎没有找到所需的头文件。所以你需要添加
-I path_to_header_files/ 命令行参数。也就是说,将blas_sparse.h复制到工作目录的目录。
发布于 2021-03-08 22:35:37
正如保罗所提到的,在标准的BLAS中没有稀疏的求解器。但是,Netlib有不同的计算例程,称为sparseblas 这里。
我推荐两个著名的稀疏矩阵的直接求解器,它们是: SuperLU 这里和腮腺炎这里。
您可以在本文“分析和两个分布式内存计算机通用稀疏求解器的比较”()中对这两个库的性能进行全面比较。
我们在代码和superLu之间做了一个小规模的基准测试,结果如图所示。

https://stackoverflow.com/questions/33190068
复制相似问题