Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
use parallel option in ga algorithm and parfor

Subject: use parallel option in ga algorithm and parfor

From: lena

Date: 12 Jul, 2013 21:12:07

Message: 1 of 1

I was reading ( about combining parfor and Parallel optimizatioin. It seems that some people suggest that it may actually be possible to take advantage of parallelll loops when they are inside of the optimization routine.

I have fixed up the following example. But i only have 4 workers on this machine and when i include the parfor inside the objective function routine running time goes up (this is not surprising). I am wondering that if I actually had excess capacity i.e. 100 workers and the size of initial population set to 12. Would using parfor inside the objective function speed things up?
% create fake data to use in the estimation
% create a vector y Nx1 and vector x Nx1


%set up options structure for
needNewWorkers = (matlabpool('size') == 0);
if needNewWorkers
    matlabpool open 4
options = gaoptimset;
 options = gaoptimset(options,'PopulationSize', 3);
options = gaoptimset(options,'MutationFcn', { @mutationadaptfeasible 5 [] });
options = gaoptimset(options,'Display', 'iter');
options = gaoptimset(options,'FitnessLimit', 0);
options = gaoptimset(options,'UseParallel', 'always');
options = gaoptimset(options,'Generations', 100);
% call ga function
[beta fval] = ga(@(beta)fitnessfun(beta,x,y), nvars, options);

% objective function called by ga
% Create fitness function
function obj=fitnessfun(beta,x,y)
parfor i=1:100
%create e_simulated




Sincerely , Lea

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us