MATLAB Answers

Why is EACH function evaluation inside a parfor loop much faster then ONE evaluation outside the loop?

2 ビュー (過去 30 日間)
Sargondjani 2021 年 1 月 16 日
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)

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by