matlab

Summary

Software Description

Matlab is a high level technical computing language and interactive environment for data visualization, data analysis, numerical computation, and algorithm development.

General Linux

To load this module for use in a Linux environment, you can run the command:

module load matlab

Depending on where you are working, there may be more than one version of matlab available. To see which modules are available for loading you can run:

module avail matlab

Parallel Test Script

The following test script demonstrates how easily Matlab loops can be parallelized with “parfor”. Basic benchmarking information is included and will vary with your choice of “–ntasks-per-node” in your Slurm script. Note that “cl.parpool()” will use the number of workers specified by the SLURM_NTASKS environment variable. You can override this value by passing it directly (e.g., “cl.parpool(4)”).

% Get number of workers from Slurm
nWorkers = str2num(getenv('SLURM_NTASKS'));

% Create parallel pool
cl = parcluster('local');
pool = cl.parpool(nWorkers);

N=50000000

tic
for i = 1:N
 A(i) = rand(1,1);
end
serial_time=toc

tic
parfor i = 1:N
 A(i) = rand(1,1);
end
parallel_time=toc

speedup = serial_time / parallel_time
efficiency = speedup / pool.NumWorkers

exit

To run this script on Agate, save it as ‘parallel_test.m’ and submit using a Slurm script like this (save as ‘run_matlab.slurm’):

#!/bin/bash
#SBATCH --nodes=1 --ntasks-per-node=8
#SBATCH --mem=16gb
#SBATCH --time=1:00:00
#SBATCH --output=%j.out

cd $SLURM_SUBMIT_DIR
module load matlab
matlab -nodisplay -nodesktop -r "parallel_test"

Submit the job with:

sbatch run_matlab.slurm

Slurm Example

#!/bin/bash
#SBATCH --job-name="rfm_RunMATLABTest_job"
#SBATCH --ntasks=1
#SBATCH --ntasks-per-node=1
#SBATCH --output=rfm_RunMATLABTest_job.out
#SBATCH --error=rfm_RunMATLABTest_job.err
#SBATCH --time=0:10:0
#SBATCH -p msismall

module load matlab/R2019a
wget https://public.s3.msi.umn.edu/reframe/sw/matlab/script.m
matlab -nodisplay -nodesktop -nosplash -r "run('script.m'); exit;"