このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
Simulink.data.dictionary.setupWorkerCache
データ ディクショナリを使用した並列シミュレーションの有効化
説明
Simulink.data.dictionary.setupWorkerCache
はデータ ディクショナリにリンクされたモデルをシミュレートするための並列プール内でワーカーを準備します。この関数を spmd
(Parallel Computing Toolbox) ブロックで使用し、parfor
(Parallel Computing Toolbox) ブロックを開始する前に並列プール内のワーカーに単一のデータ ディクショナリと安全にやり取りする方法を提供します。
データ ディクショナリにリンクされたモデルの並列シミュレーションの実行中に、各ワーカーは他のワーカーから独立してディクショナリ内のデータにアクセスし変更することができます。Simulink.data.dictionary.setupWorkerCache
はプール内の各ワーカーに所有するデータ ディクショナリ キャッシュを一時的に提供し、ワーカーがディクショナリ内のデータを永久的に変更せずに使用できるようにします。
parfor
(Parallel Computing Toolbox) ブロックを使用して並列シミュレーションを実行するには、Parallel Computing Toolbox™ ライセンスがなければなりません。
例
並列シミュレーションを使用したバリアント制御のスイープ
並列シミュレーションを使用してデータ ディクショナリに保存したバリアント制御 (値が Simulink.Variant
オブジェクトのバリアント条件に影響を与える Simulink.Parameter
オブジェクト) をスイープするには、このコードをテンプレートとして使用します。モデル、データ ディクショナリおよびバリアント制御の名前と値をアプリケーションに一致するように変更します。
ブロック パラメーターの値、あるいはブロック パラメーターを設定するために使用するワークスペース変数の値をスイープするには、データ ディクショナリへのプログラム インターフェイスの代わりに Simulink.SimulationInput
オブジェクトを使用します。ブロック パラメーター値の最適化、推定およびスイープを参照してください。
並列シミュレーションを実行するには、Parallel Computing Toolbox ライセンスがなければなりません。
% For convenience, define names of model and data dictionary model = 'mySweepMdl'; dd = 'mySweepDD.sldd'; % Define the sweeping values for the variant control CtrlValues = [1 2 3 4]; % Grant each worker in the parallel pool an independent data dictionary % so they can use the data without interference spmd Simulink.data.dictionary.setupWorkerCache end % Determine the number of times to simulate numberOfSims = length(CtrlValues); % Prepare a nondistributed array to contain simulation output simOut = cell(1,numberOfSims); parfor index = 1:numberOfSims % Create objects to interact with dictionary data % You must create these objects for every iteration of the parfor-loop dictObj = Simulink.data.dictionary.open(dd); sectObj = getSection(dictObj,'Design Data'); entryObj = getEntry(sectObj,'MODE'); % Suppose MODE is a Simulink.Parameter object stored in the data dictionary % Modify the value of MODE temp = getValue(entryObj); temp.Value = CtrlValues(index); setValue(entryObj,temp); % Simulate and store simulation output in the nondistributed array simOut{index} = sim(model); % Each worker must discard all changes to the data dictionary and % close the dictionary when finished with an iteration of the parfor-loop discardChanges(dictObj); close(dictObj); end % Restore default settings that were changed by the function % Simulink.data.dictionary.setupWorkerCache % Prior to calling cleanupWorkerCache, close the model spmd bdclose(model) Simulink.data.dictionary.cleanupWorkerCache end
メモ
データ ディクショナリが開いている場合は、コマンド Simulink.data.dictionary.cleanupWorkerCache
を使用できません。開いているデータ ディクショナリを特定するには、Simulink.data.dictionary.getOpenDictionaryPaths
を使用します。
バージョン履歴
R2015a で導入
参考
spmd
(Parallel Computing Toolbox) | parfor
(Parallel Computing Toolbox) | Simulink.data.dictionary.cleanupWorkerCache
トピック
- プログラムによるディクショナリへのデータの格納
- データ ディクショナリとは
- 並列プールでのコードの実行 (Parallel Computing Toolbox)