Conditional Execution Behavior

To speed simulation of a model, by default the Simulink software avoids unnecessary execution of blocks connected to Switch, Multiport Switch, and of conditionally executed blocks, a behavior called conditional execution (CE) behavior. You can disable this behavior for all Switch and Multiport Switch blocks in a model, or for specific conditional subsystems. See Disabling Conditional Execution Behavior.

The following model illustrates conditional execution behavior.

The outputs of the Constant block and Gain blocks are computed only while the enabled subsystem is enabled (that is, at time steps 0.5 to 1.0, 1.5 to 2.0, and so on). This is because the output of the Constant block is required and the input of the Gain block changes only while the enabled subsystem is enabled. When CE behavior is off, the outputs of the Constant and Gain blocks are computed at every time step, regardless of whether the outputs are needed or change.

In this example, the enabled subsystem is regarded as defining an execution context for the Constant and Gain blocks. Although the blocks reside graphically in the model's root system, the Simulink software invokes the blocks' methods during simulation as if the blocks reside in the enabled subsystem. This is indicated in the sorted order labels displayed on the diagram for the Constant and Gain blocks. The notations list the subsystem's (id = 1) as the execution context for the blocks even though the blocks exist graphically at the model's root level (id = 0).

Propagating Execution Contexts

In general, the Simulink software defines an execution context as a set of blocks to be executed as a unit. At model compilation time, the Simulink software associates an execution context with the model's root system and with each of its nonvirtual subsystems. Initially, the execution context of the root system and each nonvirtual subsystem is simply the blocks that it contains.

When compiling, each block in the model is examined to determine whether it meets the following conditions:

If a block meets these conditions and execution context propagation is enabled for the associated conditional subsystem (see Disabling Conditional Execution Behavior), the Simulink software moves the block into the execution context of the subsystem. This ensures that the block's methods are executed during the simulation loop only when the corresponding conditional subsystem executes.

Behavior for Switch Blocks

This behavior treats the input branches of a Switch or Multiport Switch block as invisible, conditional subsystems, each of which has its own execution context that is enabled only when the switch's control input selects the corresponding data input. As a result, switch branches execute only when selected by switch control inputs.

Displaying Execution Contexts

To determine the execution context to which a block belongs, select Sorted order from the model window's Format menu. The sorted order index for each block in the model is displayed in the upper-right corner of the block. The index has the format s:b, where s specifies the subsystem to whose execution context the block belongs and b is an index that indicates the block's sorted order in the subsystem's execution context, e.g., 0:0 indicates that the block is the first block in the root subsystem's execution context.

If a bus is connected to the block's input, the block's sorted order is displayed as s:B, e.g., 0:B indicates that the block belongs to the root system's execution context and has a bus connected to its input.

The sorted order index of conditional subsystems is expanded to include the system ID of the subsystem itself in curly brackets as illustrated in the following figure.

In this example, the sorted order index of the enabled subsystem is 0:1{1}. The 0 indicates that the enabled subsystem resides in the model's root system. The first 1 indicates that the enabled subsystem is the second block on the root system's sorted list (zero-based indexing). The 1 in curly brackets indicates that the system index of the enabled subsystem itself is 1. Thus any block whose system index is 1 belongs to the execution context of the enabled subsystem and hence executes when it does. For example, the Constant block's index, 1:0, indicates that it is the first block on the sorted list of the enabled subsystem, even though it resides in the root system.

Disabling Conditional Execution Behavior

To disable conditional execution behavior for all Switch and Multiport Switch blocks in a model, turn off the Conditional input branch execution optimization on the Optimization pane of the Configuration Parameters dialog box (see Optimization Pane). To disable conditional execution behavior for a specific conditional subsystem, uncheck the Propagate execution context across subsystem boundary option on the subsystem's parameter dialog box.

Even if this option is enabled, a subsystem's execution context cannot propagate across its boundaries under either of the following circumstances:

Displaying Execution Context Bars

The Simulink software can optionally display bars next to the ports of subsystems across which execution contexts cannot propagate, i.e., on subsystems from which no block can inherit its execution context.

To display the bars, select Execution Context Indicator from model editor's Format > Block Displays menu.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS