Why does multiobjective genetic algorithm optimization fail with parallel or vectorization on?

1 view (last 30 days)
I am using the multiobjective GA optimization with 5 variables and 2 objectives. Everything works fine in serial mode.
My system returns NaN from the function using parallel mode and complains that the function needs to return a vector of length equal to population. Of course, this cannot be true, because it is a multiobjective function, it will not be a vector but an array. Still, I even put a checking step to output the length of the array and it is correct.
I am using global variables in the function itself. The function gives the input vector to a set of neural networks, and returns their response. Then the various results of the neural network ensembles are collected and returned.
The size of the output is equal to [number_of_objectives populationSize], as verified by the output. After the end of the first generation the solver stops and gives the report that the function must return a vector of length equal to the population.
How can a multiobjective function only return a [1 x populationSize] and still work?
Even more strange, parallel mode works, but always returns NaN from the function. I have passed the function vectorized inputs in the normal command window and it returns things as expected.
Any ideas what is wrong? My global variable is a cell array of neural networks. I can post the code, but it isn't likely to be the issue. Still, I will make it available if necessary.
  2 Comments
bumblethumbs
bumblethumbs on 21 Feb 2017
Update: I copied the global variables to local copies as suggested in other parallel literature, and while this worked well, it does use a lot more memory. Fortunately that is an acceptable solution. Any other suggestions would be considered helpful.
Walter Roberson
Walter Roberson on 21 Feb 2017
You can use the shared memory approach I pointed to in my link. But not, I suspect, for global variables. Or perhaps yes for global variables if you share the memory and then assign to a global, counting on copy-on-write.
Note: global variables are the slowest variables of all. If you want fast execution you should not use them.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Feb 2017
global variables are not shared with workers in the Parallel Computing Toolbox. You would have to assign relevant values on all of the workers; for example you can use parfEvalOnAll; see also https://www.mathworks.com/matlabcentral/answers/302511-why-does-ga-parallel-global-variables-sub2ind-fail
  1 Comment
bumblethumbs
bumblethumbs on 21 Feb 2017
Thanks! I followed a few links there and was able to quickly see why parallel processing was failing. Vectorization was faster, in the end, but the solutions in the above link helped me see other methods for getting data to the function from the workspace without the global type. Since I was not needing to write to the networks the reference method of a read only copy per worker was acceptable. Thanks for the help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!