Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

执行速度

提高生成的 C/C++ 代码的执行速度

利用代码生成选项和优化来提高所生成代码的执行速度。您可以修改或禁用可能会影响执行速度的动态内存分配。可以使用 parfor 循环生成并行代码。如果可用,可以利用预先存在的经过优化的 C 代码和专用库来加快执行速度。

有关如何针对特定条件优化代码的详细信息,请参阅优化策略

函数

parfor并行 for 循环
coder.varsize声明可变大小数据
coder.const在生成的代码中将表达式折叠为常量
coder.inline控制生成的代码中特定函数的内联
coder.loop.parallelizeParallelize specific for loops in generated code; disable automatic parallelization
coder.unrollUnroll for-loop by making a copy of the loop body for each loop iteration
coder.ceval调用外部 C/C++ 函数

coder.LAPACKCallbackAbstract class for specifying the LAPACK library and LAPACKE header file for LAPACK calls in generated code
coder.BLASCallbackAbstract class for specifying the BLAS library and CBLAS header and data type information for BLAS calls in generated code
coder.fftw.StandaloneFFTW3Interface Abstract class for specifying an FFTW library for FFTW calls in generated code

主题

生成代码优化

memcpy 和 memset 优化

可变大小数组

数组布局

循环

函数调用

数值边情形

外部代码集成

疑难解答

Troubleshooting parfor-Loops

Diagnose errors for code generation of parfor-loops.

MEX Generated on macOS Platform Stays Loaded in Memory

Troubleshoot issues that occur when the source MATLAB® code contains global or persistent variables that are reachable from the body of a parfor-loop.