Simulink モデルを Parallel Computing Toolbox で分散して実行できますか?

Simulink モデルのシミュレーションに関して、以下のいずれかの条件下で、Parallel Computing Toolbox を使って処理を分散できるかどうか、教えてください。
1. 1つの Simulink モデルを異なるコア、プロセッサーもしくはクラスターマシン上で実行する。モデルの実行は、それぞれ異なる独立なパラメータ、データセットにて実行する。
2. 複数の Simulink モデルを異なるコア、プロセッサー、もしくはクラスターマシン上で実行する。

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2026년 5월 19일 0:00
편집: MathWorks Support Team 2026년 5월 19일 4:38

0 개 추천

Simulink モデルで Parallel Computing Toolbox の機能を活用するには、(A) PARFOR による並列シミュレーションを実行する方法と、(B) 分散ジョブを作成してタスクをワーカーに送信する方法があります。
(A) PARFOR による方法については、詳細は以下のドキュメントを参照します。
なお、PARFOR を使用した並列シミュレーションは MATLAB 7.7 ( R2008b ) 以降でのみ利用可能です。
(B) 分散ジョブを使用する場合は、以下のとおりです。
1. Simulink モデルの .mdl ファイルを分散ジョブ内の各ワーカーのファイル依存関係として登録し、モデルが依存するその他のファイルもすべて登録します。また、ネットワーク パスの依存関係も指定します。
2. 各ワーカーが他のワーカーとは独立してモデルをシミュレーションするように指示するため、SIM コマンドをラップした MATLAB ファイル関数を作成します。SIM コマンドの詳細については、以下のドキュメントを参照します。
Simulink モデルのパラメータを通じて、各ワーカーに異なる独立した処理タスクを実行させることができます。以下は、4 つのワーカーそれぞれで異なるデータ セットを処理しながら Simulink モデルを独立に実行する分散ジョブの作成方法の一例です。この例では、'mymodel.mdl' が Simulink モデルであり、'mysimfunc.m' が SIM コマンドをラップした MATLAB 関数ファイルです。
'mysimfunc.m' ファイルは以下のようになります。
function [t,x,y] = mysimfunc(argin1, argin2, ..., arginN)
% Input argument parsing done here
[t,x,y] = sim('mymodel.mdl', ... )
NOTE: 各ワーカーで異なる Simulink モデルを実行する場合は、モデルごとに SIM コマンドをラップした MATLAB ファイルを個別に作成する必要があります。
以下は例です。
% Find the Parallel Computing Toolbox scheduler
sched = findResource('scheduler','type','jobmanager')
% Create a distributed job on the Job Manager
j = createJob(sched)
% Set the file dependencies for the distributed job via the FileDependencies property. % Note that when running a different model on each worker, all MDL-files must be % listed as dependencies.
set(j,'FileDependencies',{'mymodel.mdl','mysimfunc.m', ... ,'mydatafile.dat'});
% Set the path dependencies via the PathDependencies property, where $DIR1, $DIR2, ... $DIRN
% are the directories containing supporting files for the simulation.
set(j,'PathDependencies',{'$DIR1','$DIR2',...,'$DIRN'});
% Create four independent tasks with different input arguments (argins) that determine
% the different model parameters to be used for the simulation on that worker.
% NOTE: If running different models on each worker, then the corresponding SIM
% wrapper MATLAB file name must be specified on each call to createTask for each model.
createTask(j, @mysimfunc, 3, {argin11 argin12 ... argin1N});
createTask(j, @mysimfunc, 3, {argin21 argin22 ... argin2N});
createTask(j, @mysimfunc, 3, {argin31 argin32 ... argin3N});
createTask(j, @mysimfunc, 3, {argin41 argin42 ... argin4N});
% Submit the distributed job to the local scheduler
submit(j);
waitForState(j);
% Get the results of the simulation.
results = getAllOutputArguments(j);
% Once the job is completed, it must be destroyed
destroy(j);
この例は、より複雑なモデルに対応するよう拡張できます。上記で使用されている PCT 関数の詳細については、利用可能な関数一覧が以下のページに記載されています。
なお、分散 Simulink シミュレーションは単一のマルチコア マシンではなくコンピュータ クラスタ上で実行することが推奨されます。これは分散 MATLAB タスクでも同様です。各シミュレーションの実行時間が長い場合、クラスタに分散することでワーカー間の通信や初期化のオーバーヘッドよりも実行時間の削減効果が大きくなります。一方、単一のマルチコア コンピュータでは、すべてのコアが 1 つのメモリ バスを共有するなどの制約があり、性能上の制限要因となります。この考え方は以下の MATLAB ヘルプページでも説明されています。

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel Computing에 대해 자세히 알아보기

제품

릴리스

R2008a

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!