Home 9 Resources 9 Software 9 MATLAB

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

  1. Start an interactive session on Bridges-2 using the interact command. See the Bridges-2 User Guide for information on interact.
  2. Load the MATLAB module. Note that the module load command is case-sensitive.
    module load matlab
  3. Run MATLAB.  You can run your MATLAB job on as many cores as the node has on which you are running.

    Use a command like

     

     

     

    matlab -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:

image of the X2Go configuration screen

  1. Start the client X2Go program. From the Session menu select Session > New Session.
  2. Set Session Name to Bridges2-X2Go.
  3. Type bridges2.psc.edu in the Host field.
  4. Set Login to your Bridges-2 username.
  5. Under Session type at the bottom in the dropdown menu on the left select Single application.
  6. In the dropdown on the bottom right select Terminal. Click OK. Please note that Bridges-2 does not provide a desktop environment.
  7. 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.
  8. screen image of starting an interactive session and starting MATLAB Start an interactive session on Bridges-2 using the interact command. See the Bridges-2 User Guide for information on interact.
  9. Load the MATLAB module. Note that the module load command is case-sensitive.
    module load matlab
  10. 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.