MATLAB-Sapelo2: Difference between revisions

From Research Computing Center Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 374: Line 374:
   
   
Some documentation and sample files are available in /apps/gb/MATLAB/R2021a/help
Some documentation and sample files are available in /apps/gb/MATLAB/R2021a/help
To learn more about the MATLAB Parallel Computing Toolbox, check out these resources:
• [http://www.mathworks.com/products/parallel-computing/code-examples.html | Parallel Computing Coding Examples]
• Parallel Computing Documentation
• Parallel Computing Overview
• Parallel Computing Tutorials
• Parallel Computing Videos
• Parallel Computing Webinars


=== Installation ===
=== Installation ===

Revision as of 22:58, 15 May 2021

Category

Other, Programming, Graphics

Program On

Sapelo2

Version

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

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 R2021a is installed in /apps/gb/MATLAB/R2021a. In order to use this version of Matlab, please first load the matlab/R2021a module with
ml matlab/R2021a
  • 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 partition.

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/R2021a

matlab &

Note that in order to have the Matlab GUI display on your local machine, you will need to have an X client running on your local machine and configure your ssh session to tunnel X11. See below for an option on run Matlab directly on your local machine and have it submit jobs to the cluster.

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

qlogin

ml matlab/R2021a

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/R2021a

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)

Sample job submission script file (sub.sh) to run a serial (single-core) matlab program:

#!/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/R2021a

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/R2021a

echo functionname | matlab -nodisplay -nosplash 

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

sbatch sub.sh


Parallel Computing - Using multiple CPU cores on a single compute node

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

Sample code psine.m

defaultProfile=parallel.defaultClusterProfile;
p=parcluster(defaultProfile);
p.NumWorkers=25;
ppool=parpool(p,24);

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

Sample job submission script sub.sh

#!/bin/bash
#SBATCH --job-name=myjobname 
#SBATCH --partition=batch  
#SBATCH --nodes=1
#SBATCH --ntasks=1    
#SBATCH --cpus-per-task=25            
#SBATCH --mem=50gb                  
#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/R2021a

matlab -nodisplay < psine.m 

Note that the number that follows --cpus-per-tasks needs to match the number of matlab workers defined with NumWorkers in the matlab code .

Sample job submission command

sbatch sub.sh


Parallel Computing - Using cores from one or more compute nodes

In order to use the Parallel Computing toolbox to run Matlab using either cores on a single node, or to use multiple nodes, you need to configure Matlab and create a new cluster profile. To do this, please login to Sapelo2, start an interactive session with qlogin, load the matlab module you want to use and start matlab. For example, to configure this for matlab/R2021a:

qlogin

ml matlab/R2021a

matlab -nodisplay

In Matlab, call the configCluster function:

>> configCluster

This function only needs to be called once per version of Matlab. Please be aware that running configCluster more than once per version will reset your cluster profile back to default settings and erase any saved modifications to the profile. If calling the configCluster function returns the error Unrecognized function or variable 'configCluster'., then run the following commands in an interactive Matlab session: >>rehash toolboxcache

Sample Matlab code that can be run in a Slurm batch partition and use more than one node (psine.m)

c = parcluster;
c.AdditionalProperties.QueueName = 'batch';
c.AdditionalProperties.WallTime = '24:00:00';
c.AdditionalProperties.MemUsage = '5G';
c.saveProfile

p = c.parpool(5);

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

Note that the resources you want this parallel job to use (e.g. partition name, the walltime limit and the memory per CPU needs to be specified in this Matlab code. For more details on how to request resources in the Matlab code, please see the Configuring Jobs from inside Matlab session below.

Sample job submission script sub.sh:

#!/bin/bash
#SBATCH --job-name=myjobname 
#SBATCH --partition=batch  
#SBATCH --nodes=1
#SBATCH --ntasks=1    
#SBATCH --cpus-per-task=1           
#SBATCH --mem-per-cpu=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/R2021a

matlab -nodisplay < psine.m 

Note that this job only needs to request one core. When this job runs, Matlab will submit another parallel jobs using the resources specified in the psine.m code. It is important that this script (sub.sh) uses the --mem-per-cpu option to request memory per cpu and not the total memory with --mem.

Sample job submission command

sbatch sub.sh

Using a Matlab client installed on your local machine to run jobs on the cluster

The Sapelo2 MATLAB support package can be found on Sapelo2, at the following locationa:

Windows: TBD

Linux/macOS: TBD

Download the appropriate archive file to your local machine and start MATLAB on your local machine. The archive file should be untarred/unzipped in the location returned by calling

>> userpath

Configure MATLAB to run parallel jobs on your cluster by calling configCluster, which only needs to be called once per version of MATLAB.

>> configCluster

Submission to the remote cluster (Sapelo2) requires SSH credentials and you will need to configure key-based SSH. You will be prompted for your ssh username and your identity file (private key). The username and location of the private key will be stored in MATLAB for future sessions.

Jobs will now default to the cluster rather than submit to the local machine.

NOTE: If you would like to submit to the local machine then run the following command:

>> % Get a handle to the local resources

>> c = parcluster('local');


Configuring Jobs from within Matlab on the cluster or on your local machine

Prior to having Matlab submit a job to the cluster, we can specify various parameters to pass to our jobs, such as partition, e-mail, walltime, etc. The WallTime, MemUsage, and QueueName (partition name) fields are mandatory in order to submit a job. >> % Get a handle to the cluster >> c = parcluster;

[REQUIRED]

>> % Specify memory to use for MATLAB jobs, per core >> c.AdditionalProperties.MemUsage = '5G';

>> % Specify a queue to use for MATLAB jobs >> c.AdditionalProperties.QueueName = 'partition-name';

>> % Specify the walltime (e.g. 5 hours) >> c.AdditionalProperties.WallTime = '05:00:00';


[OPTIONAL]

>> % Specify an account to use for MATLAB jobs >> c.AdditionalProperties.AccountName = 'account-name';

>> % Specify e-mail address to receive notifications about your job >> c.AdditionalProperties.EmailAddress = 'user-id@uga.edu';

>> % Specify constraint for you job >> c.AdditionalProperties.Constraint = 'Intel';

>> % Specify number of GPUs >> c.AdditionalProperties.GpusPerNode = 1;

>> % Specify GPU type >> c.AdditionalProperties.GpuType = 'K40';

Save changes after modifying AdditionalProperties for the above changes to persist between Matlab sessions.

>> c.saveProfile

To see the values of the current configuration options, display AdditionalProperties.

>> % To view current properties >> c.AdditionalProperties

Unset a value when no longer needed.

>> % Turn off email notifications >> c.AdditionalProperties.EmailAddress = ; >> c.saveProfile

Documentation

Some documentation and sample files are available in /apps/gb/MATLAB/R2021a/help

To learn more about the MATLAB Parallel Computing Toolbox, check out these resources: • | Parallel Computing Coding Examples • Parallel Computing Documentation • Parallel Computing Overview • Parallel Computing Tutorials • Parallel Computing Videos • Parallel Computing Webinars


Installation

Version 2021a

Installed in /apps/gb/MATLAB/R2021a.

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


Version 2020b

Installed in /apps/gb/MATLAB/R2020b.

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


Version 2020a

Installed in /apps/gb/MATLAB/R2020a.

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


Version 2019b

Installed in /apps/gb/MATLAB/R2019b.

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

System

64-bit Linux