Main Content

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 in the MATLAB Coder App

  1. To open the Generate dialog box, click the Generate arrow .

  2. Set Build type to MEX.

  3. Select the Use JIT compilation check box.

Specify Use of JIT Compilation at the Command Line

Use the -jit option of the codegen command. For example, specify JIT compilation for myfunction:

codegen -config:mex myfunction -jit -report

Alternatively, use the EnableJIT code configuration parameter.

cfg = coder.config('mex');
cfg.EnableJIT = true;
codegen -config cfg myfunction -report

JIT Compilation Incompatibilities

The following table summarizes code generation features or options that are incompatible with JIT compilation.

IncompatibilityMessage TypeGenerated MEXAction
Custom CodeWarningC/C++ MEXTo avoid the warning, disable JIT compilation.
Updating build information (coder.updateBuildInfo)WarningC/C++ MEXTo avoid the warning, disable JIT compilation.
Use of OpenMP application interface for parallelization of for-loops (parfor)Warning
  • JIT MEX

  • No parallelization

If you want parallelization of for-loops, disable JIT compilation.
Generation of C/C++ source code onlyErrorNoneSpecify either JIT compilation or generation of C/C++ code only.

See Also

Functions

Objects

Related Topics