MATLAB: Can this implementation of Matlabpool in parallel

Parallel Computing Toolbox

Im using the Matpower – Matlab toolbox in parallel computing and building the computer cluster to simulate the programme which is shown below:
matlabpool open job1 5 % matlabpool means computer cluster
spmd %the statement from the Parallel computing toolbox
% Run all the statements in parallel
% first part of code
if labindex==1
% second part of code
if labindex==2
matlabpool close;
When the labindex is 1 the first part of code in this program is running in "computer1" in the cluster, and so forth when the labindex is 2, then the second part of code in the program is "running in computer2". My question is the main code shown above running in sequence or in parallel?
By which I mean, does the second part code has to wait to be executed until the first part of code is executed or two parts of codes can be executed parallel at the two different computers in the cluster?

Best Answer

  • The code will run in parallel. Keep in mind, one path may run quicker than the other paths, so you may nee to create a "barrier", in order to sync the code paths. Take a look at
    help labBarrier
    No code will run past the spmd block until all labs have completed the block.