Simulink.sdi.sendWorkerRunToClient
並列ワーカーで作成された実行をシミュレーション データ インスペクターに送信
説明
例
この例では、並列ワーカーを使用して作成された実行をSimulink.sdi.sendWorkerRunToClientを使用して手動でシミュレーション データ インスペクターに送信する方法について説明します。
設定
この例では、Gain ブロックの値 Mu を変化させて、vdp モデルの複数のシミュレーションを実行します。並列シミュレーションを設定するには、Mu 値のベクトルを定義し、手動による Parallel Computing Toolbox™ のサポート用にシミュレーション データ インスペクターを設定します。
MuVals = [0.1 0.2 0.3 0.4];
Simulink.sdi.enablePCTSupport("manual");並列ワーカーの初期化
parpool (Parallel Computing Toolbox)を使用して 4 つの並列ワーカーのプールを開始します。この例では if ステートメント内の parpool を呼び出すため、作成するのは並列プールのみです (まだない場合)。
p = gcp("nocreate"); if isempty(p) parpool(4); end
Starting parallel pool (parpool) using the 'Processes' profile ... 11-Sep-2024 11:23:03: Job Queued. Waiting for parallel pool job with ID 1 to start ... Connected to parallel pool with 4 workers.
spmd (Parallel Computing Toolbox)を使用してすべてのワーカーに共通の初期化コードを実行できます。たとえば、vdp モデルを読み込み、関数 Simulink.sdi.markSignalForStreaming でシミュレーション データ インスペクターにログを記録する信号を選択します。parfor 内の sim でシミュレーションを実行する場合にデータの同時実行の問題を回避するには、各ワーカーに一時ディレクトリを作成します。
spmd load_system("vdp") Simulink.sdi.markSignalForStreaming("vdp/x1",1,"on") Simulink.sdi.markSignalForStreaming("vdp/x2",1,"on") workDir = pwd; addpath(workDir) tempDir = tempname; mkdir(tempDir) cd(tempDir) end
parfor を使用した並列シミュレーションの実行
並列ワーカーからシミュレーション データ インスペクターにデータをストリーミングするには、parfor (Parallel Computing Toolbox)を使用して並列シミュレーションを実行します。各ワーカーは Mu の異なる値を使用して vdp シミュレーションを実行します。parfor ループの内容にはアクセスできないため、変数 MuVal がワーカーのワークスペースで定義されます。この場合、assigninを使用して vdp モデルで内容を表示できます。
parfor (index = 1:4) assignin("base","MuVal",MuVals(index)); set_param("vdp/Mu","Gain","MuVal") sim("vdp");
Warning: Unable to open 'vdp/Scope' because you are simulating the model using parsim. Clear the 'Open at Simulation Start' parameter or simulate the model without using parsim. Warning: Unable to open 'vdp/Scope' because you are simulating the model using parsim. Clear the 'Open at Simulation Start' parameter or simulate the model without using parsim. Warning: Unable to open 'vdp/Scope' because you are simulating the model using parsim. Clear the 'Open at Simulation Start' parameter or simulate the model without using parsim. Warning: Unable to open 'vdp/Scope' because you are simulating the model using parsim. Clear the 'Open at Simulation Start' parameter or simulate the model without using parsim.
データにアクセスしてクライアント MATLAB に実行を送信
クライアント MATLAB® で使用する場合と同じ方法で、ワーカーでシミュレーション データ インスペクターのプログラムによるインターフェイスを使用できます。この例では、Simulink.sdi.Runオブジェクトを作成し、Tag プロパティを使用したシミュレーションで使われた Mu の値を付加します。
IDs = Simulink.sdi.getAllRunIDs;
lastIndex = length(IDs);
runID = Simulink.sdi.getRunIDByIndex(lastIndex);
parRun = Simulink.sdi.getRun(runID);
parRun.Tag = strcat("Mu = ",num2str(MuVals(index)));
Simulink.sdi.sendWorkerRunToClient
end一時ディレクトリを閉じてシミュレーション データ インスペクターで実行を表示
シミュレーションが完了したら、別の spmd セクションを使用してワーカーで作成された一時ディレクトリを削除します。
spmd cd(workDir) rmdir(tempDir,"s") rmpath(workDir) end
各シミュレーションで、関数 Simulink.sdi.sendWorkerRunToClient はすべてのワーカーからシミュレーション データ インスペクターに実行をインポートしました。データを表示して実行プロパティを確認し、シミュレーション中に使われた Mu の値を確認できます。
Simulink.sdi.view
入力引数
シミュレーション データ インスペクターにインポートする実行に対応する実行 ID または Simulink.sdi.Run オブジェクト。
バージョン履歴
R2018a で導入
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)