User Tools

Site Tools


matlab

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
matlab [2020/09/21 21:04]
root created
matlab [2022/06/05 16:21]
root
Line 1: Line 1:
 ====Matlab==== ====Matlab====
  
-MATLAB (MATrix LABoratory) and is a numerical computing environmentYou can find more information on the origins of Matlab [[https://www.mathworks.com/company/newsletters/articles/the-origins-of-matlab.html|here]].+Matlab is a matrix-oriented computing language UA/Fayetteville has a campus-wide license We have permission from Mathworks to serve this program to in-state users but not to users outside of Arkansas who are not affiliated with UAF.
  
-====Enviornment Setup====+The GUI version of Matlab is best accessed via interactive batch job on OpenOnDemand (pinnacle-portal).  The text version may be accessed via batch job or interactive batch job with terminal.
  
-To use matlab for the batch job we will demonstrate we need to load the required module. You can do this by modifying your ''$HOME/.bashrc'' file to include the current Matlab module.+Usually the latest installed version is the best, though multiple older versions are installed.
  
 <code> <code>
-module load matlab/r2017a+module load matlab/r2022a
 </code> </code>
  
-In your ''$HOME'' directory create another directory to run the Matlab jobs, and add the example job from Matlab that we will modify.+==GPU computing== 
 + 
 +Matlab in recent years has recently added a number of modern features such as GPU supportbig data analysis and machine learning.   A simple benchmark follows for CPU vs GPU code to find the eigenvalues of a fairly large matrix.
  
 <code> <code>
-razor-l1:jokinsey:~mkdir MATLAB-JOBS +cat eigcpu.m 
-razor-l1:jokinsey:~cp /share/apps/matlab/R2017a/examples/matlab_featured/MultiplePlotsExample.m MATLAB-JOBS/+a=rand(32768,32768); 
 +b=zeros(size(a)); 
 +tic; 
 +b = eig(a); 
 +toc; 
 +$ matlab -nodesktop -nosplash < eigcpu.m
 </code> </code>
  
-====Example Batch Job====+This requires about 2700 seconds on 32-core Intel nodes and 5300 seconds on 64-core AMD nodes.  Matlab matrix functions make extensive use of Intel MKL and are often more performant on Intel systems.  Also Intel AVX512 functions not present on AMD may be significant.
  
-To get output an output from the job we need to modify the exampleAt the top of the file where figure is defined set figure equal to a value so we can save it to a file later.+The GPU version is selected in code, commands are the same Initializing the first array as gpuArray is sufficient to use the available GPU functions, see [[https://www.mathworks.com/help/parallel-computing/gpu-computing-in-matlab.html]]  GPU and CPU multithreading are more effective on functions such as ''eig()'' than in serial Matlab code.
  
 <code> <code>
-figure;+$ cat eiggpu.m 
 +a=gpuArray(rand(32768,32768)); 
 +b=zeros(size(a)); 
 +tic; 
 +b = eig(a); 
 +toc; 
 +$ matlab -nodesktop -nosplash < eiggpu.m
 </code> </code>
  
-At any point after a plot is created you can save the figure to a pdf file ''test'' which will export the figure so we can view it later. You can find documentation on this [[https://www.mathworks.com/help/matlab/ref/saveas.html|here]].+This requires about 850 seconds on V100 gpu nodes and 700 seconds on A100 single gpu nodes.
  
-<code> +==Parallel Computing==
-saveas(f,'test','pdf'); +
-</code>+
  
-Once the example has been preparedcreate ''PBS'' script named ''matlabTest.pbs'' which looks like the script below to run the job.+Matlab has several forms of parallel computing.  Many functions are multithreaded.  Many matrix functions are implemented in Intel MKL which is also multithreaded.  Explicit parallel computing is available with parallel toolbox/parallel serversee [[https://www.nrel.gov/hpc/eagle-software-matlab-pct.html]] for an example on similarly-configured cluster The configuration is simpler on a single node (to Matlab, parallel toolbox or the local cluster) as in the NREL example.
  
-<code> +See also [[https://www.cs.usask.ca/~spiteri/CMPT851/notes/parallelMatlab.pdf]] 
-#!/bin/bash +
-#PBS -N matlab +
-#PBS -q tiny16core +
-#PBS -j oe +
-#PBS -o matlab.$PBS_JOBID +
-#PBS -l nodes=1:ppn=16 +
-#PBS -l walltime=1:00:00 +
- +
-cd $PBS_O_WORKDIR +
-cp MultiplePlotsExample./scratch/$PBS_JOBID +
-cd /scratch/$PBS_JOBID +
- +
-matlab -nodesktop -nosplash < MultiplePlotsExample.m +
-cp /scratch/$PBS_JOBID/test.pdf $PBS_O_WORKDIR +
-</code> +
- +
-All that's left to do is submit the job. +
- +
-<code> +
-razor-l1:jokinsey:~/MATLAB-JOBS$ qsub matlab.pbs +
-</code>+
  
 +[[https://research.unsw.edu.au/document/UNSW_Parallel%20Computing%20with%20MATLAB.pdf]]
  
 +[[https://www.hpc.iastate.edu/guides/using-matlab-parallel-server]]
matlab.txt · Last modified: 2022/06/05 19:44 by root