Matlab
title: SLURM Job Example: MATLAB GPU permalink: /Slurm_-_Job_Script_Example_06_Matlab/
This example submits MATLAB GPU work to a Picotte compute node using SLURM. For the browser-based MATLAB desktop, CPU jobs, and parallel computing details, see the MATLAB guide.
Save this MATLAB code as gpu_example.m:
device = gpuDevice;
disp(device.Name)
A = gpuArray(rand(4000));
B = A * A;
wait(device)
Save the following as matlab-gpu.sh, replacing the example account
with one you can use:
#!/bin/bash
#SBATCH --account=mygroupfreeprj
#SBATCH --partition=gpu-sm
#SBATCH --gres=gpu:1
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem=32G
#SBATCH --time=01:00:00
#SBATCH --output=matlab-gpu-%j.out
module load matlab/R2022b
matlab -batch "gpu_example"
Submit the job with:
sbatch matlab-gpu.sh
The output file records MATLAB's console output. See the SLURM job script guide for account, partition, and resource-request details.