Main Content

Graph-Based Multithread Simulation

This example shows how graph-based algorithms optimize simulation on multiple threads.

Graph-based algorithm

This example contains four nondirect feedthrough blocks followed by four direct feedthrough blocks. Direct feedthrough means that the output port signal of a block is computed from the values of its input port signals in the same time step. The graph-based algorithm runs the four nondirect feedthrough blocks in parallel and groups the following direct feedthrough blocks into the same branch. Then, the model uses multithreading to run those four branches. Thus, the algorithm speeds up the simulation almost four times on a four or more core machine compared to a single-threaded simulation on the same machine.

Open model and simulate

open_system('slexGraphBasedMultiThreadSimExample');

% Press "Toggle MultithreadedSim Parameter" block to turn off / on
% multithreaded simulation and compare the elapsed time.

Exit

close_system('slexGraphBasedMultiThreadSimExample');