Clear Filters
Clear Filters

How to use all cores for running a Simulink model?

28 views (last 30 days)
Nima
Nima on 2 Aug 2024 at 12:08
Answered: Walter Roberson on 2 Aug 2024 at 20:26
Hi,
I modeled a thermal-fluid network in Simulink with Simscape modules and I want to use all cores in order to speed up my simulation.
I am using a workstation with 64 physical cores and 128 logical cores, but I get the same run-time as when I run the model on my Laptop with 6 physical cores and 12 logical cores. What should I do that Simulink uses all the capacity of my workstation for running a model?
I would appreciate if you could help me.
  2 Comments
Seigan
Seigan on 2 Aug 2024 at 12:50
Hi Nima, I have the same question.
As I understand, running code on multiple cores is managed at the OS level (Windows), although modern video games seem able to do it, so I don't see why Simulink could not.
The only way I know of to control which Simulink blocks run on which core, is to build your model for a real-time machine using Simulink Real-Time and then using Concurrent Execution. But in that case you would be limited to real-time and could not run any faster. Supposing you're currently running much slower than real-time it could be an option.
Harald
Harald on 2 Aug 2024 at 16:12
Hi,
for multiple simulations, consider using parsim to run those in parallel and leverage the multiple cores of your system.
In general, it greatly depends on what you want to parallelize. MATLAB has implicit multi-threading, parallel computing, and support for GPUs, but in each cases, the application needs to be suitable for parallelization.
You may also want to explore general techniques for speeding up simulations, see for example here:
Best wishes,
Harald

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 2 Aug 2024 at 20:26
Simulink internally compiles down to a mix of algebraic and control operations. The algebraic operations are automatically operated in parallel. However, there are practical limits to operating algebraic operations in parallel that result in overall operation being slower as you add more cores beyond the optimum -- slower because it takes time to send commands and data to each core and to synchronize the operations and to collect the results.
The typical peak multi-core operations tends to be about 4 to 6 cores; more than that and you typically spend more time splitting up the task and coordinating operations than you get back.
So, if you insist that all 64 cores are used... then expect the results to be about 10 or more times slower.
The situation is different if you are performing parameter sweeps or other similar operations that are independent of the prior history: in such a case you can use parsim to split up the work into groups that run seperately.

Community Treasure Hunt

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

Start Hunting!