Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Matrix operations with Parallel Computing Toolbox

Asked by Sascha on 18 Jun 2013

Hi all,

for a student project, I work with the "Parallel Computing Toolbox". To discover it's functionality I make simple matrix operations with distributed matrizes.

With an open matlapool (12 workers) I use (for example) the following code, on a computer with 16 cores:

    M1 = rand (i,i);
    M2 = rand (i,i); 
    tic
    M = M1 * M2;
    toc
    M1 = distributed(M1);
    M2 = distributed(M2);
    tic
    M = M1 * M2;
    toc

While execution of this code I run "ksysguard" to observe the cpu-usage. During the first multiplication (with "normal" matrizes), the cpu-usage of all 16 cores is at 100%. While the second multiplication runs, the usage of 12 cores is at 100% (I think this could be correct, cause of the 12 workers). I even notice that the first multiplication is much quicker (I tested it for values of n up to 20.000), and gets quicker with bigger matrizes.

Even when I close the matlab pool and do a matrix multiplication, all 16 cores have a usage of 100%. Does this mean that matlab does parallel computation at default?

I hope you understand, what I am wondering about. Many thanks in advance for your suggestions.

0 Comments

Sascha

3 Answers

Answer by Shashank Prasanna on 18 Jun 2013
Accepted answer

Most math operations are inherently multithreaded. There is a list you will find on our external page:

http://www.mathworks.com/support/solutions/en/data/1-4PG4AN/

Jill will correct me if I am wrong, but each worker in the matlab pool is always single threaded. Which means the multithreaded operations will run single threaded on a worker but you have the advantage to scale to a large number of machines.

You may also find this link helpful which explains the difference.

http://www.mathworks.com/discovery/multicore-matlab.html

0 Comments

Shashank Prasanna
Answer by Jill Reese on 18 Jun 2013

A number of MATLAB functions are multithreaded, and matrix multiplication (*) is one of them. This is what you are seeing during the first multiplication (with "normal" matrices).

1 Comment

Sascha on 18 Jun 2013

Thanks for your quick answer!

Is there a list of the yet multithreaded functions (without matlab pool using)? So that I can figure out in which functions I can get a benefit of the Parallel Computing Toolbox.

Jill Reese
Answer by Sascha on 19 Jun 2013

Thank you both for your answers. You helped me very much!

1 Comment

Shashank Prasanna on 19 Jun 2013

Sascha, make sure you go ahead and accept an answer. This makes others who have questions similar to yours get their answer quickly by looking at the accepted answer.

Sascha

Contact us