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
matlab [2020/09/21 21:04]
root created
matlab [2022/06/05 19:44] (current)
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.+==Benchmarks== 
 + 
 +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 sec on 32-core Intel nodes and 5300 sec on 64-core AMD nodes.  Matlab matrix functions make extensive use of Intel MKL and are often more performant on Intel systems. To what degree that is deliberate on the part of Intel is disputed Also Intel AVX512 functions not present on AMD may be significant.  With an older version of Matlab and MKL, that time on AMD is reduced to 4400 sec.
- +
-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.+
  
 <code> <code>
-f = figure;+module load mkl/19.0.5 matlab/R2019b
 </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]].+Matlab doesn't use module-loaded MKL (it has its own copy) but mkl versions < 20 on AMD in our module set this environment variable, see [[https://www.mathworks.com/matlabcentral/answers/330889-does-matlab-perform-well-on-amd-ryzen]]
  
 <code> <code>
-saveas(f,'test','pdf');+MKL_DEBUG_CPU_TYPE=5
 </code> </code>
  
-Once the example has been preparedcreate a ''PBS'' script named ''matlabTest.pbs'' which looks like the script below to run the job.+which improves the performance on AMD of MKL versions less than 20, which correspond to Matlab versions less than 2020.
  
-<code> +==GPU computing==
-#!/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 +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 much more effective on functions such as ''eig()'' than in serial Matlab code, which mostly requires changes such as ''parfor()'' for speedup.
-cp MultiplePlotsExample./scratch/$PBS_JOBID +
-cd /scratch/$PBS_JOBID+
  
-matlab -nodesktop -nosplash < MultiplePlotsExample.m +<code> 
-cp /scratch/$PBS_JOBID/test.pdf $PBS_O_WORKDIR+$ cat eiggpu.m 
 +a=gpuArray(rand(32768,32768)); 
 +b=zeros(size(a)); 
 +tic; 
 +b = eig(a); 
 +toc; 
 +matlab -nodesktop -nosplash < eiggpu.m
 </code> </code>
  
-All that's left to do is submit the job.+This requires about 850 seconds on V100 gpu nodes and 700 seconds on A100 single gpu nodes.
  
-<code> +==Parallel Computing== 
-razor-l1:jokinsey:~/MATLAB-JOBS$ qsub matlab.pbs + 
-</code>+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 server, see [[https://www.nrel.gov/hpc/eagle-software-matlab-pct.html]] for an example on a similarly-configured cluster.  The configuration is simpler on a single node (to Matlab, parallel toolbox or the local cluster) as in the NREL example
 + 
 +See also [[https://www.cs.usask.ca/~spiteri/CMPT851/notes/parallelMatlab.pdf]] 
  
 +[[https://research.unsw.edu.au/document/UNSW_Parallel%20Computing%20with%20MATLAB.pdf]]
  
 +[[https://www.hpc.iastate.edu/guides/using-matlab-parallel-server]]
matlab.1600722270.txt.gz · Last modified: 2020/09/21 21:04 by root