Note: MATLAB will sometimes attemps to use all available
CPU cores on the node it is running on.
If you haven’t reserved all cores on the node,
your job may be killed if this happens.
To avoid this, you can use the taskset utility to
set the “core affinity” (as shown above).
As an example:

$ taskset 0-2 <application>

will limit application to using 3 CPU cores.
On Palmetto,
the variable OMP_NUM_THREADS is automatically set to be the
number of cores requested for a job.
Thus, you can use 0-$((OMP_NUM_THREADS-1)) as shown
in the above batch script to use all the cores you requested.

Compiling MATLAB code to create an executable

Often, you need to run a large number of MATLAB jobs
concurrently (e.g,m each job operating on different data).
In such cases, you can avoid over-utilizing MATLAB licenses
by compiling your MATLAB code into an executable.
This can be done from within the MATLAB command-line as follows:

Note: MATLAB will try to use all the available CPU cores
on the system where it is running, and this presents a problem
when your compiled executable on the cluster where available
cores on a single node might be shared amongst mulitple users.
You can disable this “feature” when you compile your code by
adding the -R -singleCompThread option, as shown above.

The above command will produce the executable mycode, corresponding
to the M-file mycode.m. If you have multiple M-files in your project
and want to create a single excutable, you can use
a command like the following:

Once the executable is produced,
you can run it like any other executable in your batch jobs.
Of course, you’ll also need the same matlab and
(optional) GCC module loaded for your job’s runtime environment.