0

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?

horchler
  • 18,384
  • 4
  • 37
  • 73
wuampa
  • 273
  • 4
  • 15
  • What loop? Is there a loop around the `spmd` block or are you referring to loops in your two tasks? I'm not sure there's enough info/code to understand what is going on. – horchler Dec 17 '15 at 17:00
  • What you observe is not a behaviour of `spmd`, it will always wait for all workers. There must be something wrong with your `TASK_TWO` causing the problem. – Daniel Dec 17 '15 at 17:05

1 Answers1

2

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
Edric
  • 23,676
  • 2
  • 38
  • 40