Main Content

Concurrent Execution on Simulink® Real-Time™

This example shows how to apply explicit partitioning to enhance concurrent execution of a real-time application that you generate by using Simulink Real-Time.

Simulink Real-Time supports concurrent execution by using implicit partitioning or explicit partitioning of models. This example shows the relationship between the explicit partitioning of the tasks in the model subsystems and the execution of tasks by using the Simulink Real-Time profiling tool.

The example model slrt_ex_mds_and_tasks runs at sample rate of 0.001 second.

To run the model with adjusted sample rate of 0.01 second, change the sample rated before running the example. In the MATLAB Command Window, type:

Ts = 0.01;

Open, Build, and Download the Model

The explicit partitioning in the top-level model occurs in subsystem1.

open_system(fullfile(matlabroot,'toolbox','slrealtime','examples','slrt_ex_mds_subsystem1'));

The explicit partitioning in the top-level model occurs in subsystem2.

open_system(fullfile(matlabroot,'toolbox','slrealtime','examples','slrt_ex_mds_subsystem2'));
%

Open the model slrt_ex_mds_and_tasks. The model is mapped to seven threads: Model1_R1, Model1_R2, Model1_R3, Model1_R4, Model2_R1, Model2_R3, and Model2_R4.

These threads run at sample rates of Ts, 2*Ts, 3*Ts, 4*Ts, Ts, 3*Ts, and 4*Ts.

mdl='slrt_ex_mds_and_tasks';
open_system(fullfile(matlabroot,'toolbox','slrealtime','examples',mdl));

To apply explicit partitioning, in the Simulink Editor, on the Real-Time tab, click Hardware Settings, and then select Solver > Configure Tasks. Select the Tasks and Mapping node.

Build, download, and run the model.

set_param(mdl,'RTWVerbose','off');
rtwbuild(mdl);
tg = slrealtime;
load(tg,mdl);
% Open TET Monitor
slrtTETMonitor;
% Start profiler on the target computer
startProfiler(tg);
start(tg);
pause(2);
stop(tg);
### Starting serial model reference simulation build
### Starting serial model reference code generation build
### Successful completion of build procedure for: slrt_ex_mds_subsystem1
### Successful completion of build procedure for: slrt_ex_mds_subsystem2
### Successful completion of build procedure for: slrt_ex_mds_and_tasks
Unable to find symbol(s) 'slrt_ex_mds_and_tasks_DW.Model1_InstanceData.rtb.RateTransition_Buf0, slrt_ex_mds_and_tasks_DW.Model1_InstanceData.rtb.RateTransition_Buf1, slrt_ex_mds_and_tasks_DW.Model1_InstanceData.rtb.RateTransition_Buf2, slrt_ex_mds_and_tasks_DW.Model1_InstanceData.rtb.RateTransition_LstBufWR, slrt_ex_mds_and_tasks_DW.Model1_InstanceData.rtb.RateTransition_RDBuf' in symbol table of ELF file: 'C:\Users\dskolnic\OneDrive - MathWorks\Documents\MATLAB\ExampleManager\dskolnic.Bdoc20b.j1420932\slrealtime-ex84556294\slrt_ex_mds_and_tasks_slrealtime_rtw\slrt_ex_mds_and_tasks'
### Created MLDATX ..\slrt_ex_mds_and_tasks.mldatx

Build Summary

Code generation targets built:

Model                   Action                       Rebuild Reason                              
=================================================================================================
slrt_ex_mds_subsystem1  Code generated and compiled  slrt_ex_mds_subsystem1.cpp does not exist.  
slrt_ex_mds_subsystem2  Code generated and compiled  slrt_ex_mds_subsystem2.cpp does not exist.  

Top model targets built:

Model                  Action                       Rebuild Reason                                    
======================================================================================================
slrt_ex_mds_and_tasks  Code generated and compiled  Code generation information file does not exist.  

3 of 3 models built (0 models already up to date)
Build duration: 0h 1m 22.867s

Display Profiling Data

The profiling data shows the execution time of each thread on a multi-core target computer.

profData = tg.getProfilerData;
profData.plot;
Processing data on target computer ...
Transferring data from target computer ...
Processing data on host computer ...
 

View model's TET information on TET monitor

Close the Model

bdclose('all');