Specify Blocks to Execute First or Last
What is Execution Order Property of a Block
Execution Order property of a Simulink block determines its relative execution order compared to other blocks in a model. By default, blocks execute based on priority. For more information, see Specify Block Execution Order, Execution Priority and Tag.
Starting in R2023b, blocks can be set to execute first or last in a model. (since R2023b)
How to Configure a Block to Execute First or Last
To configure a block to execute first or last, in the Block Properties dialog, from the
Execution Order list, select First
or
Last
.
For the first or last option in the block execution order property to work:
Only one block can be configured to execute first or last at a single level of model hierarchy. For example, if a Data Store Read block is set to execute first at the root-level model, another block cannot execute first at the root level of this model.
Connect only the Inport block to the input port of a block configured to execute first. However, there is no limitation on which block you can connect to the output port of such a block.
Connect only the Outport block to the output port of a block configured to execute last. However, there is no limitation on which block you can be connect to the input port of such a block.
Blocks cannot be in an algebraic loop. The algebraic loop solver must determine the execution order based on the algebraic variables in the loop, so specifying execution order for algebraic loops is not supported. For more information, see How the Algebraic Loop Solver Works.
Blocks must be inside a system that executes in a single task. For more information, see Control and Display Execution Order.
Note
Starting in R2024a, blocks with Execution
Order set to First
or Last
is
supported inside a model that contains blocks with continuous sample time. (since R2024a)
Limitations
These blocks are not supported for Execution Order set to
First
or Last
:
Virtual blocks. For more information, see Nonvirtual and Virtual Blocks.
Blocks with control ports, such as action subsystems, enabled and triggered subsystems, function-call subsystems, and resettable subsystems. For more information, see Conditionally Executed Subsystems Overview.
Initialize Function, Reset Function, Reinitialize Function, and Terminate Function blocks that execute based on custom routines.
Data Store Memory block.
These limitations apply to code generated from a model containing blocks set to execute first or last. In the generated code:
Execution order of the blocks being set to execute first or last may not be traceable due to optimization.
In some cases, Simulink may deem that an extra signal copy is needed before blocks set to execute first or after blocks set to execute last. For example, the software may add a copy of the output signal of a block set to execute last to the root Outport block after the block set to execute last executes.
For export-function models or subsystems with control ports, reads or writes of model data elements on the communication interface occur independent of an execution order specified on blocks in the model or subsystems. For example, output data written as the result of a service call might be the last statement in the function code for a Function-Call Subsystem to ensure data validity, regardless of any blocks being set to execute first or last in the subsystem.
See Also
Specify Block Execution Order, Execution Priority and Tag