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.
Why does multiobjective genetic algorithm optimization fail with parallel or vectorization on?
1 view (last 30 days)
Show older comments
bumblethumbs
on 21 Feb 2017
Commented: bumblethumbs
on 21 Feb 2017
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
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.
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!