Simulink: Accelerator handles parameter change from script, but Rapid Accelerator fails to rebuild

I read the answer to "What makes Rapid Accelerator regenerate code?" which is related to my problem, but I'm still confused.
I want to benchmark Accelerator and Rapid Accelerator to see which makes more sense with a given model, but I discovered that I cannot use Rapid Accelerator unless I delete the slprj directory and the _acc.mexw32 file. If I don't do this, my model does not absorb changes made to parameters through a script. Normal and Accelerator modes work fine.
I'm using 2011a and to recreate my problem using a simple model, I show the effect on changing a decimation parameter D on a To Workspace block. If the parameter is changed from 2 to 3, it should print a different sequence to the screen. It fails under Rapid Accelerator. I tried setting Rebuild to Always (under Configuration Parameters > Model Referencing), but I get the same result.
Am I doing something wrong?
Here is what I did:
Connect a Counter Limited block (Upper limit = 10, Sample time = 1) to a To Workspace block (changing only the Decimation option - use D which is set in the script).
Simulation > Configuration Parameters > Change Solver to discrete
Name the model accel_test.mdl, and close it (or leave it open - the result is the same)
Matlab script which runs the model:
%%accel_test_run1.m
% This script recreates an issue where changing a parameter in this script and then using
% Rapid Accelerator gives an incorrect result. Normal and Accelerator modes work as
% expected
% Dara Parsavand 2011-08-01
%%Initialize
clear, clc
modelname = 'accel_test';
%%Loop over cases
for sim_flag = 1:4
% sim_flag definitions
% 0 = don't sim (just assign parameters)
% 1 = normal
% 2 = accelerator
% 3 = rapid accelerator
% 4 = delete files + rapid accelerator
for D = 2:3
fprintf('\nUsing sim_flag = %d, D = %d\n',sim_flag,D)
tic
%%Compile and Sim Model
load_system(modelname)
switch sim_flag
case 1 % Normal
set_param(modelname, 'simulationmode', 'normal')
case 2 % Accelerator
set_param(modelname, 'simulationmode', 'accelerator')
case 3 % Rapid Accelerator
set_param(modelname, 'simulationmode', 'rapid')
case 4 % Delete Files + Rapid Accelerator
% Delete files
[stat, mess, id] = rmdir('slprj','s');
delete([modelname '_acc.mexw32']);
% Build and Simulate Model
accelbuild(modelname)
set_param(modelname, 'simulationmode', 'rapid')
end
% cs1 = Simulink.BlockDiagram.getChecksum(modelname)
sim(modelname);
fprintf('Simulation completed in %0.2f sec\n', toc)
%%Print Results
simout.signals.values
end
end

Answers (1)

Please contact technical support with your example model if the rapid accelerator does not rebuild when you think it should.
On a short term, to force a rebuild of the rapid accelerator, you can use this line:
Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl)

Categories

Asked:

on 1 Aug 2011

Community Treasure Hunt

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

Start Hunting!