Main Content

Simulink.data.dictionary.cleanupWorkerCache

データ ディクショナリを使用した並列シミュレーション後に既定の設定に戻す

説明

Simulink.data.dictionary.cleanupWorkerCache はデータ ディクショナリにリンクされたモデルの並列シミュレーションが終了した後に既定の設定に戻します。parfor (Parallel Computing Toolbox) ブロックを使用して並列シミュレーションが終了したら、この関数を spmd (Parallel Computing Toolbox) ブロックで使用して、関数 Simulink.data.dictionary.setupWorkerCache によって変更された設定を既定に戻します。

データ ディクショナリにリンクされたモデルの並列シミュレーションの実行中に、各ワーカーは他のワーカーから独立してディクショナリ内のデータにアクセスし変更することができます。関数 Simulink.data.dictionary.setupWorkerCache は各ワーカーにデータへの個別アクセスを許可する一意のディクショナリ キャッシュを付与し、関数 Simulink.data.dictionary.cleanupWorkerCache はキャッシュの設定を既定値に戻します。

parfor (Parallel Computing Toolbox) ブロックを使用して並列シミュレーションを実行するには、Parallel Computing Toolbox™ ライセンスがなければなりません。

並列シミュレーションを使用したバリアント制御のスイープ

並列シミュレーションを使用してデータ ディクショナリに保存したバリアント制御 (値が Simulink.VariantExpression オブジェクトのバリアント条件に影響を与える 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 で導入