Welcome to our Support Center
< All Topics
Print

Use Matlab’s deploytool to Avoid Using Toolbox Licenses on the MLSC Batch Cluster

Using deploytool in MATLAB (version Oct 2014)


This page outlines an easy procedure for deploying MATLAB applications into a script that does not require the use of any license. There will be no license limitations on the number of instances you can run on a cluster once your code has been deployed.

Disclaimer

  • Tested in MATLAB version v8.3 (R2014a), MCR V.8.2.If you want to deploy a script to use on a cluster (e.g. the Martinos center’s), I believe you will need to use MATLAB on Linux (e.g. on the Martinos center’s computers), not on Windows. If you use the same procedure on Windows, you will create a .exe instead of a .sh script. There might be a way to create a .sh script on Windows, but I am unaware of it at the moment; please let me know if you find one.

  • It is not the intention of the author of this web page to provide further scripting or command support than what is included in this webpage. This webpage has been written to provide support to the Martinos center cluster users, but can easily be used elsewhere.



Step 1: Modify your script accordingly

  • To interface your MATLAB script with unix make sure all your input parameters (if any) are plain strings, and that all output is written out to files (whatever the format, could be text files with fwrite/dlmwrite, MRI images with MRIwrite, MATLAB .mat files with save, etc). Simple examples are provided here.

  • You should avoid using parfor (parallel for loop) and parallel tools in MATLAB as you will be able to launch multiple instances of your application anyway (e.g. if you want to process several subjects).

  • You should also avoid using addpath in your MATLAB script and instead, add paths during deployment as described below.

Step 2: Deploy your script

  • Type deploytool at the MATLAB prompt. This produces a pop-up window to choose between Application Compiler and Library Compiler, the latter being beyond the scope of this document, select Application Compiler. This will open the Deploytool window with the APPLICATION TYPE preset to Standalone Application. Note that the Martinos launchpad has only two copies of the MATLAB Compiler license, so you should check with the command lmstat -a to see if either of them are free, and make sure to free up your license as soon as you are done compiling.

  • For MAIN FILE Add main file click the big plus and browse to the MATLAB script to be deployed. You need to be on Linux to produce a .sh script, otherwise it will produce a .exe file if you are on Windows.

  • Click the SETTINGS gear icon to set the location of your script. Under Additional parameters passed to MCC: you can add additional flags to the MCC command.

  • At any time you can click FILE Save to save your project to a *.prj project file that stores your project information in xml format.

  • Under PACKAGE click the Package check mark to deploy your script. If your MATLAB file is at ~/matlab/myscript.m, this will create (by default) a folder at ~/matlab/myscript/ inside of which it will create subdirectories called ~/matlab/myscript/for_testing and ~matlab/myscript/for_redistribution.

Step 3: Using the script

  • You will need to define an environment variable defining the path to the installed ‘MATLAB Complier Runtime’ MCR package. If you are at the Martinos center, you can simply define it by typing

      setenv MCR /usr/pubsw/common/matlab/current  # if your shell is tcsh
      export MCR=/usr/pubsw/common/matlab/current  # if your shell is bash

    Change current to a specific version if you used a different version of MATLAB deploytool above.

  • If you want to use the script on your own computer, all you have to do is to type

      ./run_Name.sh $MCR input1 input2 ... 

    if you are in the same directory, or write the full path to the script

    Location/src/run_Name.sh $MCR input1 input2 ...

  • If you want to use the script on the Martinos center’s cluster, you need to login to launchpad using the regular

      ssh launchpad

    and then type as usual, with or without optional parameters to pbsubmit,

    pbsubmit -c "Location/src/run_Name.sh $MCR input1 input2 ..."

  • Note that you can move the files run_Name.sh and Name out of their original location as long as they stay in the same directory.

“That’s all folks!” Enjoy the use of your MATLAB script without any license restriction.