Simulink.sdi.WorkerRun.getLatest
最新の実行のワーカー実行を作成する
説明
は、Parallel Computing Toolbox™ ワーカーでの最新の実行の workerRun
= Simulink.sdi.WorkerRun.getLatestSimulink.sdi.WorkerRun
オブジェクトを作成します。
例
並列シミュレーションのデータにアクセス
さまざまな入力フィルターの時定数でモデル slexAircraftExample
の並列シミュレーションを実行し、シミュレーション データ インスペクターのプログラムによるインターフェイスを使用してさまざまな方法でデータにアクセスします。
設定
シミュレーション データ インスペクターが空であり、Parallel Computing Toolbox のサポートがローカル ワーカーで作成された実行を自動的にインポートするように構成されていることを確認します。次に、各シミュレーションで使用するフィルター パラメーター値のベクトルを作成します。
Simulink.sdi.clear
Simulink.sdi.enablePCTSupport("local")
Ts_vals = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1];
並列ワーカーの初期化
並列シミュレーションを実行するローカル ワーカーのプールを未作成の場合は、関数 gcp
を使用して作成します。spmd
コード ブロックで、slexAircraftExample
モデルを読み込み、ログに記録する信号を選択します。sim
を parfor
で使用する際のデータの同時実行の問題を回避するには、シミュレーション中に使用する一時ディレクトリをワーカーごとに作成します。
p = gcp;
Starting parallel pool (parpool) using the 'Processes' profile ... 02-Nov-2023 16:05:17: Job Queued. Waiting for parallel pool job with ID 1 to start ... 02-Nov-2023 16:06:18: Job Queued. Waiting for parallel pool job with ID 1 to start ... Connected to parallel pool with 6 workers.
spmd % Load system and select signals to log load_system("slexAircraftExample") Simulink.sdi.markSignalForStreaming("slexAircraftExample/Pilot", 1, "on") Simulink.sdi.markSignalForStreaming("slexAircraftExample/Aircraft Dynamics Model", 4, "on") % Create temporary directory on each worker workDir = pwd; addpath(workDir) tempDir = tempname; mkdir(tempDir) cd(tempDir) end
並列シミュレーションの実行
parfor
を使用して 7 つのシミュレーションを並列実行します。各シミュレーションの Ts
の値を選択し、モデル ワークスペースで Ts
の値を変更します。次に、シミュレーションを実行し、Simulink.sdi.WorkerRun
オブジェクトの配列を作成して、シミュレーション データ インスペクターでデータにアクセスします。parfor
ループの後、別の spmd
セグメントを使用して一時ディレクトリをワーカーから削除します。
parfor index = 1:7 % Select value for Ts Ts_val = Ts_vals(index); % Change the filter time constant and simulate modelWorkspace = get_param("slexAircraftExample","modelworkspace"); assignin(modelWorkspace,"Ts",Ts_val) sim("slexAircraftExample"); % Create a worker run for each simulation workerRun(index) = Simulink.sdi.WorkerRun.getLatest end spmd % Remove temporary directories cd(workDir) rmdir(tempDir, "s") rmpath(workDir) end
並列シミュレーション出力から Dataset オブジェクトを取得
関数 getDataset
で WorkerRun
オブジェクトから Dataset
オブジェクトにデータを格納することで、簡単に後処理できるようになります。
ds(7) = Simulink.SimulationData.Dataset; for a = 1:7 ds(a) = getDataset(workerRun(a)); end ds(1)
ans = Simulink.SimulationData.Dataset '' with 12 elements Name BlockPath __________ ________________________________________ 1 [1x1 State ] '' slexAircraftExample/Actuator Model 2 [1x1 Signal] alpha, rad ...rcraftExample/Aircraft Dynamics Model 3 [1x1 State ] '' ...cs Model/Pitch Channel/Integrate qdot 4 [1x1 State ] '' ...mics Model/Vertical Channel/Integrate 5 [1x1 State ] '' ...ntroller/Alpha-sensor Low-pass Filter 6 [1x1 State ] '' ...ller/Integrator/Continuous/Integrator 7 [1x1 State ] '' ...ple/Controller/Pitch Rate Lead Filter 8 [1x1 State ] '' ...aftExample/Controller/Stick Prefilter 9 [1x1 State ] '' .../Dryden Wind Gust Models/Q-gust model 10 [1x1 State ] '' .../Dryden Wind Gust Models/W-gust model 11 [1x1 Signal] Stick slexAircraftExample/Pilot 12 [1x1 Signal] alpha, rad slexAircraftExample/alpha, rad - Use braces { } to access, modify, or add elements using index.
並列シミュレーション出力から DatasetRef
オブジェクトを取得
ビッグ データのワークフローの場合は、関数 getDatasetRef
を使用して WorkerRun
に関連付けられているデータを参照します。
for b = 1:7 datasetRef(b) = getDatasetRef(workerRun(b)); end datasetRef(1)
ans = DatasetRef with properties: Name: 'Run <run_index>: <model_name>' Run: [1×1 Simulink.sdi.Run] numElements: 12
シミュレーション データ インスペクターで並列シミュレーション データを処理
ローカルの Simulink.sdi.Run
オブジェクトを作成し、シミュレーション データ インスペクターのプログラムによるインターフェイスを使用してデータの解析と可視化を行うこともできます。この例では、各実行に対するフィルター時定数値を示すタグを示します。
for c = 1:7 Runs(c) = getLocalRun(workerRun(c)); Ts_val_str = num2str(Ts_vals(c)); desc = strcat("Ts = ", Ts_val_str); Runs(c).Description = desc; Runs(c).Name = strcat("slexAircraftExample run Ts=", Ts_val_str); end
ワーカー リポジトリをクリーンアップ
ワーカーが使用したファイルをクリーンアップし、ワーカー プールで実行するその他のシミュレーション用にディスク容量を解放します。
Simulink.sdi.cleanupWorkerResources
バージョン履歴
R2017b で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)