Should parallelization be switched on manually

1 Ansicht (letzte 30 Tage)
Serg Brylin
Serg Brylin am 1 Jul. 2015
Kommentiert: Steven Lord am 1 Jul. 2015
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

Antworten (3)

Matt J
Matt J am 1 Jul. 2015
Its usual internal multithreading should be enabled by default, but you can check with
>>maxNumCompThreads

Titus Edelhofer
Titus Edelhofer am 1 Jul. 2015
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 Kommentar
Sean de Wolski
Sean de Wolski am 1 Jul. 2015
This is probably a better option than the 'UseParallel' flag, parallelize out as far as possible.

Melden Sie sich an, um zu kommentieren.


Sean de Wolski
Sean de Wolski am 1 Jul. 2015
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 Kommentare
Matt J
Matt J am 1 Jul. 2015
I don't see a "UseParallel" option in the lsqnonlin documentation...
Steven Lord
Steven Lord am 1 Jul. 2015
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.)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by