Clear Filters
Clear Filters

why is parfor slower than for?

2 views (last 30 days)
Celso Cruz
Celso Cruz on 9 May 2013
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

Answers (1)

Sean de Wolski
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) % ;) )

Categories

Find more on Parallel Computing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!