supress simulink re-compile on every call
조회 수: 62 (최근 30일)
이전 댓글 표시
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
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
채택된 답변
추가 답변 (3개)
Titus Edelhofer
2011년 11월 9일
Hi Amardeep,
in this case I'd suggest to take a look at the following link: <http://www.mathworks.de/support/solutions/en/data/1-1HRSN0/index.html?product=ML&solution=1-1HRSN0>
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
댓글 수: 0
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
댓글 수: 0
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
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
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 Exchange에서 Choose and Parameterize Blocks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!