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

1 vue (au cours des 30 derniers jours)
Bananach
Bananach le 16 Avr 2016
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!

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by