This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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

With the accelbuild command, you can build a JIT accelerated execution engine without actually simulating the model. For example, to build an Accelerator mode simulation of myModel:

accelbuild myModel

Control Simulation

You can control the simulation mode from the command line prompt by using the set_param command:


The simulation mode can be normal, accelerator, rapid, or external.

For example, to simulate your model with the Accelerator mode, you would use:

However, a preferable method is to specify the simulation mode within the sim command:
simOut = sim('myModel', 'SimulationMode', 'accelerator');

You can use bdroot to set parameters for the currently active model (that is, the active model window) rather than 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 sim command to start the simulation:

sim('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 gcs for modelname 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 sim command 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 rebuild.

Simulation Example

The following sequence shows how to programmatically simulate myModel in Rapid Accelerator mode for 10,000 seconds.

First open myModel, and then type the following in the Command Window:

simOut = sim('myModel', 'SimulationMode', 'rapid'...
'StopTime', '10000');

Use the sim command again to resimulate 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 regenerating code.

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

Use SimCompilerOptimization to set the degree of optimization used by the compiler when generating code for acceleration. The permitted values are on or off. The default is off.

Enter the following at the command prompt to turn on compiler optimization:

set_param('myModel', 'SimCompilerOptimization', 'on')

When SimCompilerOptimization is set to on in JIT accelerated mode, the simulation time for some models improves, while the build time can become slower.

Controlling Verbosity During Code Generation

Use the AccelVerboseBuild parameter to display progress information during code generation. The permitted values are on or off. The default is off.

Enter the following at the command prompt to turn on verbose build:

set_param('myModel', 'AccelVerboseBuild', 'on')

Related Examples

More About

Was this topic helpful?