Version 3 (modified by fuji, 9 years ago) ( diff )


MATLAB (matrix laboratory) is a proprietary programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, and creation of user interfaces.

You can run your Matlab codes on Cypress clusters but you can't use GUI(Graphical User Interface) on computing nodes.

Running MATLAB interactively

Start an interactive session,

[fuji@cypress2 ~]$ idev
Requesting 1 node(s)  task(s) to normal queue of defq partition
1 task(s)/node, 20 cpu(s)/task, 2 MIC device(s)/node
Time: 0 (hr) 60 (min).
Submitted batch job 47343
JOBID=47343 begin on cypress01-063
--> Creating interactive terminal session (login) on node cypress01-063.
--> You have 0 (hr) 60 (min).
Last login: Mon Jun  8 20:18:50 2015 from

Load the module

[fuji@cypress01-063 ~]$ module load matlab

Run MATLAB on the command-line window,

[fuji@cypress01-063 ~]$ matlab
MATLAB is selecting SOFTWARE OPENGL rendering.

                                                                                         < M A T L A B (R) >
                                                                               Copyright 1984-2015 The MathWorks, Inc.
                                                                               R2015a ( 64-bit (glnxa64)
                                                                                          February 12, 2015

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit

        Academic License


You will get to the MATLAB command-line and can run MATLAB code here but no graphics.

Running MATLAB in a batch mode

You can also submit your MATLAB job to the batch nodes (compute nodes) on Cypress. To do so, please first make sure that the MATLAB module has been loaded, and then launch "matlab" with the "-nodesktop -nodisplay -nosplash" option as shown in the sample SLURM job script below.

#SBATCH --qos=normal            # Quality of Service
#SBATCH --job-name=matlab     # Job Name
#SBATCH --time=24:00:00         # WallTime
#SBATCH --nodes=1               # Number of Nodes
#SBATCH --ntasks-per-node=1     # Number of tasks (MPI processes)
#SBATCH --cpus-per-task=1       # Number of threads per task (OMP threads)

module load matlab
matlab -nodesktop -nodisplay -nosplash < mymatlabprog.m

Running MATLAB in Parallel with Multithreads

MATLAB supports multithreaded computation for a number of functions and expressions that are combinations of element-wise functions. These functions automatically execute on multiple threads if data size is large enough. Note that on Cypress, in default, MATLAB runs with a single threads, and you have to explicitly specify the number of threads in your code. For example,

% Matlab Test Code "FuncTest.m"
LASTN = maxNumCompThreads(str2num(getenv('SLURM_JOB_CPUS_PER_NODE')));
nth = maxNumCompThreads;
fprintf('Number of Threads = %d.\n',nth);

A = randn(N);
st = cputime;
B = sin(A);
realT = toc;
cpuT = cputime -st;
fprintf('Real Time = %f(sec)\n',realT);
fprintf('CPU Time = %f(sec)\n',cpuT);
fprintf('Speedup Factor = %f\n',cpuT / realT);

In above code, the line,

LASTN = maxNumCompThreads(str2num(getenv('SLURM_JOB_CPUS_PER_NODE')));

defines the number of threads. The environmental variable, SLURM_JOB_CPUS_PER_NODE has the value set in SLURM script, for example,

#SBATCH --qos=normal            # Quality of Service
#SBATCH --job-name=matlabMT     # Job Name
#SBATCH --time=1:00:00          # WallTime
#SBATCH --nodes=1               # Number of Nodes
#SBATCH --ntasks-per-node=1     # Number of tasks (MPI processes)
#SBATCH --cpus-per-task=10      # Number of threads per task (OMP threads)

module load matlab
matlab -nodesktop -nodisplay -nosplash -r "FuncTest; exit;"

The number of cores per process (task) is set by —cpus-per-task=10. This value goes to SLURM_JOB_CPUS_PER_NODE and you can use it to determine the number of threads used in the code.

Explicit parallelism

The parallel computing toolbox is available on Cypress. You can use up to 12 workers for shared parallel operations on a single node in the current MATLAB version. Our license does not include MATLAB Distributed Computing Server. Therefore, multi-node parallel operations are not supported.

Running MATLAB with Automatic Offloading

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.