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

Thread Subject:
GA parallel computing toolbox error

Subject: GA parallel computing toolbox error

From: Dave Brackett

Date: 20 Aug, 2008 14:16:03

Message: 1 of 4

Hi, I have a genetic algorithm optimization function which
I am trying to run using the parallel computing toolbox as
explained here:
http://www.mathworks.com/access/helpdesk/help/toolbox/gads/i
ndex.html?/access/helpdesk/help/toolbox/gads/f7928.html&http
://www.google.co.uk/search?
hl=en&q=matlab+custom+plot+function&meta=

The GA works fine without running it in parallel, but when
I open the matlabpool, the GA then returns the following
error: ??? Error using ==> makeState at 50
GA cannot continue because user supplied fitness function
failed with the following error:
Error using ==> reshape
To RESHAPE the number of elements must not change.

From the debugger, this appears to be happening when it is
trying to score each member of the population:

% Score each member of the population
    if strcmpi(options.Vectorized, 'off')
        try
            Score = fcnvectorizer(state.Population
(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserF
cn);
        catch
            error('gads:makestate:fitnessCheck', ...
                'GA cannot continue because user supplied
fitness function failed with the following error:\n%s',
lasterr)
        end

Anyone any ideas why this would be happening? I'm not sure
what details of my code are needed so feel free to ask for
additional information. My version is 2008a (7.6.0.324).

Thanks.

Subject: GA parallel computing toolbox error

From: Dave Brackett

Date: 20 Aug, 2008 15:47:02

Message: 2 of 4

> I am trying to run using the parallel computing toolbox
as
> explained here:
>
http://www.mathworks.com/access/helpdesk/help/toolbox/gads/i
>
ndex.html?/access/helpdesk/help/toolbox/gads/f7928.html&http
> ://www.google.co.uk/search?
> hl=en&q=matlab+custom+plot+function&meta=

Sorry, the correct url for this is

http://www.mathworks.com/access/helpdesk/help/toolbox/gads/i
ndex.html?/access/helpdesk/help/toolbox/gads/f7928.html

Subject: GA parallel computing toolbox error

From: Dave Brackett

Date: 21 Aug, 2008 10:09:02

Message: 3 of 4

As i am using global variables i wonder if it is related to
this:

"Persistent or global variables. If your objective or
constraint functions use persistent or global variables,
these variables may take different values on different
worker processors. Furthermore, they may not be cleared
properly on the worker processors."

Does anyone know how to use local variables with the GA
objective function?

Subject: GA parallel computing toolbox error

From: Dave Brackett

Date: 26 Aug, 2008 13:25:03

Message: 4 of 4

> Does anyone know how to use local variables with the GA
> objective function?

I have since solved this problem myself. To pass variables
to a GA the fitness function must be specified as shown in
the example below:

FitnessFcn=@(x)m_file_fitness_calc(x,other variables...)

then the ga is called using as: ga(FitnessFcn,other
options...) etc.

Global variables was indeed causing the initial problem and
once changed into local varibles using this method, the
errors were eliminated.

Tags for 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