'parfor' slower than 'for' for simple tutorial example
Afficher commentaires plus anciens
Hi everybody, I'm a phd student in physics and I just started learning something about parallel programming in matlab. Unfortunately from the very beginning I've encountered some problems in running parallelized code on my computer. Just to have a try I used this simple code to run some test:
parfor ii=1:1000
A(ii)=ii;
end
A
If I compare the time elapsed for this calculation to the one of the same code with the normal for loop it appears evident that the parfor loop is much slower. I've tried to use matlabpool with default settings and also varying the number of workers (I’ve also tried to completely close the pool), and i've also tried to combine this with gpuArray preallocating A on the GPU, but simple for loop remains the best choice. Is it an hardware incompatibility? I'm currently using Matlab 2011b with Parallel Computing Toolbox 5.2. In my computer I've an INTEL i7 processor and a NVIDIA GEFORCE 540M. Does it matter?
1 commentaire
Roberto
le 27 Avr 2014
I've encountered the same issue; here is what I've tried:
n = 50000;
x = randn(1,n) ;
y = zeros(3,n);
tic
for i = 1 : n
y(1,i) = std(x(1:i));
end
fprintf('\n For normal: %f secs\n',toc);
tic
for i = drange(1 : n)
y(2,i) = std(x(1:i));
end
fprintf('\n For drange: %f secs\n',toc);
tic
parfor i = 1 : n
y(3,i) = std(x(1:i));
end
fprintf('\n parFor: %f secs\n',toc);
and here are the results:
For normal: 11.337090 secs
For drange: 11.569059 secs
parFor: 11.552776 secs
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Parallel Computing Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!