Skip to content

MATLAB

MATLAB is available on Picotte through Open OnDemand and from the command line. For an introduction to Open OnDemand, see the Picotte Open OnDemand guide.

Open the MATLAB launch form in Open OnDemand.

MATLAB through Open OnDemand♯

Open OnDemand runs the MATLAB desktop in a browser while MATLAB computes on a Picotte compute node. Follow the Open OnDemand getting-started steps, then open the MATLAB launch form. You can also find it under Interactive Apps in OOD. OOD displays the desktop in your browser, so you do not need to set up X11.

Choose the MATLAB version, Project, Partition, Hours, CPU cores, and Display resolution. The Project is the SLURM account used for this session; see Picotte partitions and usage tiers. For GPU work, select a GPU partition and request at least one GPU. The app defaults to MATLAB R2022b. It also offers R2020b, R2021a, and R2024b. Your home and /ifs directories are available in MATLAB.

Select Launch and wait for the session to start. When it is running, open it with the connection button in My Interactive Sessions. Save your work before the session's walltime ends. Closing the browser tab does not stop the job. Stop the session from Open OnDemand when you are finished.

MATLAB R2024b may ask you to sign in to your MathWorks account the first time you use it. Complete the sign-in window in the browser session.

MATLAB from the command line♯

Picotte provides MATLAB R2020b, R2021a, R2022b, and R2024b as environment modules. The command-line default is R2024b. Load a specific version with Environment Modules:

module load matlab/R2022b

Run MATLAB work on a compute node through SLURM. For a terminal session on a compute node, see interactive sessions. For a batch job, put your MATLAB program in myprog.m and submit a job script like this, replacing the account with one you can use:

#!/bin/bash
#SBATCH --account=mygroupfreeprj
#SBATCH --partition=def-sm
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem=32G
#SBATCH --time=01:00:00
#SBATCH --output=matlab-%j.out

module load matlab/R2022b
matlab -batch "myprog"

Submit it with sbatch matlab.sh. SLURM writes output to matlab-JOBID.out. For more about resource requests, partitions, and accounts, see Writing SLURM Job Scripts.

MathWorks account sign-in for R2024b♯

MATLAB R2024b requires a MathWorks account sign-in. Create an account using your Drexel email through MathWorks account registration. You can complete sign-in in the R2024b Open OnDemand desktop, or once from the command line:

module load matlab/R2024b
matlab

Sign in when prompted, then exit MATLAB. MATLAB caches the credentials in your home directory, so later batch jobs can use them. If a batch job still prompts, return to an interactive desktop session and complete sign-in there. Run analysis on a compute node through SLURM, not on the login node.

Parallel Computing Toolbox♯

Use ver in MATLAB to see installed products. Parallel computations with parfor or parpool require the Parallel Computing Toolbox and available license capacity. The example below is for a one-task SLURM batch allocation like the script above. It starts workers on that compute node and reads its requested CPU count from SLURM_CPUS_PER_TASK.

For each job, SLURM provides a temporary, job-specific local directory in TMPDIR. It is removed when the job ends. Set MATLAB's local parallel-job storage there so simultaneous jobs do not share that state. In myprog.m, before calling parfor:

cluster = parcluster("local");
scratch = getenv("TMPDIR");
cluster.JobStorageLocation = fullfile(scratch, "matlab-job-storage");
if ~isfolder(cluster.JobStorageLocation)
    mkdir(cluster.JobStorageLocation);
end
workers = str2double(getenv("SLURM_CPUS_PER_TASK"));
pool = parpool(cluster, workers);

parfor i = 1:100
    result(i) = sum(rand(1, 100));
end

delete(pool)

This example assumes SLURM has set TMPDIR for the job. For details about local scratch, see Writing SLURM Job Scripts: local scratch. See MathWorks documentation for parpool and parallel computing.

Checkpointing long jobs♯

Set the job time to a value permitted by the selected partition and account; there is no single walltime limit for every Picotte job. For a long computation, periodically save enough state to resume it, such as the current input or iteration and any required random-number state. Write checkpoints to home or group storage so they remain available when the job ends. See Picotte usage limits and Writing SLURM Job Scripts.

MATLAB startup in directories with many files♯

MATLAB can start slowly when its current directory contains a very large number of files. Keep the job's working directory small, with scripts and job files, and open data by its full path—for example, /ifs/groups/mygroup/data/input.dat.

Compiling MEX files♯

MEX compiler compatibility depends on the MATLAB release and compiler. Check MathWorks' supported Linux compilers for the release you use. In MATLAB, select an installed compiler and compile the source from a compute-node session:

mex -setup C
mex mymex.c

See MathWorks' mex documentation.

GPU computing♯

The MATLAB app and command-line jobs can request GPUs on a GPU partition. For a batch job, follow the MATLAB GPU job example, adjusting the account, GPU count, and partition for your work.

In MATLAB, use gpuDevice to select and inspect the allocated device, and gpuArray to move supported data and computations to it. GPU availability alone does not make CPU-only MATLAB code run on the GPU. See MathWorks' GPU computing documentation and GPU Mandelbrot example.

MATLAB path and startup file♯

MATLAB includes ~/Documents/MATLAB in its search path by default. Put startup commands in ~/Documents/MATLAB/startup.m.

Other resources♯