Interact with the Acceleration Modes Programmatically
Why Interact Programmatically?
You can build an accelerated model, select the simulation mode, and run the simulation from the command prompt or from MATLAB® script. With this flexibility, you can create Accelerator mode MEX-files in batch mode, allowing you to build the C code and executable before running the simulations. When you use the Accelerator mode interactively at a later time, it will not be necessary to generate or compile MEX-files at the start of the accelerated simulations.
Build JIT Accelerated Execution Engine
accelbuild command, you can build a
JIT accelerated execution engine without actually simulating
the model. For example, to build an Accelerator mode
You can control the simulation mode from the command line prompt
by using the
The simulation mode can be
For example, to simulate your model with the Accelerator mode, you would use:
simOut = sim('myModel', 'SimulationMode', 'accelerator');
You can use
bdroot to set parameters for the
currently active model (that is, the active model window)
modelname if you do
not wish to explicitly specify the model name.
For example, to simulate the currently opened system in the Rapid Accelerator mode, you would use:
simOut = sim(bdroot,'SimulationMode','rapid');
Simulate Your Model
You can use
set_param to configure the model
parameters (such as the simulation mode and the stop time),
and use the
command to start the simulation:
modelname', 'ReturnWorkspaceOutputs', 'on');
However, the preferred method is to configure model parameters
directly using the
sim command, as
shown in the previous section.
You can substitute
if you do not want to explicitly specify the model name.
Unless target code has already been generated, the
sim command first builds the
executable and then runs the simulation. However, if the
target code has already been generated and no significant
changes have been made to the model (see Code Regeneration in Accelerated Models
for a description), the
executes the generated code without regenerating the code.
This process lets you run your model after making simple
changes without having to wait for the model to
The following sequence shows how to programmatically
myModel in Rapid
Accelerator mode for 10,000 seconds.
myModel, and then type
the following in the Command Window:
simOut = sim('myModel', 'SimulationMode', 'rapid'... 'StopTime', '10000');
sim command again to
simulate after making a change to your model. If
the change is minor (adjusting the gain of a gain
block, for instance), the simulation runs without
Customize the Acceleration Build Process
You can programmatically control the Accelerator mode and Rapid Accelerator mode build process and the amount of information displayed during the build process. See Customize the Build Process for details on why doing so might be advantageous.
Controlling the Build Process
SimCompilerOptimization to set
the degree of optimization used by the compiler
when generating code for acceleration. The
permitted values are
off. The default is
Enter the following at the command prompt to turn on compiler optimization:
set_param('myModel', 'SimCompilerOptimization', 'on')
SimCompilerOptimization is set
on in JIT accelerated mode,
the simulation time for some models improves,
while the build time can become slower.
Controlling Verbosity During Code Generation
to display progress information during code
generation. The permitted values are
The default is
Enter the following at the command prompt to turn on verbose build:
set_param('myModel', 'AccelVerboseBuild', 'on')
- Design Your Model for Effective Acceleration
- Perform Acceleration
- Run Accelerator Mode with the Simulink Debugger