Question

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)

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top