why is parfor slower than for?

2 次查看(过去 30 天)
Celso Cruz
Celso Cruz 2013-5-9
In this case, t_parfor is higher than t_for.
N = 100000;
x=zeros(1,N);
tic;
for i = 1 : N
x(i)=rand();
end
t_for = toc;
tic;
parfor i = 1 : N
x(i)=rand();
end
t_parfor = toc;
t_for
t_parfor

回答(1 个)

Sean de Wolski
Sean de Wolski 2013-5-9
First, do you have a matlabpool open? If no matlabpool is open then the parfor loop will not be run in parallel anyway.
Here the data transfer and communication overhead cost more than the computation. parfor will do the most good when the data transfer is low and the calculation time is high.
(And I assume you are aware of: x = rand(N,1) % ;) )

类别

Help CenterFile Exchange 中查找有关 Parallel Computing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by