User`s guide

Further Notes on Communicating Jobs
8-11
In another example, suppose you want to transfer data from every worker to the next
worker on the right (defined as the next higher labindex). First you define for each
worker what the workers on the left and right are.
from_lab_left = mod(labindex - 2, numlabs) + 1;
to_lab_right = mod(labindex, numlabs) + 1;
Then try to pass data around the ring.
labSend (outdata, to_lab_right);
indata = labReceive(from_lab_left);
The reason this code might fail is because, depending on the size of the data
being transferred, the labSend function can block execution in a worker until the
corresponding receiving worker executes its labReceive function. In this case, all the
workers are attempting to send at the same time, and none are attempting to receive
while labSend has them blocked. In other words, none of the workers get to their
labReceive statements because they are all blocked at the labSend statement. To
avoid this particular problem, you can use the labSendReceive function.