Vitesse d’exécution
Utilisez des options et des optimisations de la génération de code pour augmenter la vitesse d’exécution du code généré. Vous pouvez modifier ou désactiver l’allocation dynamique de mémoire qui peut avoir un impact sur la vitesse d’exécution. Le code parallélisé peut être généré avec des boucles parfor
. Lorsqu’ils sont disponibles, exploitez du code C optimisé préexistant et des bibliothèques spécialisées pour accélérer l’exécution.
Pour plus d’informations sur l’optimisation du code pour des conditions particulières, consultez Optimize Generated C/C++ and MEX Code.
Fonctions
Classes
coder.BLASCallback | Abstract class for specifying the BLAS library and CBLAS header and data type information for BLAS calls in generated code |
coder.LAPACKCallback | Abstract 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.Control | Customize loop optimizations in generated code (depuis R2023a) |
Rubriques
Optimisation du code généré
- Optimize Generated C/C++ and MEX Code
Optimize the execution speed or memory usage of generated C/C++ and MEX code. - MATLAB Coder Optimizations in Generated Code
To improve the performance of generated code, the code generator uses optimizations. - Optimize Implicit Expansion in Generated Code
Implicit expansion in the generated code is enabled by default.
Optimisations memcpy et memset
- memcpy Optimization
The code generator optimizes generated code by usingmemcpy
. - memset Optimization
The code generator optimizes generated code by usingmemset
.
Tableaux de taille variable
- Dynamic Memory Allocation and Performance
Dynamic memory allocation can slow down execution speeds. - Provide Maximum Size for Variable-Size Arrays
Use techniques to help the code generator determine the upper bound for a variable-size array. - Disable Dynamic Memory Allocation During Code Generation
Disable dynamic memory allocation in the app or at the command line. - Set Dynamic Memory Allocation Threshold
Disable dynamic memory allocation for arrays less than a certain size. - Optimize Dynamic Array Access
Improve execution time of dynamic arrays in generated C code.
Disposition des tableaux
- Generate Code That Uses Row-Major Array Layout
Generate C/C++ code with row elements stored contiguously in memory.
Boucles
- Algorithm Acceleration Using Parallel for-Loops (parfor)
Generate MEX functions forparfor
-loops. - Classification of Variables in parfor-Loops
Variables insideparfor
-loops are classified as loop, sliced, broadcast, reduction, or temporary. - Specify Maximum Number of Threads in parfor-Loops
Generate a MEX function that executes loop iterations in parallel on specific number of available cores. - Specify Maximum Number of Threads to Run Parallel for-Loops in the Generated Code
Run parallelfor
-loops on specific number of available cores in the generated code. - Reduction Assignments in parfor-Loops
A reduction variable accumulates a value that depends on all the loop iterations together. - Control Compilation of parfor-Loops
Treatparfor
-loops asparfor
-loops that run on a single thread. - Installer une bibliothèque OpenMP sur la plateforme macOS
Installer une bibliothèque OpenMP pour générer des bouclesfor
parallèles sur la plateforme macOS. - Minimize Redundant Operations in Loops
Move operations outside of loop when possible. - Unroll for-Loops and parfor-Loops
Control loop unrolling. - Automatic Parallelization of for-Loops in the Generated Code
MATLAB® Coder™ automatically parallelizesfor
-loops in generated C/C++ code by default, using the Open Multiprocessing (OpenMP) library. - Reduction Operations Supported for Automatic Parallelization of for-loops
Supported operations for automatic parallelization offor
-loops. - Generate SIMD Code from MATLAB Functions for Intel Platforms
Improve the execution speed of the generated code using Intel® SSE and Intel AVX technology. - Optimize Loops in Generated Code
Generate code with loop transformations according to your performance requirements.
Appels de fonctions
- Avoid Data Copies of Function Inputs in Generated Code
Generate code that uses pass-by-reference for input arguments. - Control Inlining to Fine-Tune Performance and Readability of Generated Code
Inlining eliminates the overhead of function calls but can produce larger C/C++ code and reduce code readability.
Cas numériques extrêmes
- Disable Support for Integer Overflow or Nonfinites
Improve performance by suppressing generation of supporting code to handle integer overflow or nonfinites.
Intégration de code externe
- LAPACK Calls in Generated Code
LAPACK function calls improve the execution speed of code generated for certain linear algebra functions. - BLAS Calls in Generated Code
BLAS function calls improve the execution speed of code generated for certain low-level vector and matrix operations. - Optimize Generated Code for Fast Fourier Transform Functions
Choose the correct fast Fourier transform implementation for your workflow and target hardware. - Integrate External/Custom Code
Improve performance by integrating your own optimized code. - Speed Up of Standalone Generated Code Using Preconfigured BLAS and LAPACK Callbacks
Use BLAS and LAPACK calls to improve the execution speed of generated code. - Speed Up Linear Algebra in Generated Standalone Code by Using LAPACK Calls
Generate LAPACK calls for certain linear algebra functions. Specify LAPACK library to use. - Speed Up Matrix Operations in Generated Standalone Code by Using BLAS Calls
Generate BLAS calls for certain low-level matrix operations. Specify BLAS library to use. - Speed Up Fast Fourier Transforms in Generated Standalone Code by Using FFTW Library Calls
Generate FFTW library calls for fast Fourier transforms. Specify the FFTW library. - Synchronize Multithreaded Access to FFTW Planning in Generated Standalone Code
Implement FFT library callback class methods and provide supporting C code to prevent concurrent access to FFTW planning.
Résolution des problèmes
Diagnose errors for code generation of parfor
-loops.
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.