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

3 vues (au cours des 30 derniers jours)
Jochen Schuettler
Jochen Schuettler le 9 Sep 2016
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?

Réponse acceptée

Matt J
Matt J le 9 Sep 2016
Probably because of the dangers of using global variables.
  5 commentaires
Walter Roberson
Walter Roberson le 11 Sep 2016
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 le 11 Sep 2016
Modifié(e) : Matt J le 11 Sep 2016
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

Connectez-vous pour commenter.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 10 Sep 2016
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 commentaire
Walter Roberson
Walter Roberson le 11 Sep 2016
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

Connectez-vous pour commenter.


Jochen Schuettler
Jochen Schuettler le 12 Sep 2016
Thanks to everyone!

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by