Matlab use cases: Difference between revisions
(Strated Use case Mark Bolding.) |
|||
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Some use cases describing how to offload MATLAB computation | Some use cases describing how to offload MATLAB computation to the cluster. | ||
== Use Matlab on a compute node with a scheduled batch script == | |||
A shared cluster environment like Cheaha uses a job scheduler to run tasks on the cluster to provide optimal resource sharing among users. Cheaha uses a job scheduling system call Slurm to schedule and manage jobs. A user needs to tell Slurm about resource requirements (e.g. CPU, memory) so that it can schedule jobs effectively. These resource requirements along with actual application code can be specified in a single file commonly referred as 'Job Script/File'. Following is a simple job script that prints job number and hostname. | |||
Following is a sample script to generate Fibonacci series from 1-10 and save the output | |||
<pre> | |||
%% Job Test on Cheaha with SLURM - Test1Fib.m | |||
% Submit Job with matlabSubmit.sbatch | |||
% Output Files out.mat | |||
% Create Fibonacci Series upto 10 | |||
% clear all | |||
% close all | |||
# | |||
limit = 10 % Fibonacci series from 1 to limit | |||
c(1)=0; % first element | |||
c(2)=1; % second element | |||
for i=3:limit | |||
c(i)=c(i-1)+c(i-2); | |||
end | |||
c % Displays the output on screen | |||
save('out1.mat') % Saves the workspace to mat file | |||
exit | |||
</pre> | |||
Following is the matlabSubmit.sbatch | |||
Please edit the email address and the processor cores/memory requirement according to your jobs | |||
<pre> | |||
#!/bin/bash | |||
# | |||
#SBATCH --job-name=matTest | |||
#SBATCH --output=res.txt | |||
#SBATCH --ntasks=1 | |||
#SBATCH --partition=express | |||
#SBATCH --time=10:00 | |||
#SBATCH --mem-per-cpu=100 | |||
#SBATCH --mail-type=FAIL | |||
#SBATCH --mail-user=YOUR_EMAIL_ADDRESS | |||
module load rc/matlab/R2016b | |||
srun matlab -nodesktop -nodisplay -r Test1Fib | |||
srun sleep 60 | |||
</pre> | </pre> | ||
The above job can be submitted by | |||
<pre> | <pre> | ||
$ | $ sbatch matlabSubmit.sbatch | ||
Submitted batch job 359705 | |||
</pre> | </pre> | ||
You can check the job status using squeue command | |||
<pre> | <pre> | ||
$ | $ squeue -u $USER | ||
359705 express matTest tanthony R 0:03 1 c0005 | |||
</pre> | </pre> | ||
This shows that the job is running on compute node c0005 | |||
The working directory should have two new files res.txt and out1.mat | |||
== Use Matlab on a compute node via VNC == | |||
This use case creates an ordinary Matlab session, just like you would on your desktop, however, instead of running MATLAB you your desktop, you run MATLAB on a compute node of the [[Cheaha|cluster]] and access it's GUI via your cluster desktop. | |||
In | This is useful in situations where your personal desktop or laptop is not powerful enough to run your Matlab code or you simply want to offload a long-running computation so you can free your desktop or laptop for other activities. | ||
=== Connect to Your Cluster Desktop === | |||
The first step is to connect to an existing cluster desktop session via VNC. Please follow the steps for [[Setting_Up_VNC_ Session|setting up a VNC session]] to create your cluster desktop and connect to it. | |||
=== Open a Terminal === | |||
The second step is to open a terminal window on your cluster desktop. Once you are connected to your cluster desktop, start the Terminal application from the cluster desktop menu Applications->Accessories->Terminal. | |||
=== Reserve your Computer === | |||
The third step is to request a computer on which you can run Matlab. In your cluster desktop terminal window, submit a resource request to reserve a compute node for running Matlab | |||
<pre> | <pre> | ||
sinteractive --ntasks=1 --mem-per-cpu=1024 --time=4:00:00 --partition=medium | |||
</pre> | |||
The above resource request asks for a computer with 1 gigabyte of RAM for 4 hours. You can adjust these values to suit your needs but you should try to make reasonable estimates to ensure that resources are shared fairly. WARNING: the specified time limit is a hard boundary and can't be changed after you start Matlab. When this time limit is reached, your Matlab session will be automatically stopped, without warning, by the cluster resource manager. | |||
<pre> | <pre> | ||
sinteractive --ntasks=1 --cpus-per-task=4 --mem-per-cpu=1024 --time=8:00:00 --partition=medium | |||
</pre> | </pre> | ||
The above resource request asks for a computer with 4 cores and 1 gigabyte of RAM/core (total 4GB ram) for 8 hours. | |||
=== Start Matlab === | |||
The fourth and final step is to start Matlab on the compute resource you have reserved. In the same terminal window from which you made the resource request (ie. ran "qlogin"), run the following commands to start matlab. | |||
<pre> | |||
<pre> | module load rc/matlab/R2016b | ||
matlab | |||
</pre> | |||
Matlab will be running your reserved compute resource and can be controlled interactively via the VNC session. This Matlab session works just like the Matlab sessions on your personal desktop or laptop. When you are finished using Matlab, simply exit the application as you normally would. Your compute resource will automatically return to the resource pool at the end of the your requested reservation time or you can type "exit" to return it immediately. | |||
{{MATLAB Support}} | |||
[[Category:MATLAB]] | |||
MATLAB |
Latest revision as of 19:20, 9 March 2017
Some use cases describing how to offload MATLAB computation to the cluster.
Use Matlab on a compute node with a scheduled batch script
A shared cluster environment like Cheaha uses a job scheduler to run tasks on the cluster to provide optimal resource sharing among users. Cheaha uses a job scheduling system call Slurm to schedule and manage jobs. A user needs to tell Slurm about resource requirements (e.g. CPU, memory) so that it can schedule jobs effectively. These resource requirements along with actual application code can be specified in a single file commonly referred as 'Job Script/File'. Following is a simple job script that prints job number and hostname.
Following is a sample script to generate Fibonacci series from 1-10 and save the output
%% Job Test on Cheaha with SLURM - Test1Fib.m % Submit Job with matlabSubmit.sbatch % Output Files out.mat % Create Fibonacci Series upto 10 % clear all % close all limit = 10 % Fibonacci series from 1 to limit c(1)=0; % first element c(2)=1; % second element for i=3:limit c(i)=c(i-1)+c(i-2); end c % Displays the output on screen save('out1.mat') % Saves the workspace to mat file exit
Following is the matlabSubmit.sbatch Please edit the email address and the processor cores/memory requirement according to your jobs
#!/bin/bash # #SBATCH --job-name=matTest #SBATCH --output=res.txt #SBATCH --ntasks=1 #SBATCH --partition=express #SBATCH --time=10:00 #SBATCH --mem-per-cpu=100 #SBATCH --mail-type=FAIL #SBATCH --mail-user=YOUR_EMAIL_ADDRESS module load rc/matlab/R2016b srun matlab -nodesktop -nodisplay -r Test1Fib srun sleep 60
The above job can be submitted by
$ sbatch matlabSubmit.sbatch Submitted batch job 359705
You can check the job status using squeue command
$ squeue -u $USER 359705 express matTest tanthony R 0:03 1 c0005
This shows that the job is running on compute node c0005 The working directory should have two new files res.txt and out1.mat
Use Matlab on a compute node via VNC
This use case creates an ordinary Matlab session, just like you would on your desktop, however, instead of running MATLAB you your desktop, you run MATLAB on a compute node of the cluster and access it's GUI via your cluster desktop.
This is useful in situations where your personal desktop or laptop is not powerful enough to run your Matlab code or you simply want to offload a long-running computation so you can free your desktop or laptop for other activities.
Connect to Your Cluster Desktop
The first step is to connect to an existing cluster desktop session via VNC. Please follow the steps for setting up a VNC session to create your cluster desktop and connect to it.
Open a Terminal
The second step is to open a terminal window on your cluster desktop. Once you are connected to your cluster desktop, start the Terminal application from the cluster desktop menu Applications->Accessories->Terminal.
Reserve your Computer
The third step is to request a computer on which you can run Matlab. In your cluster desktop terminal window, submit a resource request to reserve a compute node for running Matlab
sinteractive --ntasks=1 --mem-per-cpu=1024 --time=4:00:00 --partition=medium
The above resource request asks for a computer with 1 gigabyte of RAM for 4 hours. You can adjust these values to suit your needs but you should try to make reasonable estimates to ensure that resources are shared fairly. WARNING: the specified time limit is a hard boundary and can't be changed after you start Matlab. When this time limit is reached, your Matlab session will be automatically stopped, without warning, by the cluster resource manager.
sinteractive --ntasks=1 --cpus-per-task=4 --mem-per-cpu=1024 --time=8:00:00 --partition=medium
The above resource request asks for a computer with 4 cores and 1 gigabyte of RAM/core (total 4GB ram) for 8 hours.
Start Matlab
The fourth and final step is to start Matlab on the compute resource you have reserved. In the same terminal window from which you made the resource request (ie. ran "qlogin"), run the following commands to start matlab.
module load rc/matlab/R2016b matlab
Matlab will be running your reserved compute resource and can be controlled interactively via the VNC session. This Matlab session works just like the Matlab sessions on your personal desktop or laptop. When you are finished using Matlab, simply exit the application as you normally would. Your compute resource will automatically return to the resource pool at the end of the your requested reservation time or you can type "exit" to return it immediately.
MATLAB Support / Mailing List
As with any application or computer language, learning to use MATLAB to analyze data or to develop or modify MATLAB applications is an individual responsibility. There is ample application documentation available from the Mathworks website, potential outreach to colleagues who also use MATLAB, and options for consultation with Mathworks. Mathworks also host on-campus training seminars several times a year and provides many on-line learning tutorials.
Installation support for MATLAB at UAB is provided by your local IT support organization and the Docs wiki.
Mathworks Website
Your first and best option for application-specific questions on MATLAB is to refer to the on-line MATLAB documentation. The Mathworks site also provides a a support matrix and an on-line knowledge base.
UAB MATLAB Wiki
The MATLAB page on the Docs wiki is the starting point for installing MATLAB at UAB and, optionally, configuring it to use cluster computing. All users are encouraged to contribute to the MATLAB knowledge in this wiki, especially if you see areas where improvements are needed. Remember, this knowledge base is only as good as the people who contribute to it.
Contributing to the wiki is as easy as clicking the login link on the top-right of the page and signing in with your UAB BlazerID. If you are unsure about making an edit, you can make suggestions for improvement on the page's Discussion tab or discuss the proposed improvement in the MATLAB user group.
UAB MATLAB User Group
At UAB, MATLAB installation support is provided by your local IT support group. Support for application specific questions is available from peers in your research group. We realize that some people are not as familiar with MATLAB as others. For this reason, we have established a MATLAB user forum (mailing list) where users of MATLAB at UAB can help answer each others questions.
This is a network of volunteers sharing their knowledge with peers. You are encouraged to reach out to this community for questions on using MATLAB by
- Joining the MATLAB user group - alternately send an email to sympa@vo.uabgrid.uab.edu with the following text in the body of the email subscribe matlab-user
- After joining the group, you can email questions to the group via matlab-user@vo.uabgrid.uab.edu
Archives of MATLAB user group discussions are available on-line at https://vo.uabgrid.uab.edu/sympa/arc/matlab-user. You may find your question is already answered in these archives.
UAB MATLAB announce mailing list
To receive information about UAB's MATLAB license and announcements please subscribe to the matlab-annc mailing list by
- Joining the MATLAB announce mailing list - alternately send an email to sympa@vo.uabgrid.uab.edu with the following text in the body of the email subscribe matlab-annc