Should parallelization be switched on manually

1 vue (au cours des 30 derniers jours)
Serg Brylin
Serg Brylin le 1 Juil 2015
Commenté : Steven Lord le 1 Juil 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

Réponses (3)

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

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

Connectez-vous pour commenter.


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

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by