フィルターのクリア

global variables Pattern Search

6 ビュー (過去 30 日間)
Andrea Agosti
Andrea Agosti 2020 年 4 月 1 日
コメント済み: Andrea Agosti 2020 年 4 月 1 日
Hi!
i'm using Pattern Search with a custom output function that at the end each iteration is updating a global variable. Is it true that if i'm activating the parallelisation of the PS i cannot use global variables?
  2 件のコメント
Rik
Rik 2020 年 4 月 1 日
Based on your previous question I think this doc page could help you find a solution.
Andrea Agosti
Andrea Agosti 2020 年 4 月 1 日
thanks! Very clear

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

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 1 日
編集済み: Walter Roberson 2020 年 4 月 1 日
No, that is not true. You can use global variables with parallelisation.
However, the initial value of the global variables will not be transferred to the workers, and the workers do not share the global variable with each other -- you cannot use global to communicate between the workers. Also, the value of the global variables will not be copied back from the workers to the client.
In order to initialize or retrieve the global variables, you end up needing to use parfevalOnAll.
global variables are global to their process, but are not shared between processes.
If you just need to initialize something on all workers and the value does not need to be changed, then consider using https://www.mathworks.com/help/parallel-computing/parallel.pool.constant.html
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 4 月 1 日
If changing the global variables is for output only (keeping a record of intermediate values for example) then you can still do that, and use parfevalOnAll to retrieve the results afterwards. You might possibly want to tag each result with the loop control variable value, or with the lab ID, if you need to unwrap into linear order like you would get on a single process.
If changing the global variables is for the purpose of changing the search while the search is still running, then you would be violating the principle in most minimization algorithms that when if you were to run with the same parameters again, that you would get the same result (yes, this does mean that you shouldn't be using randomness unless you are controlling the random seed.) This is mathematically required for patternsearch and fmincon, but is not required for ga() or gamultiobj() -- but remember that reporting the resulting parameter vector is meaningless if those parameters no longer give the same output.
Andrea Agosti
Andrea Agosti 2020 年 4 月 1 日
very clear! Many thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurrogate Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by