I'm comparing execution times between two blocks, one using parfor
the other doing the same thing by issuing parfeval
and fetching outputs:
parfor k = 1:N
a = rand(5000);
b = inv(a);
end
vs.
for k = 1:N
a = rand(5000);
F(k) = parfeval(p,'inv',1,a);
end
for k = 1:N
[completedIdx,value] = fetchNext(F);
fprintf(1,'%d ',completedIdx);
end
The parfor
is consistently faster. Any insights into why that is the case? My simplistic understanding is parfor
essentially runs each loop as a parallel job.