why is parfor slower than for?
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Sean de Wolski
on 9 May 2013
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) % ;) )
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!