PARFOR 内で SIM コマンドが動作しないのはなぜですか?
4 views (last 30 days)
Show older comments
MathWorks Support Team
on 1 Feb 2013
Edited: MathWorks Support Team
on 21 Jul 2017
Parallel Computing Toolbox または MATLAB Distributed Computing Server を使用して以下のプログラムを実行するとエラーとなります。
プログラム:
parfor (i=1:4)
sim('vdp');
end
エラーメッセージ: ERROR: ??? Error using ==> parallel_function>make_general_channel/channel_general at 844 Error using ==> sim Transparency violation error. See Parallel for Loops in MATLAB, "Transparency". Error in ==> parallel_function>distributed_execution at 741 [tags, out] = P.getCompleteIntervals(chunkSize); Error in ==> parallel_function at 553 R = distributed_execution(...
Accepted Answer
MathWorks Support Team
on 21 Jul 2017
Edited: MathWorks Support Team
on 21 Jul 2017
PARFOR の中で sim 関数を使用するためには、sim 関数の透過性に注意する必要があります。
透過性とは、処理の分配先であるワーカーにおいて参照する変数名やパス情報のことです。もし、プログラムがワークスペース上の変数にアクセスするのであれば、このプログラムは透過性がありません。
>> sim('vdp')
はワークスペース上の変数上に値を記録するため、透過性はありません。
透過性を確保するために、以下のように sim 関数をローカルの関数内で使用する方法があります。
% sim 関数を別のローカル関数内で定義
function x = parallel_sim(mdl)
[t,x,u] = sim(mdl)
end
メインのコードでは、以下のように parallel_sim を呼び出します。
parfor (i=1:4)
x{i} = parallel_sim('vdp');
end
0 Comments
More Answers (0)
See Also
Categories
Find more on 並列 for ループ (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!