Main Content

Create Partitions

Partitioning a Model

Partitions are components of a model that execute independently as atomic tasks. In multi-tasking models, partitions are created from model components. Periodic partitions are scheduled as a function of sample times in a model. In export-function models, the root function-call inputs are defined as partitions. These partitions have a schedule associated with them, which tells what order the partitions execute.

With partitions, you can separate parts of the model which you can explicitly control. You can think of periodic partitions as components that run at specific rates in a model. Aperiodic partitions are components that run at specified hit times or specified events. The schedule of these partitions have an impact on simulation and code generation.

The Schedule Editor enables you to partition the model and interact with those partitions. The Schedule Editor shows partitions, the connections between them, and the order of the partitions.

There are three types of partitions:

Types of PartitionsImageDescription
Implicit

Automatically created by Simulink®. Blocks running at the base rate show up as an implicit partition.
Periodic

User-defined partitions from the atomic subsystems and/or Model blocks. Periodic partitions can also be defined by export-functions. These partitions execute based on their sample time and thus their execution is periodic.
Aperiodic

Aperiodic partitions are partitions which have no constraints and can be made to execute at any time. Specify the hit times in the Property Inspector of the Schedule Editor, at which you want to run the aperiodic partition. You can also use events in the Schedule Editor to schedule execution of the aperiodic partitions.

The blocks running at the base rate in the model is shown as an implicit partition in the Schedule Editor. The base rate is the fastest discrete rate in the model. D1 denotes the base rate. D1 annotation also appears in the Timing Legend. The D1 partition or implicit partition always remains the first discrete partition in the order.

The default partitions that are already present in the model are also implicit partitions.

The partition colors match their rate.

Create Partitions from a Rate-Based Model

Partitioning is enabled only on multitasking, fixed-step, and variable-step solver models. To choose multitasking execution mode, in Solver selection on the Solver pane, select the Type to be Fixed-step or Variable-step. Select the Treat each discrete rate as a separate task check box on the Solver pane of the Configuration Parameters dialog box. For more information on multitasking execution mode, see Time-Based Scheduling and Code Generation (Embedded Coder).

As a best practice, enable the Automatically handle rate transition for data transfer setting in the Solver pane. When you check Automatically handle rate transition for data transfer, Simulink inserts Rate Transition blocks between blocks when rate transitions are detected. Simulink handles rate transitions for asynchronous and periodic tasks. Simulink adds the hidden blocks configured to ensure data integrity and determinism for data transfers. When you check Treat each discrete rate as a separate task, Simulink selects multitasking execution for models operating at different rates. It also specifies that groups of blocks with the same execution priority are processed through each stage of simulation (for example, calculating output and updating states) based on task priority.

To see default partitions in the Schedule Editor, open the Schedule Editor. On the Modeling tab, click Schedule Editor. Update the diagram by clicking the icon on the toolstrip. The default partitions in the model are called implicit partitions. You can also create partitions in the model through an atomic subsystem or a model block.

Create Partitions Using Manage Partitions

In the Schedule Editor, use the Manage Partitions panel to create partitions. To open the Manage Partitions panel, click Manage Partitions, on the Schedule Editor toolstrip. The changes made in Manage Partitions are applied to the model to create partitions after updating the diagram. Manage Partitions shows the model hierarchy with the Subsystem blocks and Model blocks which can be explicitly partitioned.

To create partitions from Subsystem blocks, select the subsystems and click the . To create partitions from Model blocks, select the Model blocks and click . Enter partition names in the column Partition Name, and sample times in the column Sample Time. Repeat the steps for all the subsystems and Model blocks in the model that you want to partition. Update the diagram to see the created partitions in the Schedule Editor. The partitions appear in the graph with their deduced data dependencies and order.

The image shows the Schedule Editor canvas. The canvas contains an implicit multirate partitions. The multirate partitions contains three partitions, Cont, FiM, and D1.

Note

Creating partitions using the Manage Partitions panel makes changes to the subsystem or model block parameters.

The following example shows how to configure a model for partitioning and create partitions by using Manage Partitions panel in the Schedule Editor.

  1. Open the Model Fault-Tolerant Fuel Control System example model sldemo_fuelsys.

    openExample('simulink_automotive/ModelingAFaultTolerantFuelControlSystemExample')
    sldemo_fuelsys

  2. Open the Schedule Editor.

    Open the Schedule Editor On the Modeling tab, click Schedule Editor. To see the default partitions, click Update Diagram in the Schedule Editor. Two implicit partitions, created automatically by Simulink, are seen in the Schedule Editor.

  3. Create partitions.

    Open the Manage Partitions panel. In the panel, expand the fuel_rate_control subsystem. Select the airflow_calc subsystem and click . To change the default partition name and sample time, click the default name and sample time.

    To create a partition for the fuel_calc subsystem, select the fuel_calc subsystem and click .

    The Manage Partitions panel gives you the default partition names and sample times.

    Update the diagram to see the newly created partitions.

Create Partitions from Atomic Subsystem Blocks

You can partition an atomic subsystem. An atomic subsystem is treated by Simulink as a unit when determining the execution order of block methods(partitioning is enabled only on multitasking, fixed-step and variable-step solver models). To create partitions from an atomic subsystem block, go to the Block Parameters dialog box. Select Periodic partition from the Schedule as drop-down. Give the partition a name and a discrete sample time and click OK. This creates an explicit partition for this block. To see this partition in the Schedule Editor, update the diagram. The partition appears in the graph and in the Order with the connections based on the signals in the model.

The image shows block parameters dialog for Subsystem block. In the subsystem block parameter dialog box, the 'Schedule as' parameter is set to 'Periodic partition', the 'Partition name' is set to 'Partition1' with a text entry, and the 'Sample time' parameter is set to 0.1 with a text entry.

Create Partitions from Model Blocks

To create partitions from a Model block, in the Model events simulation, select Schedule rates and Schedule Editor from the Schedule rates with drop-down. When you enable partitioning from a referenced model, partitions are created from all the Model blocks present in the referenced model. These partitions are scoped by the model block name. To see this partition in the Schedule Editor, update the diagram. The partitions appear in the graph and in the Order column with the connections based on the design of your model.

The image shows the block parameter dialog for Model block. The Model events simulation parameter has a 'Schedule rates'. 'Schedule rates with:' parameter is set to 'Schedule Editor'.

Export-Function Partitions

In export-function models, partitions are created from the function calls present in the model. To create partitions from the function calls in the export-function models, reference the export-function model in a top model. Schedule the Model block using the Schedule Editor through the block parameters. Partitions are then created from the function calls and their order is determined by the Schedule Editor.

  1. Create an export-function model.

  2. Add a Model block that references the export-function model.

  3. Set the parameter to partition the export-function model.

Referencing an export-function model from a Model block allows you to partition the function calls without changing the model itself. Simulink functions in an export-functions model cannot be scheduled, and do not appear as partitions in the Schedule Editor.

  1. Add a Model block to a new Simulink model. In the Model name box, enter the name of an export-function model. For example, use the export-function model created in Create Export-Function Model.

  2. To enable the use of the Schedule Editor, configure the model to be multitasking. Open the Model Configuration Parameters. In Solver selection on the Solver pane, set the Type to Fixed-step. Check the Treat each discrete rate as a separate task and Automatically handle rate transition for data transfer parameters. Click OK. The model is enabled for partitioning.

    Note

    Do not convert a subsystem into a model because it automatically creates Inport blocks.

    The image shows a model block names export_function_model. The input to the model is a Sine Wave with sample time 0.1. The outport blocks are added to the output_100ms, and output_10ms.

  3. Add Outport blocks to the output_100ms and output_10ms ports for saving simulation data to MATLAB®. For this example, in the export-function model, set the sample time of both the function calls to -1.

  4. Add a Sine Wave block to provide data input. Set Amplitude to 2 and Sample time to 0.01.

  5. To partition the function calls of the export-function model, in the Block Parameters dialog box for the Model block, select Schedule Editor option from the Schedule Rates with drop-down menu.

  6. Open the Schedule Editor and update the diagram to see the function calls as partitions.

    The image shows the Schedule Editor. The Schedule Editor has two asynchronous partitions, named Model.function_call_1 and Model.function_call_2, and one implicit partition named D1. The Model.function_call_1 partition is selected and has Hit Times entered as [0:0.1:10

See Also

Related Topics