why does (ga + parallel + global variables + sub2ind) fail?

1 回表示 (過去 30 日間)
Jochen Schuettler
Jochen Schuettler 2016 年 9 月 9 日
回答済み: Jochen Schuettler 2016 年 9 月 12 日
When optimizing with ga and parallel computing, a sub2ind call using globals fails (subscript vectors must be of same size), but when doing it in serial, it doesn't fail. Why?

採用された回答

Matt J
Matt J 2016 年 9 月 9 日
Probably because of the dangers of using global variables.
  5 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 11 日
Note that the above discussion is only for serial computing. The considerations are a bit different for parallel computing, where each worker must have a copy of the data because they are different processes.
Matt J
Matt J 2016 年 9 月 11 日
編集済み: Matt J 2016 年 9 月 11 日
The discussion still applies to parallel computing if we're not talking about the one-time cost of broadcasting constant data to the workers. The OP seems to think that arguments passed to the fitness function will be copied "again and again" each time the fitness function is called. That is not true, even on parallel workers

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 9 月 10 日
Global variables are never copied to parallel workers.
You might be able to take advantage of parallel.pool.Constant or of parfevalOnAll() to initialize the variable on all of the workers.
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 11 日
If you have especially large shared data, you could also use the File Exchange contribution https://www.mathworks.com/matlabcentral/fileexchange/28572-sharedmatrix to use shared memory. This will only work if the compute nodes are on the same host, though

サインインしてコメントする。


Jochen Schuettler
Jochen Schuettler 2016 年 9 月 12 日
Thanks to everyone!

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by