Does using global variables in objective function risk error when using ga in parallel?
4 views (last 30 days)
Show older comments
Hi,
I am using the optimization toolbox with a relatively complicated computational fluid dynamics tool I have written as the objective function. The tool uses global variables within it becuase it was convenient when I wrote it. Some of these variables are simulation specific and will change based on the optimization input.
My question is, when I use the ga tool in parallel, is there a risk of the global variables becoming confused because simultaneous simulations are being performed on different processors? Or will the global variables be kept private to each processor?
Thank you,
W. S. H.
UPDATE:
Instead of spending excessive time trying to figure out what was going on with my problems, I spent a couple hours modifying my tool to use only private variables. This fixed the issues I was having. So not sure what the problem was in my case, but the lesson here is be VERY CAREFUL if trying to use global variables in this type of problem.
0 Comments
Answers (1)
Rakesh Kumar
on 8 May 2015
Every worker will have its own copy of the global variable not in sync with other workers. Its global for all the M-files on a worker but not for all workers.
I do not fully understand your usage but if global variables depend on (previous) simulation then I don't see any easy way you can use them in parallel.
See this blog (section on globals) http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/
Rakesh
2 Comments
Rakesh Kumar
on 11 May 2015
Are there constraints in the problem? Are you using HybridFcn option? The 'optimization run reported...' are the arguments returned by GA or iterative display?
Please send the iterative display (The last few iterations and stopping message), the final output you get from GA and show how it does not match? This may give some clue.
Thanks,, Rakesh
See Also
Categories
Find more on Fluid Dynamics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!