Main Content

Implement Pipelining in Simulink

This example shows how to implement pipelining for a system represented in a Simulink® model. The ex_task_parallelism_initial model consists of an input, functional components applied to the same input, and a concatenated output. This example shows how to break up data dependencies between the tasks so that they can run completely in parallel. For more information on pipelining, see Types of Parallelism.

A block diagram with an input connected to 2 functional components. Each functional component is connected to the output scope.

Set up this model for concurrent execution. To see the completed model, open ex_pipelining_top.

Configure Model for Concurrent Execution

  1. Open the ex_task_parallelism_initial model.

  2. Convert areas in this model to referenced models. Use the same referenced model to replace each of the functional components that process the input.

Set Model Configuration Parameters

  1. Click Configure Tasks. In the Concurrent Execution dialog box, in the right pane, select the Enable explicit model partitioning for concurrent behavior check box. With explicit partitioning, you can partition your model manually.

  2. On the Modeling tab, click Model Settings.

  3. Select Code Generation > Interface > Advanced parameters. Clear the MAT-file logging check box.

  4. Select Solver, set Type to Fixed-step, and click Apply.

  5. On the Solver pane, expand Solver details. Check that Periodic sample time constraint is set to Unconstrained. Under Tasking and sample time options, select Allow tasks to execute concurrently on target.

Partition Model Using Explicit Partitioning

Partition the top model.

In the Concurrent Execution tree, under Tasks and Mapping, select CPU. Click Add task three times to add three new tasks.

Map Blocks to Tasks

In the Concurrent Execution tree, select Tasks and Mapping. On the Map block to tasks pane:

  • Under Block: Input, click select task and select Periodic: Task.

  • Under Block: Function 1, select Periodic: Task1.

  • Under Block: Function 2, select Periodic: Task2.

  • Under Block: Output, select Periodic: Task.

This action maps your partitions to the tasks you created. The Input and Output model blocks are on one task. Each functional component is assigned a separate task.

Finalize Model

Close the Concurrent Execution dialog box.

Share Configuration with Referenced Models

Apply configuration parameters to all referenced models.

Initialize Data Dictionary to Store Configuration Set

  1. Create a object that represents the configuration set, which is an entry in the dictionary. For this example, suppose the name of the dictionary is myData.sldd and the name of the Simulink.ConfigSet object is myConfigs.

  2. Store a copy of the target Simulink.ConfigSet object in a temporary variable.

  3. Save changes made to the dictionary.

Set Up Configuration Reference

  1. Create a freestanding configuration set in the base workspace by copying the active configuration set of the model.

  2. Create a separate configuration reference for the top model and each reference model. To point the reference to your freestanding configuration, set the SourceName property to freeConfigSet, the variable that represents your configuration.

  3. Attach the configuration reference to each model by using the ConfigSetRef object. To use the configuration reference in the model, activate it for each model.

For more information, see Share a Configuration with Multiple Models, Automate Model Configuration by Using a Script, and Make Changes to Configuration Set Stored in Dictionary.

Update your model to see the tasks mapped to individual model blocks.

A Simulink model with 4 reference model blocks to represent the input, 2 functions, and output. Each reference model has a block-to-task mapping symbol in the top-left corner. There is a z-1 badge above every connection to represent delays.

Notice that delays are introduced between different tasks, indicated by the z-1 badge. Introducing these delays may cause different model outputs in Simulink. Ensure that your model has an expected output on simulating the parallelized model.

Related Examples

More About