Simulink slower to compile when 'SrcWorkspace' set to 'current' (call to sim a function)

3 views (last 30 days)
I received a rather heavy model (.slx ~57Mo, 40k parameters and signals) from a client, and I need to run it several times for test purposes. To run the model, I call a function (e.g. runTest()) that load every parameters and signals and then call sim function. Here is the problem :
When the sim function is called with option SrcWorkspace set to current (i.e. runTest() workspace), the model is stuck at step "Compiling : Evaluating block parameter." for a very long time (hours scale)
However, when I assign all variables in base workspace and I call sim with SrcWorkspace set to base, this step take a reasonable amount of time (minutes scale).
Do you have any idea why calling sim within function workspace slow down the compilation step ?

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 16 Jul 2020
Do you have an apple-to-apple fair comparison? Might it be that when you specify 'SrcWorkspace' as 'current' in runTest(), the data is also loaded in base workspace thus reduces the availability of memory?
Put a breakpoint in runTest() and run "memory" in Command Window to compare.
The default SrcWorkspace for a Simulink model is base, speifying function workspace might slow down a little bit but should not be that significant.
The Simulink model itself is always loaded into the memory used by MATLAB, even though you run load_system() inside runTest().
Another alternative is to use Simulink Data Dictionary or Simulink Model Workspace to store the data.
  2 Comments
Arthur Roué
Arthur Roué on 16 Jul 2020
Thanks for your answer. It's highly likely it's a memory problem, I did cop with MATLAB crash when working too long with this model.
I'm at the end of a long industrial process, so the model and input data are what they are when they get to me... Then I can't do such changes as implement a dictionnary or put the data in model workspace.
The memory used by MATLAB is almost the same with or without model parameters in base workspace (in addition to runTest() workspace).
Maximum possible array: 2848 MB (2.987e+09 bytes) *
Memory available for all arrays: 2848 MB (2.987e+09 bytes) *
Memory used by MATLAB: 20364 MB (2.135e+10 bytes) // 20351 MB (2.134e+10 bytes)
Physical Memory (RAM): 8083 MB (8.476e+09 bytes)
For a first run (normal mode) of a basic test with compilation, if SrcWorkspace is base it takes ~30 mins to end the simulation, whereas using runTest() workspace took 7 hours last time.
Again thanks, I'll accept your answer and continue working with base workspace because I almost lost a day on this model which is quite unpleasent to interact with (everything is sooooo slow).
Fangjun Jiang
Fangjun Jiang on 16 Jul 2020
Contact Mathworks tech support if you have to use "current" workspace. It sounds like a bug or a significant performance issue.

Sign in to comment.

More Answers (0)

Categories

Find more on Configure and View Diagnostics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!