Skip to Main Content Skip to Search
Product Documentation

Setting MEX Compilation Options

Working with the MEX Compiler Configuration Object

For MEX code generation, MATLAB provides a configuration object coder.MEXConfig for fine-tuning the compilation. To set MEX compilation options:

  1. Define the compiler configuration object in the MATLAB workspace by issuing a constructor command:

    comp_cfg = coder.mexconfig

    MATLAB displays the list of compiler options and their current values in the command window.

  2. Modify the compilation options as necessary. See Modifying Compilation Options at the Command Line Using Dot Notation

  3. Invoke fiaccel with the -config option and specify the configuration object as its argument:

    fiaccel -config comp_cfg myMfile

    The -config option instructs fiaccel to convert myFile.m to a MEX function, based on the compilation settings in comp_cfg.

Modifying Compilation Options at the Command Line Using Dot Notation

Use dot notation to modify the value of compilation options, using this syntax:

configuration_object.property = value

Dot notation uses assignment statements to modify configuration object properties. For example, to change the maximum size function to inline and the stack size limit for inlined functions during MEX generation, enter this code at the command line:

co_cfg = coder.MEXConfig
co_cfg.InlineThreshold = 25;
co_cfg.InlineStackLimit = 4096;
fiaccel -config co_cfg myFun

MEX Configuration Dialog Box Options

The following table describes parameters for fine-tuning the behavior of fiaccel for converting MATLAB files to MEX:

ParameterEquivalent Command-Line Property and Values
(default in bold)
Description
Report
Create code generation reportGenerateReport
true, false
Document generated code in an HTML report.
Launch report automaticallyLaunchReport
true, false
Specify whether to automatically display HTML reports after code generation completes.

    Note   Requires that you enable Create code generation report

Debugging
Echo expressions without semicolonsEchoExpressions
true, false
Specify whether or not actions that do not terminate with a semicolon appear in the MATLAB Command Window.
Enable debug buildEnableDebugging
true, false
Compile the generated code in debug mode.
Language and Semantics
Constant Folding TimeoutConstantFoldingTimeout
integer, 10000
Specify the maximum number of instructions to be executed by the constant folder.
Dynamic memory allocationDynamicMemoryAllocation
'off', 'AllVariableSizeArrays'

Enable dynamic memory allocation for variable-size data. By default, dynamic memory allocation is disabled and fiaccel allocates memory statically on the stack. When you select dynamic memory allocation, fiaccel allocates memory for all variable-size data dynamically on the heap.

You must use dynamic memory allocation for all unbounded variable-size data.

Enable variable sizingEnableVariableSizing
true, false
Enable support for variable-size arrays.
Extrinsic callsExtrinsicCalls
true, false

Allow calls to extrinsic functions.

When enabled (true), the compiler generates code for the call to a MATLAB function, but does not generate the function's internal code.

When disabled (false), the compiler ignores the extrinsic function. Does not generate code for the call to the MATLAB function—as long as the extrinsic function does not affect the output of the caller function. Otherwise, the compiler issues a compiler error.

Global Data Synchronization ModeGlobalDataSyncMethod
string,SyncAlways, SyncAtEntryAndExits, NoSync

Controls when global data is synchronized with the MATLAB global workspace. By default, (SyncAlways), synchronizes global data at MEX function entry and exit and for all extrinsic calls. This synchronization ensures maximum consistency between MATLAB and generated code. If the extrinsic calls do not affect global data, use this option with the coder.extrinsic -sync:off option to turn off synchronization for these calls.

SyncAtEntryAndExits synchronizes global data at MEX function entry and exit only. If only a few extrinsic calls affect global data, use this option with the coder.extrinsic -sync:on option to turn on synchronization for these calls.

NoSync disables synchronization. Ensure that your generated code does not interact with MATLAB before disabling synchronization. Otherwise, inconsistencies might occur.

Saturate on integer overflowSaturateOnIntegerOverflow
true, false
Add checks in the generated code to detect integer overflow or underflow.
Safety (disable for faster MEX)
Ensure memory integrityIntegrityChecks
true, false
Detects violations of memory integrity in code generated from MATLAB algorithms and stops execution with a diagnostic message. Setting IntegrityChecks to false also disables the run-time stack.
Ensure responsivenessResponsivenessChecks
true, false
Enables responsiveness checks in code generated from MATLAB algorithms.
Function Inlining and Stack Allocation
Inline Stack LimitInlineStackLimit
integer, 4000
Specify the stack size limit on inlined functions.
Inline ThresholdInlineThreshold
integer, 10
Specify the maximum size of functions to be inlined.
Inline Threshold MaxInlineThresholdMax
integer, 200
Specify the maximum size of functions after inlining.
Stack Usage MaxStackUsageMax
integer, 200000
Specify the maximum stack usage per application in bytes. Set a limit that is lower than the available stack size. Otherwise, a runtime stack overflow might occur. Overflows are detected and reported by the C compiler, not by fiaccel.
Optimizations
Use BLAS library if possibleEnableBLAS
true, false
Speed up low-level matrix operations during simulation by calling the Basic Linear Algebra Subprograms (BLAS) library.

See Also

How fiaccel Resolves Conflicting Options

fiaccel takes the union of all options, including those specified using configuration objects, so that you can specify options in any order.

  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS