Why is parfor 500 times faster with 12 workers on a loop of size 100

1 次查看(过去 30 天)
I am running code that is equivalent to
A=init();
T=init2();
N=100;
B=zeros(N,1);
for i=1:N
B(i)=T.foo(A(i));
end
If I replace the for loop by a parfor, using my local pool, then the computation is approximately 500 times faster (0.4 seconds instead of 238 seconds).
How can this possibly happen, given that the for loop is only of size 100 and that I only have 12 workers (according to the small little button on the left-bottom corner of MATLAB, and also since I have only 12 cores on my CPU)?
Not that I am unhappy with the speedup, but I feel like there is something going on I should know about.
EDIT: I reduced the loopsize to 1, and parfor is still 10 times faster. For the one single computation!

采纳的回答

Bananach
Bananach 2016-4-16
Restarted, and the effect went away. for loop became faster, in a way that made the numbers reasonable

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by