Embedded Matlab in Acclerator Mode

1 visualización (últimos 30 días)
Matthew
Matthew el 6 de Feb. de 2012
Hi,
I have a large model and I am using the Simulink profiler to find out what blocks are taking my model a long time to run. The profiler tells me that the Embedded Matlab blocks are taking up most of the run time. Normally, we run the model in Rapid Accelerator mode, but the profiler requires that we use Accelerator mode. What is the difference in the way that Simulink handles Embedded Matlab blocks in Accelerator vs Rapid Accelerator Mode? I want to know if these Embedded Matlab blocks are still what is taking the longest time when I run in Rapid Accelerator mode.
I made a simple model with an Embedded Matlab block and ran it in Accelerator and Rapid Accelerator modes then tried looking at the model.c file that is generated with each. It looks like with Rapid Accelerator it inlines the Embedded Matlab code, but with Accelerator mode it creates an S-function. Is the S-function a level 2 m-file S-function? If that is the case it is not surprising that these blocks take the longest time because they are interpreted. If they are level-2 m-file S-functions, is there any way I can tell the model to make C S-functions when running in Accelerator mode?
Finally, is there a way to manually profile the code when running in Rapid Accelerator? I am thinking of something similar to putting tic and toc calls before and after a block. Any help is appreciated. Thanks.

Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 6 de Feb. de 2012
The Embedded MATLAB blocks generate a C-MEX S-function in Normal/Accelerator mode (not an M-file S-function). Like you have observed, the only difference between the two modes should be that the code is inlined in the Rapid Accelerator mode. My guess is that the same blocks would take the longest time in Rapid Accel mode also (assuming that creating the function-call stack is much cheaper than the execution time of your code). Have you tried running your MATLAB code in an M-file S-function or Intepreted MATLAB Function block? For many math operations, MATLAB uses highly optimized libraries, which may be faster than the standalone C code generated by the Embedded MATLAB block. You may be able to speed up your model execution by doing so.
One other way that you might profile your code is by setting up PreOutputs and PostOutputs execution event listeners: http://www.mathworks.com/help/toolbox/simulink/ug/f13-92122.html#f13-92463
You can use tic's return argument (the ticID) in the PreOutputs event and store it in the block's UserData, and access the same ticID in the PostOutputs event to pass to toc.
  1 comentario
Matthew
Matthew el 6 de Feb. de 2012
Thanks for the response.
I don't think I can use the Matlab function block because I need to generate standalone C code using the Realtime Workshop. However, in the past, I tried making C S-functions to replace the Embedded Matlab blocks. I saw modest run-time improvement for code that was just doing simple math operations in embedded for/while loops, but much slower performance for code that was doing matrix operations.
Sounds like I need to see if I can optimize the algorithms that are in the embedded matlab blocks.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by