Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel Matrix Multiplication in MATLAB

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)

like image 427
Malcolm Avatar asked Mar 26 '26 23:03

Malcolm


2 Answers

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.

like image 56
Andrew Janke Avatar answered Mar 29 '26 19:03

Andrew Janke


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
like image 43
Edric Avatar answered Mar 29 '26 19:03

Edric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!