Embedded Matlab in Acclerator Mode
2 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Kaustubha Govind
2012 年 2 月 6 日
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!