필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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)
%SINGLE RUN:
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;
%PARALLEL RUN:
y = feval(myfun,x);
Jac(:,ix) = (y-y0)./dx(ix)
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by