In this video, I'll show how to analyze and optimize
the multicore execution behavior of your Simulink model
by using Dataflow domain to make use of multiple cores
and improve simulation performance.
To use Dataflow, you select your computation
with intensive subsystem and enable Dataflow execution
domain from the execution tab in the property inspector.
Upon enabling Dataflow, the multicore contextual tab
appears in Simulink toolstrip.
Multi-core analysis will automatically
flow balanced blocks across the course.
To do this for simulation we must
profile block execution times and perform multicore analysis.
To do this, first we select the cost mode
on the left-hand side of the toolstrip.
For good generation targets, cost estimation
will use an internal compiler to estimate
the relative costs of blocks.
And for software in the loop, or processor in the loop,
we use execution time profiling.
As you are taking a look at simulation analysis,
we selected default mode of simulation profiling.
For best performance it is recommended to set some model
parameters to optimal settings.
Using the optimized dropdown button,
we can set individual parameters to optimal settings.
Or by clicking the icon, you can set all the parameters
simultaneously.
For convenience, profiling and analysis
are combined into a single analysis button
click for simulation analysis.
Before we run the analysis, we can change the analysis
constraints.
To the left of the run analysis button
we see two edit boxes where we can
override the auto constraints.
The first one is maximum number of threads
to be used for multicore simulation.
When it's left to auto, the maximum number of threads
will be the number of physical cores
in the host machine, which in this case would be six.
The second constraint is the multithread threshold,
which is the lower bound of total execution
time at which multithreading overhead is justified.
For simulations it's recommended to leave this as auto.
With the constraints left in auto,
we click on the analyze button.
This will simulate the model and profile
execution times of the blocks.
Once the profiling simulation is complete,
the multicore analysis is run.
Upon completion of the analysis, the results of partitioning
are show.
Thread highlighted shows that the blocks are
partitioned onto two threads.
To get more insight on the results of the analysis
and to get suggestions, you can look at a Dataflow analysis
report panel.
The first thing we notice here is
a suggestion for increasing concurrency in the model.
We are suggested to add an algorithmic latency
to increase the throughput of the model execution.
A Dataflow subsystem has a latency of 0
and the analysis suggests that we change that to 2.
When we click accept, the Dataflow latency
is changed to a latency of 2 and the analysis is rerun.
There are still only two threads highlighted,
but the partition has been optimized.
The third highlighting can be controlled since they're
highlighted in the legend.
We can also see pipeline delays have
been added to Dataflow subsystem to break data dependencies
and allow blocks to be executed concurrently
on different threads.
The delays are indicated with certain [INAUDIBLE] and icons.
And the visibility the icons can be controlled from the toolbar.
We can also see if there are additional multicore
diagnostics.
Here we can see the receiver block is
75% of the computational load.
We can investigate further and take a look
at the cost of the blocks in the cost editor.
Here we can see the profile execution times
for the blocks and their relative loads.
You can see that receiver block is significantly
more computationally intensive than the other blocks.
This will impact the maximum throughput
as this blocks takes longer to execute than all
the other blocks combined.
This limits us to two threads for this Dataflow subsystem.
One thread for the receiver and one thread
for all the other blocks.
Any additional threads would be wasted as a Dataflow subsystem
cannot execute faster than the most computationally expensive
block.
Utilizing Dataflow with two threads give us a simulation
speed of 1.5x compared to normal non-Dataflow single thread
execution.
Using the multicore contextual tab
you can analyze and optimize a simulation multicore execution
of a Dataflow domain.
Thanks for watching.