- Code in External mode is compiled using a different compiler with different optimization capabilities and running in entirely different environment. Strictly speaking, there is no reason for the performance of the code to be identical or even similar, except for the fact that different compilers use similar optimizations after all, and that the environment (runtime library, OS support) usually has similar performance when doing similar tasks. Apparently, your S-function might be using something that is much slower in External mode compiled code and/or libraries than it is in Normal mode code. This will be difficult to locate though. Potential candidates are math functions (sin, cos, exp, ...), string manipulation functions, or any library function in general, provided that it is called many times during the mdlOutputs or mdlUpdate method (or model_step if they are using this code format). Most likely, this will happen in the innermost loop if there are nested loops in the code.
- The only way to diagnose this would be disable pieces of code in the S-function (replacing the code by some dummy operation like returning a constant) until the piece of code responsible for the slow performance is found - starting with bigger pieces, then refining to a group of functions or even to a single function. I understand that this is a time-consuming iterative process, but there are not many alternatives.
- External mode has been never designed for long-running tasks. Let's say a task taking 10 seconds is already too much for a single task to execute. Often times, a long running task is aborted by Windows on the assumption that the CPU has stopped responding. The maximum execution time of a single External mode task is about 1 second; for longer tasks, Normal mode is recommended otherwise.
S-function performance in SLDRT external mode
6 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2020-10-8
编辑: MathWorks Support Team
2023-6-21
Why does my S-function run faster in SLDRT normal mode than external mode?
采纳的回答
MathWorks Support Team
2023-6-21
编辑:MathWorks Support Team
2023-6-21
S-function has very limited support in external mode. Try inline S-functions, to see if it boosts the performance. With that said, see the following points:
You can read about inline S-functions and their performance here:
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!