wuampa
wuampa

Reputation: 363

Waiting when using spmd (parallel computing) in Matlab

I am using spmd to distribute two different tasks into the two processors of the computer. The code is something similar to:

spmd
    if labindex==1
       TASK_ONE;
    end
    if labindex==2
       TASK_TWO;
    end
end

Each task opens a file and processes it, storing the results. The loop continues while there still are files to process. My problem is that TASK_ONE has fewer files to process, and when it finishes, the code stops (it exits the spmd block). Thus, TASK_TWO does not finish processing all of its files. Is there a way to make that spmd keeps running until TASK_TWO finishes, even if TASK_ONE has already finished?

Upvotes: 0

Views: 308

Answers (1)

Edric
Edric

Reputation: 25140

The spmd block cannot complete until all workers have completed, so if you are seeing that not all are files processed, you must have some other bug in your code. Essentially, each spmd block executes as if it had a call to labBarrier at the end.

You can easily see this behaviour like so:

spmd
    if labindex == 1
        for idx = 1:10, disp(idx), pause(1), end
    end
    if labindex == 2
        for idx = 1:3, disp(idx), pause(1), end
    end
end

Upvotes: 2

Related Questions