Compiling MATLAB Scripts into Executables to Reduce the Use of Licenses

Article ID: 527
Last updated: 16 Dec, 2025

NAS currently has 16 MATLAB licenses available. To avoid overwhelming the license server, and to reduce contention for the limited number of licenses, PBS batch jobs running on most NAS compute nodes are not allowed to query the MATLAB license server. Therefore, in order to run a MATLAB script in a batch job on most NAS compute nodes, you must first compile the script. Compiled executables do not access the license server.

Note: It is not necessary to compile your MATLAB scripts for batch jobs running on the LDANs or Endeavour—on these systems, there is less risk of overwhelming the MATLAB license server because fewer hosts query the server. Also, you can still run interactive MATLAB jobs on NAS compute nodes without compiling the scripts (it is easier to debug the scripts if they are not compiled into executables).

Steps for Compiling a MATLAB Script

This method is the simplest way to compile a MATLAB script into a standalone executable. The steps are described using the following sample script, findR.m:

function R = findR
% findR - given data T, calculate R
%
T = 10;
R = .5*(-9.8)*T
% end of MATLAB code

Complete these steps to compile the sample script:

  1. Load the modules:
    % module load matlab
    % module load gcc/9.3 # or later
    
  2. If this is the first time you are using MATLAB to create an executable, run:
    % matlab -nodisplay
    >>mbuild -setup
    >>exit
  3. Compile the script into an executable. At the Linux or MATLAB prompt, run:
    % mcc -m findR.m -o findR 
    Two files are created:
    • An executable: findR
    • A shell script: run_findR.sh
  4. To run the executable, add the following lines to your PBS script or run them at the Linux prompt:
    % module load matlab/
    % module load gcc/9.3
    ./run_findR.sh $MATLAB
    
    The output will be:
    % ./run_findR.sh $MATLAB
    ------------------------------------------
    Setting up environment variables
    ---
    LD_LIBRARY_PATH is
    .:/nasa/matlab/2024a/runtime/glnxa64:/nasa/matlab/2024a/bin/glnxa64
    :/nasa/matlab/2024a/sys/os/glnxa64:/nasa/matlab/2024a/sys/opengl/lib/glnxa64
    R =
       -49

Note: If you have several MATLAB scripts, where master.m calls y.m, and y.m calls z.m, make sure that master.m is the first file listed in the command line when you compile the script:

% mcc -m master.m y.m z.m 

In this case, the resulting files are:

  • Executable: master
  • Shell script: run_master.sh

Contact Us

General User Assistance

Security

  • Report security issues 24x7x365
  • Toll-free: 1-877-NASA-SEC (1-877-627-2732)
  • E-mail: soc@nasa.gov

User Documentation

High-End Computing Capability (HECC) Portfolio Office

NASA High-End Computing Program

Tell Us About It

Our goal is furnish all the information you need to efficiently and effectively use the HECC resources needed for your NASA computational projects.

We welcome your input on features and topics that you would like to see included on this website.

Please send us email with your wish list and other feedback.