Speed Up MEX Generation by Using JIT Compilation
To speed up generation of a MEX function, specify use of just-in-time (JIT) compilation technology. When you iterate between modifying MATLAB® code and testing the MEX code, using this option can save time.
By default, MATLAB Coder™ creates a C/C++ MEX function by generating and compiling C/C++ code. When you specify JIT compilation, MATLAB Coder creates a JIT MEX function that contains an abstract representation of the MATLAB code. When you run the JIT MEX function, MATLAB generates the executable code in memory.
JIT compilation is incompatible with certain code generation features or options. See JIT Compilation Incompatibilities. If JIT compilation is enabled, the
absence of warning or error messages during code generation indicates
successful JIT compilation. In a code generation
report, the Summary tab indicates that the Build
Type is JIT MEX Function
.
Note
JIT MEX functions are not compatible across different releases of MATLAB Coder software. Run the JIT MEX function by using MATLAB Coder software of the same release that you used to generate the function.
Specify Use of JIT Compilation
To instruct the code generator to use JIT compilation for MEX function generation, use one of these approaches:
In a code configuration object, set the
EnableJIT
property totrue
.In the Code Generation Settings dialog box, select the Use JIT compilation for build type of MEX check box.
JIT Compilation Incompatibilities
The following table summarizes code generation features or options that are incompatible with JIT compilation.
Incompatibility | Message Type | Generated MEX | Action |
---|---|---|---|
Custom Code | Warning | C/C++ MEX | To avoid the warning, disable JIT compilation. |
Updating build information (coder.updateBuildInfo ) | Warning | C/C++ MEX | To avoid the warning, disable JIT compilation. |
Use of OpenMP application interface for parallelization of for -loops
(parfor ) | Warning |
| If you want parallelization of for -loops,
disable JIT compilation. |
Generation of C/C++ source code only | Error | None | Specify either JIT compilation or generation of C/C++ code only. |