For models that contain large model reference hierarchies, you can reduce code generation and compilation time by building the referenced models in parallel. With Parallel Computing Toolbox™ software, you can distribute the code generation and compilation for referenced models across a parallel pool of MATLAB® workers. If you also have MATLAB Parallel Server™ software, you can distribute the code generation and compilation across remote workers in your MATLAB Parallel Server configuration.
To build referenced models in parallel:
Open the Configuration Parameters dialog box for the top model of the model hierarchy.
Select the Enable parallel model reference builds check box.
For each MATLAB worker, you can set up a MATLAB environment that is consistent with the MATLAB environment of the client. From the MATLAB worker initialization for builds drop-down list, select one of these values:
None
–– Simulink® does not initialize workers.
Copy base workspace
–– Simulink attempts to copy the base workspace to each
MATLAB worker.
Load top model
–– Simulink loads the top model onto each MATLAB worker.
Build your model from the command line or the Simulink Editor Code perspective:
Command line –– Use, for example, rtwbuild
or slbuild
. The
build process displays build log messages in the Command
Window.
Simulink Editor Code perspective –– Click the Build button. The build process displays build log messages in the Diagnostic Viewer.
If a parallel pool of MATLAB workers is not running when you build your model,
MATLAB automatically opens a parallel pool of workers
using the default cluster profile. To change the default
behaviour of the worker cluster, you can modify properties of
the cluster profile. If you have not touched your parallel
preferences, the default profile is local
.
Control parallel behavior with the parallel preferences,
including scaling up to a cluster, automatic pool creation, and
preferred number of workers. For more information, see Discover Clusters and Use Cluster Profiles (Parallel Computing Toolbox).
For more general information about parallel computing, see Run MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).
Through the Build Status window, you can:
View the overall build progress for a model hierarchy.
View the build status of individual models in the model hierarchy.
Cancel the parallel build process.
Note
The Build Status window supports only parallel building of model hierarchies. Do not use the Build Status window for serial builds.
To open the Build Status window, use one of these line commands:
coder.buildstatus.open('
model
')
rtwbuild('
model
', ...
'OpenBuildStatusAutomatically',true)
slbuild('
model
','StandaloneCoderTarget',
... 'OpenBuildStatusAutomatically',true)
This example shows how you can monitor the build process for a model hierarchy. In
the hierarchy, rtwdemo_parabuild_a_1
references
rtwdemo_parabuild_b_1
,
rtwdemo_parabuild_b_2
, and rtwdemo_parabuild_b_3
.
Copy the model files to a local folder.
src_dir = ... fullfile(matlabroot,'toolbox','rtw','rtwdemos'); if exist(fullfile('.','myTempFolder'),'dir') rmdir('myTempFolder','s') end mkdir myTempFolder copyfile(fullfile(src_dir,'rtwdemo_parabuild_a_1.slx'), ... 'myTempFolder'); copyfile(fullfile(src_dir,'rtwdemo_parabuild_b_1.slx'), ... 'myTempFolder'); copyfile(fullfile(src_dir,'rtwdemo_parabuild_b_2.slx'), ... 'myTempFolder'); copyfile(fullfile(src_dir,'rtwdemo_parabuild_b_3.slx'), ... 'myTempFolder'); cd myTempFolder
Open the top model.
open_system('rtwdemo_parabuild_a_1')
View the model dependencies with the Dependency Analyzer. On the Modeling tab, on the far right of the Design section, click the arrow. Then, under System Design, click Dependency Analyzer.
Start parallel building of the model hierarchy and open the Build Status window.
rtwbuild('rtwdemo_parabuild_a_1','OpenBuildStatusAutomatically',true)
The Build Status window displays the overall build progress and the build status for models as the code generator works through the model hierarchy.
This table explains the Status column values.
Status | Description |
---|---|
Blocked | The code generator cannot schedule the model build because the build is blocked by dependencies. For example, a child model build is not complete. |
Scheduled | In parallel building, the code generator schedules a model
build when the build is not blocked by dependencies. The status
of the model build is |
Building | The model is being built on a worker. |
Completed | When a model is built without errors, the status changes to
|
Error | If the model build fails, the status changes to
|
Up To Date | Code generation is not required for the model because the current generated code is up to date. |
Canceling | When you click the Cancel Build
button, the build process changes the status of incomplete
builds to |
Canceled | The canceling operation is complete. |
The Elapsed Time column shows the build times for models in the hierarchy. To reduce the total build time, analyse the build times for referenced models together with model dependency information. Then, consider, for example:
Restructuring the referenced model hierarchy.
Increasing the number of workers in the parallel pool.
coder.buildstatus.close
| coder.buildstatus.open
| rtwbuild
| slbuild