User Tools

Site Tools


development:scripting_languages:matlab

Differences

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

Link to this comparison view

development:scripting_languages:matlab [2019/10/12 07:55] (current)
meesters created
Line 1: Line 1:
 +====== Mathworks MATLAB ​ ====== ​
 +
 +{{ http://​upload.wikimedia.org/​wikipedia/​commons/​thumb/​2/​21/​Matlab_Logo.png/​267px-Matlab_Logo.png?​100&​nocache}} MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment and fourth-generation programming language. Developed by MathWorks, MATLAB allows matrix manipulations,​ plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, and Fortran. (taken from http://​en.wikipedia.org/​wiki/​MATLAB,​ more details there) ​
 +
 +[[http://​www.mathworks.de/​products/​matlab/​]]\\
 +
 +<WRAP center round important 60%>
 +This page currently undergoes a revision. ​
 +</​WRAP>​
 +
 +==== Versions ====
 +
 +We currently offer the following MATLAB versions:
 +<code bash>
 +math/​MATLAB/​2017a
 +math/​MATLAB/​2018b
 +</​code>​
 +
 +You can query the versions yourself with ''​%%module av |& grep -i matlab%%''​.
 +
 +=== Usage ===
 +Load the most recent version available with:
 +<code shell>
 +$ module load math/MATLAB
 +</​code>​
 + You can also load a particular version with ''​%%module load math/​MATLAB/<​version>​%%'',​ e.g. ''​%%module load math/​MATLAB/​2017a%%''​
 +
 +See the vendor documentation:​ [[https://​www.mathworks.com/​help/​matlab/​]]
 +
 +==== License ====
 +
 +^  Matlab ​ ^^
 +|**Version:​**|R2017a,​ 2018b|
 +|**License:​**|[[http://​www.uni-mainz.de|University of Mainz]]|
 +|**Developer**:​|Mathworks|
 +
 +==== Toolboxes ====
 +
 +The currently available toolboxes are
 +
 +^ Toolbox ^ Version ^
 +|Curve Fitting Toolbox|3.5.8|
 +|Econometrics Toolbox|5.1|
 +|Fuzzy Logic Toolbox|2.4|
 +|Image Acquisition Toolbox|5.5|
 +|Image Processing Toolbox|10.3|
 +|MATLAB Compiler|7.0|
 +|MATLAB Compiler SDK|6.6|
 +|Mapping Toolbox|4.7|
 +|Optimization Toolbox|8.2|
 +|Parallel Computing Toolbox|6.13|
 +|Partial Differential Equation Toolbox|3.1|
 +|Signal Processing Toolbox|8.1|
 +|Statistics and Machine Learning Toolbox|11.4|
 +|Symbolic Math Toolbox|8.2|
 +|Wavelet Toolbox|5.1|
 +
 +
 +====== Using Matlab ======
 +Using Matlab is possible several ways, which we would like to briefly introduce here.
 +
 +===== Interactive Job Submission =====
 +Request resources according to your needs, e.g. with:
 +<code bash>
 +[joe_user@login]$ srun -n<​ntasks>​ -p<​partition>​ -A<​account>​ -t<​time>​ --mem<​amount>​ --pty --preserve-env $SHELL  ​
 +</​code>​
 +Load the desired Matlab module:
 +
 +<code bash>
 +module load math/MATLAB
 +</​code>​
 +
 +Now you can run Matlab. Add ''​-nojvm''​ flag to start Matlab without the Java virtual machine, ''​nosplash''​ prevents Matlab from displaying the Matlab logo.
 +
 +<code bash>
 +matlab -nojvm -nosplash
 +</​code>​
 +
 +Check the version info and the available toolboxes for that version:
 +
 +<code bash>
 +>> ver
 +</​code>​
 +
 +gives:
 +
 +<code bash>
 +-------------------------------------------------------------------------------------------
 +MATLAB Version: 9.5.0.944444 (R2018b)
 +...
 +Operating System: Linux 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64
 +Java Version: Java is not enabled
 +-------------------------------------------------------------------------------------------
 +MATLAB ​                                               Version 9.5         ​(R2018b)
 +Curve Fitting Toolbox ​                                ​Version 3.5.8       ​(R2018b)
 +Econometrics Toolbox ​                                 Version 5.1         ​(R2018b)
 +...
 +</​code>​
 +
 +
 +<WRAP center round info 80%>
 +**The use of the Matlab-Compiler is to be preferred!**
 +
 +Only a limited number of licences are available on the cluster. It is therefore preferable to use the Matlab-Compiler to compile your scripts beforehand. We explain more about the Matlab-Compiler as follows. ​
 +</​WRAP>​
 +
 +===== Matlab-Compiler =====
 +
 +There are several options to compile your Matlab code to stand-alone executables/​libraries. Being independent of licenses is one of the major advantages here, of course. But when running compiled code with the Matlab Runtime Envirenment (MRE) on the cluster you have to consider the threading of your code just as well as when you run Matlab itself. ​
 +Generally, Matlab detects the number of physical cores and opens the same amount of threads to make full use of the multithreading implemented in the built-in functions. So, if you call 
 +<​code>​ mcc -m my_mfile.m </​code>​ you obtain multithread code. Often this might be wanted, but you have to make sure that you select the appropriate resources for this then - namely, the appropriate core-affinity. Since Matlab wants to use everything on a host you'll have to call ''​ bsub -n 1 -R '​affinity[cores(64)]'​ ''​ and an appropriate memory reservation. ​
 +On the other hand, if your code doesn'​t need the full multithreading capability, which often is the case, you should compile your code with the flag '​singleCompThread'​ <​code>​ mcc -m -R -singleCompThread my_mfile.m </​code>​. This makes sure that your standalone code will run on a single computational thread, which not only doesn'​t frustrate the core scheduler and the other users less but improves performance of your code because less time is spent in scheduling all the threads on one core. 
 +
 +====== Examples ======
 +===== Submitting a Matlab job =====
 +
 +The flag ''​nojvm''​ starts Matlab without the Java virtual machine, ''​nodisplay''​ instructs Matlab to run without the GUI, ''​nosplash''​ prevents Matlab from displaying the Matlab logo and ''​r''​ defines the name of the script you want to run.\\
 +**Notice:** Save your file with the ''​.m''​ extension, but call it without the ''​.m''​ extension.
 +
 +For full nodes consider
 +
 +<code shell>
 +#SBATCH -p nodeshort ​           # Queue name
 +#SBATCH -n 32                   # Total number of tasks
 +#SBATCH -c 2                    # Total number of cores
 +</​code>​
 +as Matlab will not be able to fully utilize the node, but considers every FPU equal to a CPU.
 +===== Compiling a m-file on a node =====
 +
 +Using the following shell script you can compile a m-file into a stand-alone c application. It's a variation of the script for [[:​local_scratch|using local scratch on a node]]. ​
 +
 +<file bash compileFile.sh>​
 +#!/bin/bash
 +
 +# Store working directory to be safe
 +SAVEDPWD=`pwd`
 +FILENAME=$1
 +
 +# We define a bash function to do the cleaning when the signal is caught
 +cleanup(){
 +    cp /​jobdir/​${LSB_JOBID}/​*$FILENAME.sh ${SAVEDPWD}/​
 +    cp /​jobdir/​${LSB_JOBID}/​$FILENAME ${SAVEDPWD}/​
 +    exit 0
 +}
 +
 +# Register the cleanup function when SIGUSR2 is sent, ten minutes before the job gets killed
 +trap '​cleanup'​ SIGUSR2
 +
 +# Copy input file
 +cp ${SAVEDPWD}/​$FILENAME.m /​jobdir/​${LSB_JOBID}/​
 +
 +# Go to jobdir and start the program
 +cd /​jobdir/​${LSB_JOBID}
 +mcc -m $FILENAME.m
 +
 +# Call the cleanup function when everything went fine
 +cleanup
 +</​file>​
  
development/scripting_languages/matlab.txt · Last modified: 2019/10/12 07:55 by meesters