MATLAB is available on Wynton HPC via a built-in environment module and is supported by a UCSF-wide MATLAB license.
To load the MATLAB module, do:
[alice@dev2 ~]$ module load matlab [alice@dev2 ~]$ matlab -nosplash -nodesktop MATLAB is selecting SOFTWARE OPENGL rendering. < M A T L A B (R) > Copyright 1984-2021 The MathWorks, Inc. R2021a (220.127.116.112886) 64-bit (glnxa64) February 17, 2021 To get started, type doc. For product information, visit www.mathworks.com. >> 1+2 ans = 3 >> quit [alice@dev2 ~]$
If you forget to load the MATLAB module, then you will get an error when attempting to start MATLAB:
[alice@dev2 ~]$ matlab -bash: matlab: command not found
In order to run MATLAB in jobs, the MATLAB environment module needs to be loaded just as when you run it interactive on a development node. For example, to run the
my_script.m script, the job script should at a minimum contain:
#! /usr/bin/env bash #$ -cwd ## SGE directive to run in the current working directory module load matlab matlab -singleCompThread -batch my_script.m
-batch option tells MATLAB to run the
my_script.m script in batch mode, in contrast to interactive mode. The
-singleCompThread option tells MATLAB to run in sequential mode; this prevents your job for overusing the compute nodes by mistake.
If your MATLAB code supports parallel processing, make sure to specify the number of CPU cores when submitting your job submit, e.g.
-pe smp 4 will request four cores on one machine, which in turn will set environment variable
4. To make your MATLAB script respect this, add the following at the top of your script:
%% Make MATLAB respect the number of cores that the SGE scheduler %% has alloted the job. If not specified, run with a single core, %% e.g. when running on a development node nslots = getenv('NSLOTS'); % env var is always a 'char' if (isempty(nslots)) nslots = '1'; end % default value nslots = str2num(nslots); % coerce to 'double' maxNumCompThreads(nslots); % number of cores MATLAB may use
and then launch your MATLAB script without option
matlab -batch my_script.m.