Executing parfor takes more time than executing standard for loop

7 visualizaciones (últimos 30 días)
Hi,
I have some big data to compute and I've read Parallel Computing Toolbox would speed up some calculations. As we have access to Parallel Computing Toolbox, I though I would give it a go. I read just a few pages of a manual and tried to do some tests. Unfortunately, the time to get through standard for-loop is significantly less than using PCT. I did the same test on 2 different computers and the results are the same. I have validated that PCT can work on each computer before I did tests. Probably I am missing something but I don't know that would be. I tried different loops: less iteration with heavier computations, much more iteration with less computation etc. but always PCT take more time to get through than standard for-loop.
So what I did was I executed command
parloop
to start Parallel Computing Toolbox, waited until the toolbox got lunched and then executed this script
clc;
N = 10*1024*1024;
M = 10;
t = 0:1/N:1-1/N;
A = zeros(N,M);
for it = 1:10
tic;
for f = 1:M
A(:,f) = sin(2*pi*f*t);
end
tt = toc;
fprintf('%30s: %.2f secs\n', 'Non-parallel computing', tt);
tic
parfor f = 1:M
A(:,f) = sin(2*pi*f*t);
end
tt = toc;
fprintf('%30s: %.2f secs.\n', 'Parallel computing', tt);
end
Did I misunderstand something?
Thanks

Respuesta aceptada

Image Analyst
Image Analyst el 19 de Abr. de 2016
You have very very small loops. So few iterations (10) that the overhead of setting up processes on different CPUs is probably more than you gain from having it be parallel. You should see improvements as your iterations get bigger, like in the millions.
  1 comentario
Zbigniew Koziel
Zbigniew Koziel el 19 de Abr. de 2016
I did not realised overhead would cause that. I set the loops for 1 million iterations and parallel is 4 times faster now. Thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by