supress simulink re-compile on every call

52 ビュー (過去 30 日間)
Amardeep
Amardeep 2011 年 11 月 9 日
コメント済み: Pranjal Biswas 2022 年 5 月 12 日
Hi everybody;
I have a somewhat odd problem so bear with me.
I was presented with a rather large simulation suite written in Matlab which calculates sensory returns in an environment. Part of what I had to do was to re-make part of it in Simulink.
The simulink model I have made is called every so often in the model (at a regular number of time steps) and executed once on the current system parameters and sensor returns.
The output of my model will affect the system model for the next four steps and thus affect my inputs for my next execution. It is for this reason I cant simply make a big time based array of inputs and squirt them in in one go simulating a whole run. (Think of it like a feedback element whose tunining parameters can be changed on the through path as well as internal to itself).
This means that I have to call the model every time it is needed rather than pre-generating. My problem is that every time I call the sim command it re-compiles the simulink. This slows down my one simulation run from 30 mins to 11 hours (due to the sim call every n time steps). Is there a way to prevent it from having to recompile? All my inputs are presented as constants as I cant ammend the data structures to include time steps as each execution is only a single time step.
Regards
Amardeep
  2 件のコメント
Titus Edelhofer
Titus Edelhofer 2011 年 11 月 9 日
Hi Amardeep,
what do you mean by "recompile"? Do you mean the Accelerator compiling the model (again) because the accelerator thinks something substantial has changed?
Titus
Amardeep
Amardeep 2011 年 11 月 9 日
Yes this appears to be the case. On every call the simulink window displays the compiling messages at the base of the window with the green progress bar. I was able to cut down the execution time a little by fixing all dimensions so it wouldnt have to waste time propagating all of them but this hasnt made a significant impact (although every little helps).

サインインしてコメントする。

採用された回答

Amardeep
Amardeep 2011 年 11 月 22 日
As a solution I was able to find the block which was the problem but execution time using sim was very slow. Thus the best speed solution was to compile using real-time worksop and interface with the .exe using .mat files. This took the per execution time from ~2.5s down to ~0.2s.
  2 件のコメント
Mikkel Fristrup Schou
Mikkel Fristrup Schou 2017 年 4 月 11 日
Can you elaborate how it is done with .exe and .mat ?
Pranjal Biswas
Pranjal Biswas 2022 年 5 月 12 日
Yes, could you please eleborate a bit on the method that helped you?

サインインしてコメントする。

その他の回答 (3 件)

Titus Edelhofer
Titus Edelhofer 2011 年 11 月 9 日
Hi Amardeep,
Additionally take a look at the doc for
Simulink.BlockDiagram.getChecksum
which can be used to find out, which blocks have changed in a way the accelerator does not like.
Titus

Giovanni
Giovanni 2017 年 8 月 2 日
I have just received this technical support that solved this problem. It is a particular situation using simscape (topic is 'run-time parametres Vs compile-time parameters'). So if you do not need to change any simscape parameters but only need to change simulink parameters the 'set_param' lines are not needed, and the , 'FastRestart', option is enough! I love this team!
Support starts here (see also model option about automatic data save):
I understand that you want to avoid compilation time when running multiple simulations of the same Simscape model in a loop, while changing the value of a parameter.
Please note that Simscape run-time parameters are different from Simulink tunable parameters. You can visit the documentation for more information on how Simscape run-time parameters differs from Simulink.
A possible solution is to enable fast restart while specifying run-time parameters as follows :
% First we load the example model 'ssc_bipolar_nonlinear'
model = 'ssc_bipolar_nonlinear';
open_system(model)
% In this model, the R3 resistor is varied within a for-loop.
% The result is then plotted for each value of R3.
set_param([model '/R3'], 'R', 'R3_par' )
set_param([model '/R3'], 'R_conf', 'runtime')
hold all
for R = [1000 2000 3000 4000 5000 6000 7000 8000]
R3_par = R;
% The simulations are launched using the FastRestart mode to avoid compilation time
simout = sim(model, 'FastRestart', 'on');
plot(simout.simlog_ssc_bipolar_nonlinear.R3.i.series.time, simout.simlog_ssc_bipolar_nonlinear.R3.i.series.values);
end
You can visit the following link for additional information on run-time parameters : http://www.mathworks.com/help/physmod/simscape/run-time-parameters.html

Charles Harrison
Charles Harrison 2013 年 10 月 9 日
Aramdeep,
I feel your pain and have experienced similar situations before. As such there are two solutions that I can think of that can solve your problem:
1st Solution: Instead of using the 'sim' command, I suggest using the model command. Specifically the model command is advantageous if you are just trying to treat your model as a funciton and get outputs for a given set of inputs. Additionally make sure that you 'compile' and 'term' the model as few times as possible to prevent initialization overhead.
Example: model_name([],[],[],'compile');
for i=1:number_cases
output_vector = model_name(0,state_vector,input_vector);
end
model_name([],[],[],'term');
2nd solution:
Tell the reference models not to rebuild. This is a two step process. First Go to Simulation->Configuration Parameters -> Model Referenceing -> Rebuild -> Never (Alternatively this can be also done progratically from the command line if needed. Just reply to this post if you need to know how). After that, make sure the secondary setting next to the rebuild parameter (regarding the error message) is set to None. I think it is the stupidest thing, but even if you tell Simulink not to rebuild, and dont set the error checking message also not to check, then it will still rebuild! Once this step is complete if you need to make changes to the reference models (like make a data or structural change) you need to temporarily set the Rebuild parameter to 'If out of Date' and then run the sim to recompile. Another alternative is if you need changes to be recognize, you can use the slbuild command.
  4 件のコメント
Andrew Hopkins
Andrew Hopkins 2018 年 6 月 14 日
Charles, thanks for this answer. Could you point me to any documentation on executing the model? I haven't been able to find anything on this, especially the structure of the state, input, output, and what the first argument corresponds to.
Andrew Hopkins
Andrew Hopkins 2018 年 6 月 14 日
It's sad how much I searched, and then a coworker found this link in 5 seconds.
It was not clear from the other posts (or even the model documentation), that you need to call each function successively for each time step for some total amount of simulation time.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeChoose and Parameterize Blocks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by