Main Content

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

执行速度

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

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

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

函数

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

coder.BLASCallbackAbstract class for specifying the BLAS library and CBLAS header and data type information for BLAS calls in generated code
coder.LAPACKCallbackAbstract class for specifying the LAPACK library and LAPACKE header file for LAPACK calls in generated code
coder.fftw.StandaloneFFTW3Interface Abstract class for specifying an FFTW library for FFTW calls in generated code
coder.loop.ControlLoop optimization control object (自 R2023a 起)

主题

生成代码优化

memcpy 和 memset 优化

可变大小数组

数组布局

循环

函数调用

数值边缘情形

外部代码集成

疑难解答

parfor 循环故障排除

诊断 parfor 循环的代码生成错误。

Resolve Issue: coder.inline("never") and coder.nonInlineCall Do Not Prevent Function Inlining

Troubleshoot instances of coder.inline('never') not preventing inlining.

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.