Parallel computation with Matlab, SPMD. Explanation with simple example code

Today I’d like to introduce a parallel computation skill in Matlab.

I also heard that the use of parallel computation in Matlab is very easy. But it was better than my expectation. Wonderful!! Smile

You need to know the usage of SPMD. It is pretty easy.

First let’s the code, you can also download this file in the attachment, click <here>.


The result is the below

Starting matlabpool using the ‘local’ configuration … connected to 4 labs.
Elapsed time is 120.482356 seconds.
Sending a stop signal to all the labs … stopped.
Elapsed time is 167.796932 seconds.

Because, I did many other works in the calculation time, Its result is not very fast, The slowest CPU core determined the final computation time. But its performance is really good if you have more than 4 multi cpu cores.

I wish this post can help your understanding about the use of SPMD in Matlab.

if you have any question, please leave me a comment below.


I am Youngmok Yun, and writing about robotics theories and my research.

My main site is, and Korean ver. is





2 thoughts on “Parallel computation with Matlab, SPMD. Explanation with simple example code

  1. huda

    in my case N=2,
    so I changed for i=1: 4 to be for i=1:2
    Also, I changed for j=1:4 to be for j=1:2


    if so , the time of parallel code is 74 S whereas 70 S for the other code.

    I badly need solve my problem. I need code show me the difference in running time but I did not find.
    please help me.


  2. admin Post author

    One possible reason is that N is too small. If you run the parallel processing, the Matlab does several extra works which is necessary only for parallel processing. So, it the work is too simple, the load of the extra work is even larger than main work load. In this case, the work time is longer than single process programming.

    My opinion is that this parallel processing program is only more efficient when N is large, or the workload for each process is very large.

    If you need more opinion, let me know.



Leave a Reply