Reduce Build Time for Referenced Models by Using Parallel Builds - MATLAB & Simulink (original) (raw)

Main Content

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.

Build Referenced Models in Parallel

To build referenced models in parallel:

  1. Open the Configuration Parameters dialog box for the top model of the model hierarchy.
  2. Select the Enable parallel model reference builds check box.
  3. 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.
  4. Build your model from the command line or the Simulink Editor Code perspective:
    • Command line –– Use, for example, slbuild. The build process displays build log messages in the Command Window.
    • Simulink Editor Code perspective –– Click theBuild button. The build process displays build log messages in the Diagnostic Viewer.
      If the Parallel Computing Toolbox parallel setting Automatically create a parallel pool is selected, a parallel pool of MATLAB workers is automatically started. For more information, see Specify Your Parallel Settings (Parallel Computing Toolbox).
      If a parallel pool of MATLAB workers is not running when you build your model, MATLAB automatically opens a parallel pool of workers by using the default cluster profile. To change the default behavior of the worker cluster, you can modify properties of the cluster profile. If you have not touched your parallel settings, the default profile is local. Control parallel behavior with the parallel settings, 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, seeRun MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).

Monitor Parallel Building of Referenced Models

Through the Build Status window, you can:

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:

This example shows how you can monitor the build process for a model hierarchy. In the hierarchy, ParallelBuildA1 references ParallelBuildB1, ParallelBuildB2, and ParallelBuildB3.

Open the top model.

open_system('ParallelBuildA1');

parallelbuilda1model.png

View the model dependencies with the Dependency Analyzer. On the Modeling tab, in Design section, click the down arrow to expand the Design gallery. Under Dependencies, click Dependency Analyzer.

parallelbuilda1dependencies.png

Start parallel building of the model hierarchy and open the Build Status window.

slbuild('ParallelBuildA1','OpenBuildStatusAutomatically',true)

Searching for referenced models in model 'ParallelBuildA1'.

Total of 4 models to build.

Initializing workers for parallel model reference build.

Parallel worker initialization complete.

Starting parallel code generation build.

Successfully updated the model reference code generation target for: ParallelBuildB1

Successfully updated the model reference code generation target for: ParallelBuildB2

Successfully updated the model reference code generation target for: ParallelBuildB3

Starting build procedure for: ParallelBuildA1

Successful completion of build procedure for: ParallelBuildA1

Build Summary

Model reference code generation targets:

Model Build Reason Status Build Duration

ParallelBuildB1 Target (ParallelBuildB1.c) did not exist. Code generated and compiled. 0h 0m 19.387s ParallelBuildB2 Target (ParallelBuildB2.c) did not exist. Code generated and compiled. 0h 0m 19.432s ParallelBuildB3 Target (ParallelBuildB3.c) did not exist. Code generated and compiled. 0h 0m 19.406s

Top model targets:

Model Build Reason Status Build Duration

ParallelBuildA1 Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 19.703s

4 of 4 models built (0 models already up to date) Build duration: 0h 0m 56.727s

Cleaning up parallel workers.

The Build Status window displays the overall build progress and the build status for models as the code generator works through the model hierarchy.

Build Status display.png

The Suggested Pool Size value indicates what pool size you can use to achieve the fastest build time.

The Status column can display these values:

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:

See Also

slbuild | coder.buildstatus.open | coder.buildstatus.close

Topics