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 aC/C++ MEXfunction by generating and compiling C/C++ code. When you specify JIT compilation,MATLAB Codercreates aJIT MEXfunction 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. SeeJIT 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, theSummarytab indicates that theBuild TypeisJIT MEX Function.

Note

JIT MEX functions are not compatible across different releases ofMATLAB Codersoftware. Run the JIT MEX function by usingMATLAB Codersoftware of the same release that you used to generate the function.

Specify Use of JIT Compilation in theMATLABCoder应用程序

  1. To open theGeneratedialog box, click theGeneratearrow.

  2. SetBuild typetoMEX.

  3. Select theUse JIT compilationcheck box.

Specify Use of JIT Compilation at the Command Line

Use the-jitoption of thecodegen命令。为example, specify JIT compilation formyfunction:

codegen-config:mexmyfunction-jit-report

Alternatively, use theEnableJITcode configuration parameter.

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

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 offor-loops (parfor) Warning
  • JIT MEX

  • No parallelization

If you want parallelization offor-loops, disable JIT compilation.
Generation of C/C++ source code only Error None Specify either JIT compilation or generation of C/C++ code only.

See Also

Functions

Objects

Related Topics