MATLAB
MATLAB is a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages.
MATLAB is available on PSC systems for academic users. Academic users must complete the MATLAB Request form to request access to MATLAB. Once access has been granted, follow the steps below.
Non-academic users should contact help@psc.edu to discuss how they can get access to MATLAB at PSC.
Sample scripts for MATLAB use are available in directory /opt/packages/examples/matlab on Bridges and Bridges-2.
Documentation
Usage on Bridges-2
To see what versions of MATLAB are available and if there is more than one, which is the default, along with some help, type
module spider matlab
You can run MATLAB from the Bridges-2 command line or in a graphical interface.
Run MATLAB from the command line
- Start an interactive session on Bridges-2 using the
interact
command. See the Bridges-2 User Guide for information oninteract
. - Load the MATLAB module. Note that the
module load
command is case-sensitive.module load matlab
- Run MATLAB. You can run your MATLAB job on as many cores as the node has on which you are running.
Use a command likematlab -options < input-file > output-file
.
Example script
Here is an example script to run MATLAB on the command line. You can also find this script and the input file in the directory /opt/packages/examples/matlab on Bridges-2.
#!/bin/bash #SBATCH --partition=RM #SBATCH --nodes=1 #SBATCH --ntasks-per-node=128 #SBATCH --time=00:10:00 #SBATCH --job-name=matlab-parfor module load matlab # echo commands to stdout set -x cd $SLURM_SUBMIT_DIR date matlab -nodisplay -nosplash -nodesktop -logfile pp.log < pp.m > pp.out date
Here is the input file, pp.m in the example script above.
% N = str2num(getenv('SLURM_TASKS_PER_NODE')) N = str2num(getenv('SLURM_CPUS_ON_NODE')) parpool('local',N) a = zeros(N,1); parfor(i=1:N) feature getpid a(i) = ans end
Run MATLAB in a graphical interface
You can run MATLAB in a graphical interface using the X2Go program. X2Go is client-server software; you must have the client installed on your local machine to speak to the server on Bridges-2.
You must download and install an X2Go client for your operating system from https://wiki.x2go.org/doku.php/doc:installation:x2goclient. When that is done, you can run MATLAB in the X2Go interface using these steps:
- Start the client X2Go program. From the Session menu select Session > New Session.
- Set Session Name to Bridges2-X2Go.
- Type bridges2.psc.edu in the Host field.
- Set Login to your Bridges-2 username.
- Under Session type at the bottom in the dropdown menu on the left select Single application.
- In the dropdown on the bottom right select Terminal. Click OK. Please note that Bridges-2 does not provide a desktop environment.
- Click the Bridges2-X2Go session on the right and enter your login credentials. Click Ok. This will open an xterm window with a Bridges-2 shell.
- Start an interactive session on Bridges-2 using the
interact
command. See the Bridges-2 User Guide for information oninteract
. - Load the MATLAB module. Note that the
module load
command is case-sensitive.module load matlab
- Run MATLAB. You can run your MATLAB job on as many cores as the node has on which you are running. The program will open as a window on your desktop. When you are finished close the program, and type “exit” once to exit your interact shell and again to exit the x2go shell.
See what toolkits are available
Once you have started MATLAB, typing
ver
lists all the installed toolkits. PSC has the PCT toolkit, which is how you can run parallel MATLAB jobs. This command also gives information on your license number, operating system, Java version, etc., which may be useful in diagnosing problems.