How to run Simulink environment(3D Simulation) and MATLAB function/script logic asynchronously in parallel?

Hello,
I am experiencing a significant slowdown in my robotics simulation because the 3D environment (Simulation 3D Robot) and my control logic (MATLAB System block/Function) are executing in a strictly sequential, synchronous manner.
Currently, the simulation waits for the code execution to finish at every step, and the code waits for the environment to provide the next frame. I want to decouple these two processes so they can run asynchronously in parallel.
Specifically, I want the 3D environment to continue its physics/rendering without waiting, while the control logic performs its heavy computation on a separate core/process.
Could you please advise on:
1. Non-blocking Asynchronous Execution:How can I configure Parallel Model Reference or use specific blocks (like Rate Transition with 'Ensure deterministic data transfer' unchecked) to allow the environment to run at full speed without being blocked by the controller's computation time?
2. Asynchronous Rate Transition:What is the best way to handle data exchange when the environment runs at a high frequency (e.g., 60Hz) but the perception/control logic runs at a lower, non-deterministic frequency (e.g., 5-10Hz)?
3. Utilizing Parallel Computing Toolbox for Real-time Speedup:Beyond just enabling 'Parallel Model Reference', are there specific S-Function or MATLAB System object techniques that allow a block to run in a separate thread or background process so it doesn't halt the main Simulink solver?
Thank you!

 Accepted Answer

You might be observing this slowdown due to how Simulink 3D Animation co‑simulates with Unreal Engine, though this is just one possible explanation based on the workflow.
From what I understand, the Simulation 3D environment uses a lock‑step co‑simulation mechanism, where Simulink and the 3D engine advance together at each fixed time step. In such a setup, it may be expected that the simulator waits for all blocks (including MATLAB Function or MATLAB System blocks) to finish execution before moving to the next step, which can limit opportunities for true asynchronous execution
For multi‑rate designs, you could consider running the 3D environment at a higher fixed rate (for example, 1/60 s) and the control or perception logic at a slower rate, using Rate Transition blocks to exchange data. Depending on model needs, relaxing deterministic data transfer might reduce latency, although this trades determinism for responsiveness.
If the computation inside the controller is particularly heavy, another possible approach is to ensure that the block itself returns quickly while the computation is handled in parallel. For example, MATLAB supports running work asynchronously using background execution (such as parfeval with backgroundPool), which can allow the Simulink step to continue while results are computed and applied later.
Finally, for CPU‑intensive components implemented as C‑MEX S‑Functions, Simulink may be able to execute eligible blocks on multiple cores if they are thread‑safe and meet the required constraints, though this typically applies to specific co‑simulation or S‑Function scenarios (Run Co-Simulation Components on Multiple Cores - MATLAB & Simulink).
I hope this gives some context on what might be influencing the synchronous behavior you’re seeing and a few possible directions to explore.

1 Comment

Thank you for your explanation.
In addition to parallel execution, I was wondering if there is a way in MATLAB/Simulink to make the simulation and control fully decoupled.
Specifically, can they run independently and communicate with each other without depending on each time step, similar to a ROS-based system?

Sign in to comment.

More Answers (0)

Categories

Find more on Simulation in Help Center and File Exchange

Asked:

on 14 Apr 2026 at 11:13

Commented:

on 17 Apr 2026 at 9:53

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!