MATLAB 中的并行矩阵乘法

发布于 2024-12-18 14:42:11 字数 445 浏览 3 评论 0原文

有没有一种相对容易实现或透明的方法来在Matlab中并行乘以两个大矩阵?

理想情况下,我想最多用几行代码来执行这种并行乘法,也许是这样的:

    C_1 = A*B        % normal
    C_2 = pmult(A,B) % parallel
    % C_1 and C_2 have the same entries

如果有一种方法可以轻松地执行这种并行乘法,有人可以指出我的代码吗?如果没有,有谁知道在 Matlab 中实现并行矩阵乘法算法的最佳方法是什么?

预先感谢很棒的 Stackoverflow 社区。

编辑 - 我相信我遇到的部分问题是稀疏矩阵的矩阵乘法不会自动并行化;它会自动并行化密集矩阵。新问题:Matlab 可以并行进行稀疏矩阵乘法吗? (CPU 并行化,因为我没有启用 CUDA 的显卡)

Is there a relatively easy to implement or transparent way to multiply two large matrices in Matlab in parallel?

Ideally, I would like to perform this parallel multiplication with at most a few lines of code, perhaps something like:

    C_1 = A*B        % normal
    C_2 = pmult(A,B) % parallel
    % C_1 and C_2 have the same entries

If there is a way to easily do this paralell multiplication, can someone please point me to the code? If not, does anyone have any ideas on what they feel is the best way to implement a parallel matrix multiplication algorithm in Matlab?

Thanks in advance, awesome Stackoverflow community.

EDIT --
I believe that part of the issue I was running into is that matrix multiplication for sparse matrices is not automatically parallelized; it is automatically parallelized for dense matrices. New question: can Matlab do sparse matrix multiplication in parallel? (CPU parallelization as I don't have CUDA enabled graphics cards)

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

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

发布评论

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

评论(2

自由如风 2024-12-25 14:42:11

Matlab 可能已经通过其隐式多线程支持做到了这一点。请参阅 http://www.mathworks.com /support/solutions/en/data/1-4PG4AN/?solution=1-4PG4AN; “*”运算符。 Matlab 已经为您完成了简单的可并行操作;只需在多核机器上运行它即可。

Matlab probably already does this via its implicit multithreading support. See http://www.mathworks.com/support/solutions/en/data/1-4PG4AN/?solution=1-4PG4AN; the "*" operator. The trivially parallelizable operations are already done for you by Matlab; just run it on a multicore machine.

究竟谁懂我的在乎 2024-12-25 14:42:11

你说的并行是什么意思?这两种方法都使用显式并行性,并且都需要并行计算工具箱(第二种也需要功能强大的 GPU)。

选项 1:MPI 并行

matlabpool open local
D = distributed.rand(2000); % distributed across workers of matlabpool
R = D * D; % mtimes overloaded to compute in parallel

选项 2:GPU 并行

G = gpuArray(rand(2000)); % place data on the GPU
G2 = G * G; % operate on it in parallel

What do you mean by parallel? These two approaches use explicit parallelism, and both require Parallel Computing Toolbox (the second also requires a capable GPU).

Option 1: MPI parallelism

matlabpool open local
D = distributed.rand(2000); % distributed across workers of matlabpool
R = D * D; % mtimes overloaded to compute in parallel

Option 2: GPU parallelism

G = gpuArray(rand(2000)); % place data on the GPU
G2 = G * G; % operate on it in parallel
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文