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

조회 수: 3 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by