寻找 C/C++ Linux 中高效计算巨大稀疏矩阵的接口

发布于 2024-10-06 23:03:21 字数 504 浏览 1 评论 0 原文

我正在寻找一个 C/C++ 接口,用于在 Linux 中有效计算巨大的稀疏矩阵。该矩阵可能是数百万乘以百万/千。我检查了一些现有的库,但似乎没有一个能够满足我的所有要求,

1,我需要通过动态添加元素来创建一个稀疏矩阵。 (不适用于 SparseLib++)

2,我还需要能够创建一个稀疏对角矩阵,以便我可以使用不同的标量缩放另一个稀疏矩阵的列。 (没有找到这方面的库,也许还有另一种方法可以按列缩放稀疏矩阵)

3,它需要支持矩阵乘以矩阵/向量的操作(许多库都支持这些基本操作)

4,它需要支持两个稀疏矩阵或向量之间的逐项乘法或除法,例如 MATLAB 中的 .* 或 ./ (没有找到用于此目的的库,我需要此操作来筛选一个稀疏矩阵与另一个稀疏矩阵的一些条目稀疏矩阵)

5、矩阵求逆或线性求解器。 (大多数库都提供线性系统的求解器)

我最初使用Python中的scipy来实现我的算法。 Python 消耗太多内存并且速度很慢,这就是为什么我想将我的程序转换为 C。

谢谢。

I am looking for a C/C++ interface for efficient computation of huge sparse matrix in Linux. The matrix could be of millions times millions/thousands. I have checked a few existing libraries, but it seems none of them satisfies all of my requirements,

1, I need to create a sparse matrix by dynamically adding elements to it. (not for SparseLib++)

2, I also need to be able to create a sparse diagonal matrix so that I can scale the columns of another sparse matrix with different scalars. (didn't find a library for this, and maybe there is another way to scale the sparse matrix by columns)

3, It needs to support the operations of matrix multiplied with matrix/vector (Many libraries support these basic operations)

4, It needs to support entry-wise multiplication or division between two sparse matrices or vectors, like .* or ./ in MATLAB (didn't find a library for this, and I need this operation to screen out some entries of one sparse matrix with another sparse matrix)

5, Matrix inversion or linear solver. (Most libraries provide the solver for linear system)

I originally made use of scipy in Python to implement my algorithm. Python consumes too much memory and it is slow, and that's why I'd like to convert my program into C.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

廻憶裏菂餘溫 2024-10-13 23:03:21

I would recommend CSparse by Tim Davis.

Update (2019): Tim Davis has since released SuiteSparse. This satisfies all requirements listed in the post, including the ability to incrementally building the matrix (see slide 34 in a RedisGraph presentation or "3.1.8 Non-blocking mode" in the SuiteSparse:GraphBLAS paper).

梓梦 2024-10-13 23:03:21

我非常高兴使用英特尔的 MKL

I was very happy using Intel's MKL.

最单纯的乌龟 2024-10-13 23:03:21

唉,大多数稀疏矩阵库使用的格式使得动态设置元素非常困难(谷歌搜索压缩稀疏行,这是最常见的格式)。

正如您所说,大多数库都满足您的所有要求,除了#1。对于#2,一旦您了解了存储格式,这通常很容易。

英特尔 MKL 提供的 PARDISO 解算器不强加格式,它只要求您能够执行矩阵/向量乘积:您在循环中调用解算器,从中获取返回代码,然后执行它要求您执行的操作do(乘以 A,检查终止条件,预处理,...)。这样,您就可以使用您需要的任何存储方案。例如,当您不想存储矩阵或者您有一种时髦的存储格式时,它很有用。

您的要求(尤其是#1)非常适合基于四叉树的稀疏矩阵。但是,我不知道这有什么好的实现。如果您设法对其进行编码/找到它的实现,我将不胜感激。

Alas, most sparse matrix libraries use a format which makes very difficult to set elements dynamically (google for Compressed Sparse Row, which is the most common format).

As you said, most libraries provide you with all you requirements, except #1. For #2, it is usually easy once you understand the storage format.

Intel MKL provides the PARDISO solver which doesn't impose a format, it only requires you to be able to do matrix/vector products: you call the solver in a loop, get a return code from it, and perform what it asks you to do (multiplication by A, checking termination condition, preconditioning, ...). This way, you can use whatever storage scheme you need. It is useful when you don't want to store the matrix for instance, or if you have a funky storage format.

Your requirements (especially #1) makes an excellent candidate for quadtree based sparse matrices. However, I do not know any good implementation of this. If you manage to code it / find an implementation of it, I'd be grateful.

池予 2024-10-13 23:03:21

您看过 LinBox 吗?它支持多种稀疏矩阵存储格式,其中一些允许您在创建矩阵后设置条目:

// set m[i,j] to a
m.refEntry(i, j) = a;

我不确定您的要求 4. 是否满足开箱即用,但它肯定可以轻松编码使用 refEntry 方法。

Have you had a look at LinBox? It supports several sparse matrix storage formats, some of which allow you to set entries after the matrix has been created:

// set m[i,j] to a
m.refEntry(i, j) = a;

I'm not sure whether your requirement 4. is satisfied out-of-the-box, but it can certainly be coded easily using the refEntry method.

妥活 2024-10-13 23:03:21

尝试 TAUCS腮腺炎

我个人曾在一个项目中尝试过 TAUCS,该项目使用它来解决图像处理中百万 x 百万级的稀疏矩阵,这样您就可以知道它可以处理的大小。

我同意亚历山大的观点,这些包有自己的“格式”来编码稀疏矩阵,但这是不可避免的,因为你必须告诉求解器非零元素在哪里。但好的一面是,它们并不难学。顺便说一句,TAUCS 使用压缩列存储 (CCS) 格式。 Alexandre 指的可能是压缩行存储(CRS)。我认为有一种更流行的格式,它使用矩阵中元素的 (i, j)“位置”显式编码元素值,但仅此而已。

有关这些软件包的详细信息,请参阅 www.matrixprogramming.com

Try TAUCS or MUMPS.

I've personally tried TAUCS for a project solving sparse matrices of the order of million x million in image processing using it so that will give you an indication of the size it can deal with.

I agree with Alexandre that these packages come with their own "format" for how to encode the sparse matrix but that is inevitable because you have to tell the solver where the non-zero elements are. But on the bright side they are not difficult to learn. TAUCS by the way, uses the compressed column storage (CCS) format. What Alexandre is referring to is probably the compressed row storage (CRS). There is I think 1 more popular format which encodes explicitly the element value with the (i, j) "location" of the element in the matrix but that is about it.

For details on these packages, see www.matrixprogramming.com.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文