Mar 15, 2018 - MATLAB Compiler Runtime icon A runtime environment that allows the execution of MATLAB-based applications without having the original.
Description The MATLAB Compiler can be used to create a stand-alone executable from a MATLAB application. This executable can then be run on Biowulf or your local machine without utilizing a MATLAB license. Thus, the compiler can be used to build an executable which can then be run as a on hundreds or thousands of CPUs distributed across the Biowulf cluster. The compiler can also be used to incorporate MATLAB-based algorithms into applications built using C/C,.NET, Java, or Python.
See the for details. Most MATLAB functions can be compiled, but a few cannot. Check to see if your code can be compiled. Users of the NIH HPC systems should call the MATLAB compiler using the function mcc2 which wraps the MATLAB fuction mcc. Mcc2 utlizes the MATLAB compiler license more efficiently than mcc by releasing the license when compilation is completed. See for details. The MATLAB.m files used in these examples, along with other sample files, can be found on Biowulf in the /usr/local/matlab64/extern/examples/compiler directory.
A MATLAB program may produce different results after it has been compiled. Test your application again after compiling to be sure its behavior has not changed. See the articles listed under 'Programming Considerations for Compiling MATLAB code' below to learn how to avoid these issues. MATLAB Component Runtime (MCR) Once MATLAB code has been compiled, it is run using the MATLAB Component Runtime (MCR). There are several versions of the MCR available on the systems. The MCR version must match the version of MATLAB that was used to compile the code. On our systems, the MCR is located in /usr/local/matlab-compiler.
MATLAB to MCR mapping MATLAB Version MCR Version R2018b v95 R2018a v94 R2017b v93 R2017a v92 R2016b v91 R2016a v901 R2015b v90 R2015a v85 R2014b v84 R2014a v83 R2013b v82 R2013a v81 R2012b v80 R2012a v717 R2011b v716 R2011a v715 R2010b v714 R2010a v7.13 R2009b v711. Compilation example The following demonstrates how to compile a.m file and then call the resulting executable. In this example, the user copies the magicsquare.m example file to a new directory in their home space. They then compile it into an executable using mcc2. Several files are generated including a binary executable version of magicsquare and a shell script that sets up runtime libraries to make it easier to run the compiled executable ( runmagicsquare.sh). Finally, the binary is executed using runmagicsquare.sh with arguments providing the location of the (appropriate) MATLAB MCR and the variable for generating the magic square (first 3, then 5).
Magicsquare.m contains the following code. user@cn1234 /matlabcompilertest$ module load matlab/2018b #or different version with different MCR below user@cn1234 /matlabcompilertest$ mcc2 -m -R singleCompThread magicsquare.m Copyright 1984-2018 The MathWorks, Inc. R2018b (9.5.0.944444) 64-bit (glnxa64) August 28, 2018 For online documentation, see For product information, visit www.mathworks.com. user@cn1234 /matlabcompilertest$ ls -l total 108 -rwxr-r- 1 ulloapereza staff 88922 Dec 13 15:32 magicsquare -rw-r-r- 1 ulloapereza staff 124 Jun 27 14:19 magicsquare.m -rw-r-r- 1 ulloapereza staff 102 Dec 13 15:32 mccExcludedFiles.log -rw-r-r- 1 ulloapereza staff 3546 Dec 13 15:32 readme.txt -rw-r-r- 1 ulloapereza staff 6 Dec 13 15:32 requiredMCRProducts.txt -rwxr-r- 1 ulloapereza staff 879 Dec 13 15:32 runmagicsquare.sh The two new files magicsquare and runmagicsquare.sh are most important for our purposes. Finally, the user runs the compiled code directly from the shell by entering the path and name of the run.sh shell script followed by the full path to the correct MCR for the version of matlab used to compile followed by the variable(s) needed by the compiled MATLAB function.
A note on mcc2 vs. Mcc When checked out using mcc, the MATLAB compiler license remains allocated to a user for as long as an interactive session is open, or allocated to a node for a minimum of 30 minutes. The in-house function called mcc2 (used in the examples above) has been written to avoid this problem. Mcc2 compiles MATLAB code and immediately releases the compiler license when finished. Users are strongly encouraged to use mcc2 in place of mcc.
It's usage is identical to mcc. Like mcc, mcc2 is available in the shell environment after loading a matlab module file like so. Compiling a.m file to produce an executable via a MATLAB GUI Open an and start up MATLAB. It is a good idea to test your MATLAB script before compilation by running it at the prompt.
Type deploytool to start the Compiler GUI. In the window that appears, select (for the purposes of this example) 'Application Compiler' to get started. Of course, you can select 'Library Compiler' if you want to build a shared library. (See the for details.) The Application Compiler window will appear on your screen Select the plus sign beside 'Add main file' (highlighted in pink at the top) and in the resultant window, select the MATLAB file that you want to compile Add required files in the 'Files required for your application to run' section. Click the 'Package' button, which is the green check button at the top right. Once your build is complete, follow the instructions above or below on running your compiled code.
Running a swarm of compiled jobs The great advantage of a compiled executable is that a large number of simultaneous jobs can be run on the Biowulf cluster without requiring the use of a MATLAB license. For example, a program could be run with several hundred different sets of parameters. The in-house program is an easy and powerful way to run many processes in parallel on the cluster, also known as a job array. When running a job array, it helps to store the MATLAB runtime on the local file system (in /lscratch/$SLURMJOBID) in order to relieve the central file system of the combined load of accessing the Matlab runtime tree from all of your subjobs. In the following example, the MATLAB program magicsquare takes 1 parameter as input.
Once the program has been compiled either on the or using the, a swarm file can be set up along the following lines. # This file is my-mat-jobs.swarm.
MCR cache location can affect performance When a user executes compiled MATLAB code, MATLAB creates a hidden cache containing binaries, links, scripts, etc. By default this cache will be located in a user's home directory (i.e. Performance of the compiled MATLAB code can be poor if the MCR cache directory is located on a network filesystem and a large number of parallel processes attempt to access it simultaneously.
To address this issue the cache directory can be made local to each node in a swarm. The location of the directory can be determined by setting the MCRCACHEROOT environmental variable. Local scratch space should be requested for this purpose in the swarm or sbatch command. See for more information. The following command could be incorporated into the wrapper script generated by the matlab compiler. Export MCRCACHEROOT=/lscratch/$SLURMJOBID Setting the directory to the value of $SLURMJOBID is important to prevent multiple jobs running on the same nodes from interfering with one another.
Otherwise, one job may attempt to read from a file in the cache while another file is overwriting it. This means the variable must be set after a job has initiated and been assigned a job id. (This approach will work with swarm because each subjob in a job array actually has a unique job id.) If you don't want to manually edit the runX.sh script generated by MATLAB upon compilation, another strategy would be to add this command to each line of you swarm file like so.
Notice The first public version (v1.0) of the SOS software is now available for download. To receive e-mail notification regarding important updates to the software, send a message to [email protected] SOS is free software under the GPL (v3) for non-commercial academic purposes. For other uses, contact the authors.
Download and Install Both standalone executable and source code versions of SOS are available for download. If you have MATLAB (version = 2010a) installed, we recommend that you install the source code version. This will allow you to interact with SOS as you would with any other MATLAB library or standalone package, manipulate and access the SOS variables directly and integrate them with your own code (particularly useful for power users), and generally take advantage of the most stable version of SOS. The current version and installation instructions are included below. The same basic instructions also apply to the which are also available for download. Source Code REcommended Requires MATLAB (version = 2010a) Size 2 mb. Instructions: Uncompress the downloaded file to a location of your choosing and make note of that directory name.
You can then add this directory to your MATLAB path to interact with the SOS source files directly. To do so, you may either use the graphical interface (Menu-File-Set Path.) or via the 'addpath' command in the command line interface (type 'help addpath' in MATLAB for additional information). Standalone Executable Recommended only if you do not have MATLAB The standalone executable version is broken down into two separate downloads. The first consists of the MATLAB component runtime (MCR) which is required to run the standalone software. If you do not already have this installed on your system, you will need to install it before running SOS. If your operating system is not listed below In principle, SOS can be run as a standalone executable on any operating system that can run a current version of MATLAB (2010a+).
However, to create a standalone executable we require access to a machine running that operating system and with the MATLAB compiler installed so that we can compile SOS into a standalone application. Currently, binaries have been compiled into standalone executables for the major operating systems and versions listed below. Contact [email protected] with your operating system information if your system is not currently supported. MATLAB Runtime Component (MCR) (Required if not installed) Note: It is possible that using an older OR more recent version of the MCR than that used when compiling the standalone binaries of SOS may prevent SOS from running successfully. If you experience problems running the standalone version of SOS, please try reinstalling the MCR with one of the specific versions below. Note that by default the MCR may be installed to a common location for all users and may request 'administrator' or 'root' access when doing so. Although you may choose to install the MCR at this location, it is not necessary, and you may install it for your own user account only and in your personal (home) directory.
Size 200 mb Version: MCR version 7.13, MATLAB 2010a. Version: MCR version 7.14.1, MATLAB 2010b; Compiler 4.14.1. Instructions: Uncompress the archive and run the installer (win: MCRInstaller.exe; linux: MCRInstaller.bin; OSX: MCRInstaller.dmg). Make note of the directory in which you install the MCR as you may need this information when running SOS.
Standalone Executable Size 2 mb Version: SOS 1.0, MCR version 7.13; MATLAB 2010a. Version: SOS 1.0, MCR version 7.14.1, MATLAB 2010b. Running SOS Once these setup files have been downloaded and installed, you may wish to visit the page for startup information.