MATLAB-Sapelo2

From Research Computing Center Wiki
Revision as of 12:57, 8 March 2021 by Shtsai (talk | contribs) (Created page with "Category:Sapelo2Category:SoftwareCategory:OtherCategory:ProgrammingCategory:Graphics === Category === Other, Programming, Graphics === Program On ===...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Category

Other, Programming, Graphics

Program On

Sapelo2

Version

R2019b (9.7.0.1216025), R2020a (9.8.0.1451342), R2020b (9.9.0.1524771)

Author / Distributor

The MathWorks (see http://www.mathworks.com)

Description

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

Running Program

Also refer to Running Jobs on Sapelo2

For more information on Environment Modules on Sapelo2 please see the Lmod page.

  • Version R2020b is installed in /apps/gb/MATLAB/R2020b. In order to use this version of Matlab, please first load the matlab/R2020b module with
ml matlab/R2020b
  • Version R2020a is installed in /apps/gb/MATLAB/R2020a. In order to use this version of Matlab, please first load the matlab/R2020a module with
ml matlab/R2020a
  • Version R2019b is installed in /apps/gb/MATLAB/R2019b. In order to use this version of Matlab, please first load the matlab/R2019b module with
ml matlab/R2019b


Running Matlab interactively

Please do not run MatLab interactively on the Sapelo2 login node, instead please run it using the interactive queue

To run MatLab interactively, start an interactive session with xqlogin (with GUI) or qlogin (without GUI) and at the interactive node shell prompt start the application.

For example:

1. To run with the graphical front-end on a regular node:

xqlogin

ml matlab/R2020b

matlab &

2. To run without the graphical front-end on a regular node:

qlogin

ml matlab/R2020b

matlab -nodisplay

3. To run without the graphical front-end on a node in a different partition, e.g. in abc_p, or to request more resources (cores or memory), use for example


srun --pty  -p abc_p  --mem=10G --ntasks=1 --cpus-per-task=2 --time=12:00:00 --job-name=qlogin /bin/bash -l

ml matlab/R2020b

matlab -nodisplay


Running Matlab as a batch job

Matlab can also be run as a batch job, for example in the batch partition. To do this, first create a MatLab M-file with the MatLab commands. Then use a job submission file to submit this job to the batch partition.

Sample MatLab M-file (matrixinv.m):

n = 500; 
Q = orth(randn(n,n));
d = logspace(0,-10,n);
A = Q*diag(d)*Q';
x = randn(n,1);
b = A*x;
tic, z = A\b, toc
err = norm(z-x)
res = norm(A*z-b)

import java.lang.System
java.lang.System.exit(0)

Sample job submission script file (sub.sh):

#!/bin/bash
#SBATCH --job-name=myjobname 
#SBATCH --partition=batch  
#SBATCH --ntasks=1    
#SBATCH --cpus-per-task=1              
#SBATCH --mem=5gb                  
#SBATCH --time=48:00:00               
#SBATCH --output=%x.%j.out    
#SBATCH --error=%x.%j.err    
#SBATCH --mail-type=END,FAIL       
#SBATCH --mail-user=username@uga.edu  
cd $SLURM_SUBMIT_DIR

ml matlab/R2020b

matlab -nodisplay < matrixinv.m 

The parameters of the job, such as the maximum wall clock time, maximum memory, email address, the number of cores per task, and the job name need to be modified appropriately.

If you are using functions, you might have to use a sample script like this:

#!/bin/bash
#SBATCH --job-name=myjobname 
#SBATCH --partition=batch  
#SBATCH --ntasks=1    
#SBATCH --cpus-per-task=1              
#SBATCH --mem=5gb                  
#SBATCH --time=48:00:00               
#SBATCH --output=%x.%j.out    
#SBATCH --error=%x.%j.err    
#SBATCH --mail-type=END,FAIL       
#SBATCH --mail-user=username@uga.edu  
cd $SLURM_SUBMIT_DIR

ml matlab/R2020b

echo functionname | matlab -nodisplay -nosplash 

To submit either of the two sample files sub.sh to the queue:

sbatch sub.sh


Parallel Computing Toolbox

1. Using many CPU cores on a node

The Parallel Computing toolbox allows a user to use many CPU cores on the same node for the job. Here is a simple example using the parfor loop with 10 Matlab workers.

Sample code psine.m

parpool(10)
parfor i=1:1024
  A(i) = sin(i*2*pi/1024);
end
p = gcp;
delete(p)

Sample job submission script sub.sh

#PBS -S /bin/bash
#PBS -q batch
#PBS -N matlabjob
#PBS -l nodes=1:ppn=10
#PBS -l walltime=48:00:00
#PBS -l mem=20gb
#PBS -M username@uga.edu 
#PBS -m ae

cd $PBS_O_WORKDIR

module load matlab/R2017b

matlab -nodisplay < psine.m > matlab_${PBS_JOBID}.out

Sample job submission command

qsub sub.sh

Note that the number that follows ppn= needs to match the number of matlab workers defined in the matlab code.


NOTE

At job exit time, you might get a Java error of the form

com.mathworks.util.ShutdownRuntimeException: Java is shutting down
  ...

Although this error is harmless (it occurs after the MatLab program finishes), you can avoid it by adding the following two lines of code to your MatLab program (M-file):

import java.lang.System
java.lang.System.exit(0)


Documentation

Some documentation and sample files are available in /usr/local/apps/MATLAB/R2017b/help

Installation

Version 2017b

Installed in /usr/local/apps/MATLAB/R2017b.

Available toolboxes: Almost all toolboxes for which UGA has a license. For details, see the directories in /usr/local/apps/MATLAB/R2017b/toolbox


Version 2018b

Installed in /usr/local/apps/MATLAB/R2018b.

Available toolboxes: Almost all toolboxes for which UGA has a license. For details, see the directories in /usr/local/apps/MATLAB/R2018b/toolbox


Version 2019b

Installed in /usr/local/apps/MATLAB/R2019b.

Available toolboxes: Almost all toolboxes for which UGA has a license. For details, see the directories in /usr/local/apps/MATLAB/R2019b/toolbox

System

64-bit Linux