Translations of this page:


Create directory and copy tutorial case to your home directory:

mkdir -p ~/matlabpartest
cp -R /shared/tutorials/matlab ~/matlabpartest

Enter to directory and modify your job script with nano editor (for example):

cd ~/matlabpartest

After making changes hit Ctrl+X and save your changes. Put job to queue with command:


Check output. Check more instructions about general usage from SLURM page.

Example job script to run MATLAB:
#SBATCH --nodes 1
#SBATCH --ntasks 1
#SBATCH --cpus-per-task 12
#SBATCH --mem-per-cpu=2000
#SBATCH --time 14-0:00:00
#SBATCH --job-name example
#SBATCH --error example.stderr.%j
#SBATCH --output example.stdout.%j
#SBATCH --partition phase1
#SBATCH --mail-type=end
#SBATCH --mail-user=<>
module load matlab/R2018a
cd /home/<yourusername>/matlabpartest/
# Create a temporary directory on scratch
mkdir -p /tmp/$SLURM_JOB_ID
srun --mpi=pmi2 matlab -nodisplay -nosplash -r example
# Cleanup local work directory
rm -rf /tmp/$SLURM_JOB_ID
% Create a local cluster object
pc = parcluster('local')
% Set JobStorageLocation to the tmp directory
pc.JobStorageLocation = strcat('/tmp/', getenv('SLURM_JOB_ID'))
% Start matlabpool with maximum available workers
% This should match cpus_per_task setting in your job script
parpool(pc, str2num(getenv('SLURM_CPUS_ON_NODE')))
% Example parallel task
fileID = fopen(strcat('example.output.txt.',getenv('SLURM_JOB_ID')),'w');
fprintf(fileID, 'Random samples Time Approximate pi value\n\n');
for k = [1 2 10]
  R = 1;
  n = k*1e7;
  count = 0;
  fprintf('Approximate value of pi with %10d random samples\n',n);
  parfor i = 1:n
    x = R*rand(1); y = R*rand(1);
    if x^2 + y^2 <= R^2
      count = count + 1;
  apprxpi = 4*count/n;
  t = toc;
  fprintf('Approximate value of pi is %8.7f\n',apprxpi);
  fprintf('Parallel MC method was executed in %6.2f seconds to calculate approximation of pi\n', t);
  fprintf(fileID,'%10d %8.7f %f\n',n,t,apprxpi);
/opt/webdata/webroot/wiki/data/pages/en/hpc/software/matlab.txt · Last modified: 2018/09/13 12:04 by vrintala
[unknown button type]
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki