Main Content

执行速度

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

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

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

函数

coder.areUnboundedVariableSizedArraysSupportedCheck if current configuration settings allow unbounded variable-size arrays (自 R2024a 起)
coder.ceval从生成的代码中调用 C/C++ 函数
coder.const在生成的代码中将表达式折叠为常量
coder.inline控制生成代码中当前函数的内联
coder.inlineCallInline called function in generated code (自 R2024a 起)
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.loop.vectorizeVectorize for loops in generated code (自 R2023a 起)
coder.nonInlineCallPrevent inlining of called function in generated code (自 R2024a 起)
coder.unroll通过为每次循环迭代生成循环体的副本来展开 for 循环
coder.varsize声明可变大小数据
parfor并行 for 循环

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 优化

  • memcpy 优化
    代码生成器通过使用 memcpy 来优化生成的代码。
  • memset 优化
    代码生成器通过使用 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.