Documentation

Speed Up Simulation

Performance of Model Update

Stateflow® uses Just-In-Time (JIT) compilation mode to improve model update performance of most charts. Stateflow applies JIT mode to charts that qualify. For a chart in JIT mode, Stateflow generates an execution engine in memory for simulation. For these charts, Stateflow does not generate C code or a MEX file to simulate the chart. JIT mode provides the best performance during the compilation of a model.

Some charts do not qualify for JIT mode, such as charts with:

  • Debugging breakpoints set

  • Custom C code symbols

  • Signal logging

  • Model Coverage in Simulink® Verification and Validation™

For charts that do not qualify for JIT mode, Stateflow generates C code with debugging support. The C code is built into an executable file that is used during simulation.

To gain optimal performance for charts that do not qualify for JIT mode, turn off debugging using this command.

sfc('coder_options', 'forceDebugOff', 1);

After you run this command, these charts do not have debugging, animation, or run-time error checking.

Disable Simulation Target Options That Impact Execution Speed

To simulate your model more quickly, disable the following options as described.

  1. Open the Model Configuration Parameters dialog box and select the Simulation Target pane.

  2. Clear any of these options:

    • Detect wrap on overflow — Clear this check box to disable overflow detection of Stateflow data in the generated code. Overflow occurs for data when a value is assigned to it that exceeds the numeric capacity of its type. The Detect wrap on overflow option is important for fixed-point data. For more information, see Detect Overflow for Fixed-Point Types. To detect overflow in data during simulation, you must also select Simulation > Debug > MATLAB & Stateflow Error Checking Options > Data Range. See Data Range Violations in a Chart for more details.

    • Echo expressions without semicolons — Clear this check box to disable run-time output in the MATLAB® Command Window, such as actions that do not terminate with a semicolon.

    • Ensure responsiveness — Clear this check box to disable ability to break out of long-running execution using Ctrl+C.

  3. Click OK.

Keep Charts Closed to Speed Up Simulation

During model simulation, any open charts with animation enabled take longer to simulate. If you keep all charts closed, you can speed up the simulation.

Keep Scope Blocks Closed to Speed Up Simulation

During model simulation, any open Scope blocks continuously update their display. If you keep all Scope blocks closed, you can speed up the simulation. After the simulation ends, you can open the Scope blocks to view the results.

Use Library Charts in Your Model

If your model contains multiple charts that do not use JIT mode and contain the same elements, you might generate multiple copies of identical simulation code. By using library charts, you can minimize the number of copies of identical simulation code. For example, using five library charts reduces the number of identical copies from five down to one.

For more information about using library charts, see Create Specialized Chart Libraries for Large-Scale Modeling.

Was this topic helpful?