필터 지우기
필터 지우기

Should parallelization be switched on manually

조회 수: 1 (최근 30일)
Serg Brylin
Serg Brylin 2015년 7월 1일
댓글: Steven Lord 2015년 7월 1일
Hi there! I would like to know whether parallelization in Matlab switches on automatically or should I do that manually. I have a code to solve an optimization problem (determining constants in kinetic equations, ODE), and I start with many initial guesses(doing Latin hypercube sampling). Last time I run my program, it took approx. 6 hours. Here is the code I am running:
load matlab S data input
dimS = size(S);
rankS = rank(S);
td=data(:,1);
xd=data(:,2);
p = 1000; % Number of points (samples)
N = 8; % Number of dimensions
lb = [0.00001 0.000002 0.00045 0.01 0.0001 0.00001 0.0002 0.000001]; % lower bounds
ub = [0.5 0.5 0.5 1 0.5 0.5 0.5 0.5]; % upper bounds
X = lhsdesign(p,N,'criterion','correlation');
D = bsxfun(@plus,lb,bsxfun(@times,X,(ub-lb)));
for i=1:size(D,1)
k0(i,:)=D(i,:);
options =optimset('Display','off','LargeScale','off','MaxFunEvals',2000);
ke=lsqnonlin(@myobjective,k0(i,:),[1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5],[],options, td, xd, input, S);
k_all(i,:)=ke(1,:);
end

답변 (3개)

Matt J
Matt J 2015년 7월 1일
Its usual internal multithreading should be enabled by default, but you can check with
>>maxNumCompThreads

Titus Edelhofer
Titus Edelhofer 2015년 7월 1일
Hi,
on first sight it looks as if the loop on D
for i=1:size(D,1)
k0(i,:)=D(i,:);
options =optimset('Display','off','LargeScale','off','MaxFunEvals',2000);
ke=lsqnonlin(@myobjective,k0(i,:),[1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5,1e-5],[],options, td, xd, input, S);
k_all(i,:)=ke(1,:);
end
could be parallelized using parfor and the Parallel Computing Toolbox ...
Titus
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2015년 7월 1일
This is probably a better option than the 'UseParallel' flag, parallelize out as far as possible.

댓글을 달려면 로그인하십시오.


Sean de Wolski
Sean de Wolski 2015년 7월 1일
If you have the Parallel Computing Toolbox, you can turn on Parallel Computing using the 'UseParallel' flag in optimset (or optimoptions).
The speedup will vary but if there is a high number of dimensions it can help significantly for gradient calculations.
  댓글 수: 2
Matt J
Matt J 2015년 7월 1일
I don't see a "UseParallel" option in the lsqnonlin documentation...
Steven Lord
Steven Lord 2015년 7월 1일
Not all of the options are available for all of the solvers, and even when an option is available for one of the solvers it may not be available for all the algorithms that solver can use. So for this particular situation Sean's answer doesn't apply, but in general it's something to consider when using Optimization Toolbox (or PARTICLESWARM in Global Optimization Toolbox, according to the OPTIMOPTIONS page.)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by