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:
Load the modules:
% module load matlab
% module load gcc/9.3 # or later
If this is the first time you are using MATLAB to create an executable, run:
% matlab -nodisplay
>>mbuild -setup
>>exit
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
To run the executable, add the following lines to your PBS script or run them at the Linux prompt:
% ./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: