overhead communication in Parfor
Show older comments
I would like to use parfor to speed up my code but it does not work well. I think it may be due to a warning: Variable "x" is indexed, but not sliced, in a parlor loop. This might result in unnecessary communication.
My code looks similar to the following,
X = cell{128*64,1};
parfor ii = 1:64
y = function(X(ii:ii*128))
end
Accepted Answer
More Answers (1)
Sean de Wolski
on 29 Jun 2015
0 votes
Since your matrix is not that big, one approach would be to replicate it to be a 64x128 where each column is the values you want transmitted to that worker. Then you could have the parfor loop run over columns of this array passing off one column at a time x(:,ii) and this will result in a sliced matrix.
If you have access to the R2015b Prerelease, there might also be something in there you find useful.
4 Comments
Chao Song
on 29 Jun 2015
Chao Song
on 29 Jun 2015
Sean de Wolski
on 30 Jun 2015
This document helps explain classification of variables, basically, you can only have the loop iterator and a constant, not a dynamic range (like ii:ii*128).
My same thought above should work on a cell rather than an mxn matrix since cells can be sliced by the same rules as a numeric matrix. I'll try to provide a small example tomorrow.
Chao Song
on 30 Jun 2015
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!