Why is EACH function evaluation inside a parfor loop much faster then ONE evaluation outside the loop?
1 vue (au cours des 30 derniers jours)
Basically I calculate a finite difference Jacobian of a function, as shown below.
The function evaluation labelled SINGLE RUN takes about 60 seconds, and the ones labelled PARALLEL RUN take about 20 seconds.
Any clue why this might be?
Note: the "dx=0.1" does not have any influence on the speed of myfun.
myfun = @(x).... %the function of interest, which has a tic/toc inside it
[Jac] = jacob_paral(myfun,x0)
function [Jac] = jacob_paral(myfun,x0)
y0 = feval(myfun,x0);
nn = length(x0);
Jac = NaN(length(y0),nn);
parfor ix = 1:nn
dx = zeros(1,nn)
dx(ix) = 0.01;
x = x0+dx;
y = feval(myfun,x);
Jac(:,ix) = (y-y0)./dx(ix)