Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB Compiler   

Working with the MCR

Understanding the MCR

MATLAB Compiler was designed to work with a large range of applications that use the MATLAB programming language. Because of this, run-time libraries are large.

If you do not have MATLAB installed on the target machine and you want to run components created by MATLAB Compiler , you still need to install the MCR on the target machine, whether you are a developer or end user. You have to install the MCR only once. There is no way to distribute your application with any subset of the files that are installed by the MCRInstaller.

You can install the MCR by running MCRInstaller.exe.

On platforms other than Windows, you must also set paths and environment variables. See Directories Required for Run-Time Deployment for more information about these settings.

See Deploying to End Users for more information about the general steps for installing the MCR as part of the deployment process.

See also Using MCR Installer Command Line Options for more information.

Installing the MCR and MATLAB on the Same Machine

You do not need to install the MCR on your machine if your machine has both MATLAB and MATLAB Compiler installed. The version of MATLAB should be the same as the version of MATLAB that was used to create the deployed component.

Modifying the Path

If you install the MCR on a machine that already has MATLAB on it, you must adjust the library path according to your needs.

Windows.   To run deployed components against the MCR install, mcr_root\ver\runtime\win32|win64 must appear on your system path before matlabroot\runtime\win32|win64.

If mcr_root\ver\runtime\arch appears first on the compiled application path, the application uses the files in the MCR install area.

If matlabroot\runtime\arch appears first on the compiled application path, the application uses the files in the MATLAB Compiler installation area.

UNIX.   To run deployed components against the MCR install, on Linux, Linux x86-64, or Solaris, the <mcr_root>/runtime/<arch> folder must appear on your LD_LIBRARY_PATH before matlabroot/runtime/<arch>, and XAPPLRESDIR should point to <mcr_root>/X11/app-defaults. See Directories Required for Run-Time Deployment for the platform-specific commands.

To run deployed components on Mac OS X, the <mcr_root>/runtime folder must appear on your DYLD_LIBRARY_PATH before matlabroot/runtime, and XAPPLRESDIR should point to <mcr_root>/X11/app-defaults.

To run MATLAB on Mac OS X or Intel® Mac, matlabroot/runtime must appear on your DYLD_LIBRARY_PATH before the <mcr_root>/bin folder, and XAPPLRESDIR should point to matlabroot/X11/app-defaults.

Installing Multiple MCRs on One Machine

MCRInstaller supports the installation of multiple versions of the MCR on a target machine. This allows applications compiled with different versions of the MCR to execute side by side on the same machine.

If you do not want multiple MCR versions on the target machine, you can remove the unwanted ones. On Windows, run Add or Remove Programs from the Control Panel to remove any of the previous versions. On UNIX, you manually delete the unwanted MCR. You can remove unwanted versions before or after installation of a more recent version of the MCR, as versions can be installed or removed in any order.

Deploying a Recompiled Application

Always run your compiled applications with the version of the MCR that corresponds to the MATLAB version with which your application was built. If you upgrade your MATLAB Compiler software on your development machine and distribute the recompiled application to your users, you should also distribute the corresponding version of the MCR. Users should upgrade their MCR to the new version. If users need to maintain multiple versions of the MCR on their systems, refer to Installing Multiple MCRs on One Machine for more information.

Retrieving MCR Attributes

Use these new functions to return data about MCR state when working with shared libraries (this does not apply to standalone applications).

Function and SignatureWhen to UseReturn Value
bool mclIsMCRInitialized()Use mclIsMCRInitialized() to determine whether or not the MCR has been properly initialized.Boolean (true or false).
Returns true if MCR is already initialized, else returns false.
bool mclIsJVMEnabled()Use mclIsJVMEnabled() to determine if the MCR was launched with an instance of a Java Virtual Machine (JVM).Boolean (true or false).
Returns true if MCR is launched with a JVM instance, else returns false.
const char* mclGetLogFileName()Use mclGetLogFileName() to retrieve the name of the log file used by the MCRCharacter string representing log file name used by MCR
bool mclIsNoDisplaySet()Use mclIsNoDisplaySet() to determine if -nodisplay option is enabled.Boolean (true or false).
Returns true if -nodisplay is enabled, else returns false.

    Note   false is always returned on Windows systems since the -nodisplay option is not supported on Windows systems.

      Caution   When running on Mac, if -nodisplay is used as one of the options included in mclInitializeApplication, then the call to mclInitializeApplication must occur before calling mclRunMain.

Example: Retrieving Information from MCR State

 const char* options[4];     
    options[0] = "-logfile";    
    options[1] = "logfile.txt";
    options[2] = "-nojvm";
    options[3] = "-nodisplay"; 
    if( !mclInitializeApplication(options,4) )
    {
        fprintf(stderr, 
                "Could not initialize the application.\n");
        return -1;
    }
    printf("MCR initialized : %d\n", mclIsMCRInitialized());
    printf("JVM initialized : %d\n", mclIsJVMEnabled());
    printf("Logfile name : %s\n", mclGetLogFileName());
    printf("nodisplay set : %d\n", mclIsNoDisplaySet());
    fflush(stdout);

Improving Data Access Using the MCR User Data Interface

The MCR User Data Interface lets you easily access MCR data. It allows keys and values to be passed between an MCR instance, the M-code running on the MCR, and the wrapper code that created the MCR. Through calls to the MCR User Data Interface API, you access MCR data by creating a per-MCR-instance associative array of mxArrays, consisting of a mapping from string keys to mxArray values. Reasons for doing this include, but are not limited to the following:

The API consists of:

For implementations using .NET components, Java components, or COM components with Excel, see the MATLAB Builder NE User's Guide, MATLAB Builder JA User's Guide, and MATLAB Builder EX User's Guide, respectively.

MATLAB Functions

Use the M-language functions getmcruserdata and setmcruserdata from deployed M applications. They are loaded by default only in applications created with the MATLAB Compiler or builder products. See Functions — Alphabetical List, for more information.

External C Functions

Use the following C functions in deployed C/C++ applications. See Functions — Alphabetical List for more information.

Setting MCR Data for Standalone Executables

MCR data can be set for a standalone executable with the -mcruserdata command line argument.

The following example demonstrates how to set MCR user data for use with a Parallel Computing Toolbox configuration .mat file:

 parallelapp.exe -mcruserdata 
                  ParallelConfigurationFile:config.mat

The argument following -mcruserdata is interpreted as a key/value MCR user data pair, where the colon separates the key from the value. The standalone executable accesses this data by using getmcruserdata.

Setting and Retrieving MCR Data for Shared Libraries

As mentioned in Improving Data Access Using the MCR User Data Interface, there are many possible scenarios for working with MCR Data. The most general scenario involves setting the MCR with specific data for later retrieval, as follows:

  1. Outside the scope of your main code, use libnameGetMcrID to retrieve the key value of the MCR data you want to update.

  2. In your code, Include the MCR header file and the library header generated by MATLAB Compiler.

  3. Properly initialize your application using mclInitializeApplication.

  4. After creating your input data, write or "set" it to the MCR with setmcruserdata or mclSetMCRUserData, as appropriate. Use mclSetCmdLineUserData to set data from the command line.

  5. After calling functions or performing other processing, retrieve the new MCR data with getmcruserdata or mclGetMCRUserData, as appropriate.

  6. Free up storage memory in work areas by disposing of unneeded arrays with mxDestroyArray.

  7. Shut down your application properly with mclTerminateApplication.

Example: MagicMatrix.   This following is an end-to-end example showing how to set and retrieve MCR data with the magicmatrix application and the MCR User Data interface API:

 Building on UNIX

 Building on Windows

 Running on UNIX

 Running on Windows

 Running on 64-bit Macintosh

 magicmatrix.c

Deploying Applications Created Using Parallel Computing Toolbox

For information about creating and exporting configurations from Parallel Computing Toolbox applications, see Programming with User Configurations.

For information about using the MCR User Data Interface see "Improving Data Access Using the MCR User Data Interface" in the MATLAB Builder JA, MATLAB Builder NE, and MATLAB Builder EX user guides.

For a complete working example describing how to use Parallel Computing Toolbox with MATLAB Builder JA, see Example: Supplying Run-Time Configuration Information for Parallel Computing Toolbox Applications.

Displaying MCR Initialization Start-Up and Completion Messages For Users

You can display a console message for end users that informs them when MCR initialization starts and completes.

To create these messages, use the -R option of the mcc command.

You have the following options:

Some examples of different ways to invoke this option follow:

This command:Displays:
mcc -R -startmsgDefault start-up message Initializing MATLAB Compiler Runtime version x.xx
mcc -R -startmsg,'user customized message'Default start-up message Initializing MATLAB Compiler Runtime version x.xx and user customized message for start-up
mcc -R -completemsg,'user customized message'Default start-up message Initializing MATLAB Compiler Runtime version x.xx and user customized message for completion
mcc -R -startmsg,'user customized message' -R -completemsg,'user customized message" Default start-up message Initializing MATLAB Compiler Runtime version x.xx and user customized message for both start-up and completion by specifying -R before each option
mcc -R -startmsg,'user customized message',-completemsg,'user customized message'Default start-up message Initializing MATLAB Compiler Runtime version x.xx and user customized message for both start-up and comlpetion by specifying -R only once

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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