Control Compilation of parfor-Loops - MATLAB & Simulink (original) (raw)
Main Content
By default, MATLAB® Coder™ generates code that can run the parfor
-loop on multiple threads. To treat the parfor
-loops as for-loops that run on a single thread, disable parfor
with one of these methods:
- By using the codegen function with
-O disable:openmp
option at the command line. - By using a code generation configuration object with the property
EnableOpenMP
set to false. For example:
cfg = coder.config('lib');
cfg.EnableOpenMP = false;
codegen myFunction -config cfg - By setting Enable OpenMP library if possible to
No
under All Settings tab in the project settings dialog box.
When to Disable parfor
Disable parfor if you want to:
- Compare the execution times of the serial and parallel versions of the generated code.
- Investigate failures. If the parallel version of the generated code fails, disable
parfor
and generate a serial version to facilitate debugging. - Use C compilers that do not support OpenMP.