MATLAB
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 the GUI(Graphical User Interface) on computing nodes.
See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab
MATLAB Modules
[fuji@cypress1 ~]$ module av matlab ----------------------------------------------- /share/apps/modulefiles ------------------------------------------------ matlab/r2013b matlab/r2015a matlab/r2015b matlab/r2016a matlab/r2017b matlab/r2020a ------------------------------------------- /share/apps/centos7/modulefiles -------------------------------------------- matlab/r2022b matlab/r2023a
Running MATLAB interactively
Download example:
git clone https://hidekiCCS:@bitbucket.org/hidekiCCS/hpc-workshop.git
Start an interactive session,
Load the module
Run MATLAB on the command-line window,
You will get to the MATLAB command-line and can run MATLAB code here, but no graphics.
Running MATLAB interactively with GUI
If you have an X-Windows environment on the local machine, you can forward the MATLAB GUI window from Cypress to your local screen. See X-window forwarding.
- Log in to Cypress with X-window forwarding.
ssh -Y userID@cypress.tulane.edu
- Start an interactive session.
idev
- Load module
module load matlab
- Run MATLAB
matlab &
Note that your MATLAB session will be killed when the session time exceeds the walltime limit.
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.
or
matlab -nodesktop -nodisplay -nosplash -r "mymatlabprog; exit;"
See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab
Compiled Matlab
Compiling Matlab Scripts using mcc
Start an interactive session with idev, load the intel-psxe module (if you want to use mkl and multithreading), load the matlab module
[tulaneID@cypress1 ~]$ 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 80102 JOBID=80102 begin on cypress01-036 --> Creating interactive terminal session (login) on node cypress01-036. --> You have 0 (hr) 60 (min). --> Assigned Host List : /tmp/idev_nodes_file_tulaneID Last login: Tue Sep 22 16:27:39 2015 from cypress1.cm.cluster [tulaneID@cypress01-036 ~]$ module load intel-psxe [tulaneID@cypress01-036 ~]$ module load matlab [tulaneID@cypress01-036 ~]$
cd to the directory containing your MATLAB file and compile using MATLAB's C compiler mcc -m <your matlab .m file>. If your script is spread over many files you need to specify the directories containing those files mcc -m -I <source directory> <your matlab .m file>. For example, to compile my_script.m which depends on other .m files located in /home/tulaneID/myMatlab I would run
mcc -m -I /home/tulaneID/myMatlab my_script.m
This will compile files that my_script.m depends upon provided they are in /home/tulaneID/myMatlab
To see help,
mcc -?
Executing Compiled scripts
The above will create a binary executable named my_script. To run the executable as a SLRUM Job, just include the matlab module in your SLURM script. This will provide all the necessary libraries. For example,
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 the data size is large enough.
Note that on Cypress, by default, MATLAB runs with a single threads, MATLAB utilizes the maximum number of cores, regardless of the number requested, and therefore, you have to explicitly specify the number of threads in your code.
For example,
In the above code, the line,
defines the number of threads. The environmental variable, SLURM_JOB_CPUS_PER_NODE has the value set in SLURM script, for example,
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.
See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab
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 now includes MATLAB Distributed Computing Server, which means multi-node parallel operations are supported.
Workers are like independent processes. If you want to use 4 workers, you have to request at least 4 tasks within a node.
CreateWorker.m is a MATLAB code to create workers.
Parfor.m is a sample 'parfor' test code,
See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab
Running MATLAB with Automatic Offload
Internally, MATLAB uses Intel MKL Basic Linear Algebra Subroutines (BLAS) and Linear Algebra package (LAPACK) routines to perform the underlying computations when running on Intel processors.
Intel MKL includes Automatic Offload (AO) feature that enables computationally intensive Intel MKL functions to offload partial workload to attached Intel Xeon Phi coprocessors automatically and transparently.
As a result, MATLAB performance can benefit from Intel Xeon Phi coprocessors via the Intel MKL AO feature when problem sizes are large enough to amortize the cost of transferring data to the coprocessors.
In SLURM script, make sure that option --gres=mic:1 is set and intel-psxe module as well as the MATLAB module has been loaded.
Note that
enables Intel MKL Automatic Offload (AO).
The sample code is below:
See https://wiki.hpc.tulane.edu/trac/wiki/cypress/Matlab#CompiledMatlab
To generate the offload report at run time,
export OFFLOAD_REPORT=2
- Setting OFFLOAD_REPORT to 0 (or not setting it) results in no offload report.
- Setting OFFLOAD_REPORT to 1 results in a report including:
- Name of function called
- Effective Work Division
- Time spent on Host during call
- Time spent on each available Phi coprocessor during the call
- Setting OFFLOAD_REPORT to 2 results in a report including everything from 1, and in addition:
- Amount of data transferred to and from each Phi during call
Attachments (1)
- MatlabWorkers.jpeg (18.6 KB ) - added by 11 years ago.
Download all attachments as: .zip

