Mysterious behavior in parfor (I know, sounds basic, but...)
Show older comments
This truly seems odd to me. I've tested on a couple of Ubuntu x86-64 machines with 2010b. I use "matlabpool 8" to open up 8 workers, then run the following function (simplified from useful code):
parfor ij=1:100
ijp = ij-1; % ijp in [0, 99]
j = mod(ijp,10);
i = floor(ijp/10);
nlabs = numlabs;
labid = labindex;
if i == 0 || j == 0
disp([ijp,labid,nlabs]);
pause(10);
else
pause(0.01);
end
The first round, I see 8 outputs at once meaning everything runs in parallel (the i ==0 or j == 0 entries). Soon though, there will be 10 seconds between each output from disp, meaning that for some reason the workers are no longer getting long (10 second) workloads.
If I remove the conditional (in my real case I do this when I want to do a very large simulation for all entries and not just the entries where i or j is 0) everything runs in parallel just fine.
Also, numlabs and labindex always returns 1 (not sure if that is normal).
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!