Does using global variables in objective function risk error when using ga in parallel?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Rakesh Kumar
2015-5-8
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 个评论
Rakesh Kumar
2015-5-11
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computational Fluid Dynamics (CFD) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!