Translations of this page:

MATLAB

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
nano example.sh

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

sbatch example.sh

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

Example job script to run MATLAB:

MATLAB_example.sh
#!/bin/bash
#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=<youremail@lut.fi>
 
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
example.sh
% 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);
 
  tic
 
  parfor i = 1:n
    x = R*rand(1); y = R*rand(1);
    if x^2 + y^2 <= R^2
      count = count + 1;
    end
  end
 
  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);
 
end
 
fclose(fileID);
 
delete(gcp);
 
exit;
 
/opt/webdata/webroot/wiki/data/pages/en/hpc/software/matlab.txt · Last modified: 2018/09/13 15: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