c – 改进稀疏线性系统的解决方案
作者:互联网
我在Linux系统上用C编写了一个代码,它解决了线性系统A x = b,其中A是一个稀疏对称矩阵,使用以下两种方法:
>使用UMFPACK顺序分解并进行后向替换.
>使用UMFPACK顺序分解,然后使用cuSPARSE库进行向后转发.
我的系统配置是:CUDA版本5.0,UMFPACK版本5.6.2,Linux内核版本Debian 3.2.46-1,使用的显卡:GeForce GTX Titan.
从理论上讲,第二种方法应该比第一种方法表现更好,而且误差很小或没有.但是,我观察到以下问题:
>使用UMFPACK函数umfpack_di_solve的后向/前向替换几乎比CUDA变体快2倍.
>对于某些矩阵,使用UMFPACK和CUDA获得的结果之间的误差非常大,最大误差为3.2537,而对于其他矩阵,其大小为1e-16.
附件是我的tar文件,包含以下组件:
>一个文件夹factorize_copy,主文件fc.cu,我用它来解决线性系统.它从grid _ * _ CSC.m文件中读取稀疏矩阵,这些文件也存在于同一目录中.为方便起见,提供三个稀疏矩阵的结果也在文本文件中给出.
>具有编译和运行UMFPACK(我们也用于计算)的所有依赖项的文件夹.
tar文件的链接是
https://www.dropbox.com/s/9qfs5awclshyk3b/code.tar.gz
如果你想运行代码,我提供了一个MAKEFILE,因为我在factorize_copy目录中的系统中使用了MAKEFILE.您可能需要重新编译UMFPACK库.
我们的586 x 586稀疏矩阵程序的示例输出也如下所示(请注意,与我们检查的其他稀疏矩阵相比,此情况下的误差非常高).
***** Reading the Grids Reading Grids Successful ***** Solving a sparse matrix of size: 586x586 ***** Solving the grid on umfpack ***** Factorizing The Grid -------------- CPU TIME for umfpack factorization is: 0.00109107 -------------- Wall-Clock TIME for umfpack factorization is: 0 Factorizing the Grid successful Solving the grid on umfpack successful -------------- CPU TIME for umfpack solve is: 6.281e-05 ***** Allocating GPU memory and Copying data ---------------- CPU Time for Allocating GPU memory and Copying Data: 1.6 ***** Performing b = P*b to account for the row ordering in A Matrix-Vector (Pb) multiplication successful ***** Solving the system: LUx=b Analyzing Ly = b successful Solving Ly = b successful Analyzing Ux = y successful Solving Ux = y successful ***** Performing x = Q*x to account for the column ordering in A Matrix-Vector (Qx) multiplication successful ---------- GPU Time for the solve is: 5.68029 ms ##### Maximum error between UMFPACK and CUDA: 3.2537 ##### Average error between UMFPACK and CUDA: 0.699926 ***** Writing the results to the output files Result Written to the file 'vout_586.m' and the file 'vout_umfpack_586.m' (Operation Successful!)
如果有人能指出在这种情况下可能出现的错误,我真的很感激.如果有一种更好的方法可以解决我错过的使用CUDA的稀疏线性系统,请告诉我.
编辑:我弄清楚为什么它在某些情况下给出错误,在某些情况下没有.在代码中调用内核函数时,每个块的线程数有误.但是,我仍然有加速的问题.
解决方法:
如果你正在处理一个在CPU上花费数小时的时间的问题,那么考虑到gpu计算中涉及的所有延迟,你几乎不能指望gpu执行得更快.
标签:c,linux,cuda,sparse-matrix,umfpack 来源: https://codeday.me/bug/20190831/1777348.html