Difference between revisions of "Applications/Matlab"

From HPC
Jump to: navigation , search
(Toolboxes)
m
 
(52 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__TOC__
 
__TOC__
 
=== Application Details ===
 
=== Application Details ===
* Description: MATLAB  is a numerical computing environment and programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, and implementation of algorithms. A  range of toolboxes are available to extend functionality.
+
* Description: MATLAB  is a numerical computing environment and programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, and implementation of algorithms. A  range of toolboxes is available to extend functionality.
* Versions: 2016a
+
* Versions: 2016a, 2016b, 2017a, 2018a, 2019a, 2020a
* Module names: matlab/2016a
+
* Module names: matlab/2016a matlab/2016b  matlab/2017a  matlab/2018a matlab/2019a matlab/2020a
* License: University of Hull Total Academic Headcount license, available to everyone
+
* License: University of Hull Total Academic Headcount license, available to members of the university for research use
  
 
==== Toolboxes ====
 
==== Toolboxes ====
{| class="wikitable"  style="background-color:#f5f5dc;"
+
Matlab on our HPC has the following toolboxes available:
 +
{| class="wikitable mw-collapsible mw-collapsed"  style="background-color:#f5f5dc;"
 +
|-
 +
! Toolbox
 +
! Toolbox
 +
! Toolbox
 +
! Toolbox
 +
|-
 
|  MATLAB
 
|  MATLAB
 
|  Filter Design HDL Coder
 
|  Filter Design HDL Coder
Line 75: Line 82:
  
 
== Usage Examples ==
 
== Usage Examples ==
 +
{|
 +
|style="width:5%; border-width: 0;cellpadding=0" | [[File:icon_exclam3.png]]
 +
|style="width:95%; border-width: 0;cellpadding=0" | By default Matlab will make use of multithreading for certain functions, with the maximum number of computational threads equal to the number of computational cores on the node. If a job or session hasn't requested an appropriate resource, this multithreading can cause contention for CPU resources and negatively impact other users. For this reason when using the standard '''matlab''' command please make sure you request appropriate resources by either:
 +
* Using an exclusive session, e.g. use '''interactive --exclusive''' or submit a task with the '''#SBATCH --exclusive''' option
 +
* Starting matlab using '''matlab ‑singleCompThread''' which limits Matlab to using a single CPU core
 +
|-
 +
|}
  
 +
<!--=== Executables ===
 +
{| class="wikitable" style="background-color:#f5f5dc;"
 +
! Executable
 +
! Description
 +
|-
 +
| MatLab
 +
| By default Matlab will make use of multithreading for certain functions, with the maximum number of computational threads equal to the number of computational cores on the node. If a job or session hasn't requested an appropriate resource, this multithreading can cause contention for CPU resources and negatively impact other users. For this reason when using the standard '''matlab''' command please make sure you request appropriate resources by either using an exclusive session with '''interactive --exclusive''' or submitting a task with the '''#SBATCH --exclusive'''. See [[Applications/Matlab#Parallel_Matlab | Parallel Matlab]]
 +
|-
 +
| matlab&nbsp;&#8209;singleCompThread ## need to replace matlab ‑singleCompThread with a non-breaking space followed by a non-breaking hyphen otherwise this looks rubbish cc 2018-09-25 ##
 +
| If you do not require the possible performance benefits provided by using multiple cores, please run Matlab with &#8209;singleCompThread option and it will only use a single CPU core. See [[Applications/Matlab#Parallel_Matlab | Parallel Matlab]]
 +
|}
 +
-->
 
=== Interactive ===
 
=== Interactive ===
Interactive with full graphical interface:
+
Interactive with full graphical interface (note the use of --exclusive when starting the interactive session):
 
<pre style="background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
 
<pre style="background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
[username@login01 ~]$ interactive
+
[username@login01 ~]$ interactive --exclusive
 
salloc: Granted job allocation 289663
 
salloc: Granted job allocation 289663
 
Job ID 289663 connecting to c170, please wait...
 
Job ID 289663 connecting to c170, please wait...
 
Last login: Thu Jan 26 12:59:11 2017 from 10.254.5.246
 
Last login: Thu Jan 26 12:59:11 2017 from 10.254.5.246
[username@c170 ~]$ module add matlab/2016a
+
[username@c170 ~]$ module add matlab/2020a
[username@c170 ~]$ matlab
+
[username@c170 ~]$ matlab  
 
</pre>
 
</pre>
  
Line 92: Line 118:
  
 
                                                     < M A T L A B (R) >
 
                                                     < M A T L A B (R) >
                                           Copyright 1984-2016 The MathWorks, Inc.
+
                                           Copyright 1984-2020 The MathWorks, Inc.
                                           R2016a (9.0.0.341360) 64-bit (glnxa64)
+
                                           R2020a Update 4 (9.8.0.1417392) 64-bit (glnxa64)
                                                     February 11, 2016
+
                                                     June 24, 2020
 
 
  
 
To get started, type one of these: helpwin, helpdesk, or demo.
 
To get started, type one of these: helpwin, helpdesk, or demo.
 
For product information, visit www.mathworks.com.
 
For product information, visit www.mathworks.com.
 
  
 
         Academic License
 
         Academic License
Line 107: Line 131:
  
 
=== Batch Submission ===
 
=== Batch Submission ===
 +
To submit a batch job for Matlab, put your code in a .m script file and refer to this in your batch submission script, as shown below in the example MATLABtest.job job script. Remember to leave the .m extension from the script name in the Matlab command line.
 
<pre style="background-color: #C8C8C8; color: black; font-family: monospace, sans-serif;">
 
<pre style="background-color: #C8C8C8; color: black; font-family: monospace, sans-serif;">
 
#!/bin/bash
 
#!/bin/bash
#SBATCH -J MATLAB          # Job name, you can change it to whatever you want
+
#SBATCH -J MATLAB           
#SBATCH -N 1                # Number of nodes (for Matlab should be always one)
+
#SBATCH -N 1                 
#SBATCH -o %N.%j.out       # Standard output will be written here
+
#SBATCH -o %N.%j.out      
#SBATCH -e %N.%j.err        # Standard error will be written here
+
#SBATCH -e %N.%j.err         
#SBATCH -p compute          # Slurm partition, where you want the job to be queued
+
#SBATCH -p compute           
#SBATCH -t 0-01:30          # Your expected run-time format in D-HH:MM
+
#SBATCH --exclusive  
#SBATCH --exclusive
 
 
   
 
   
 
module purge
 
module purge
module add matlab/2016a
+
module add matlab/2020a
 
   
 
   
matlab -nodisplay -nojvm -nodesktop -nosplash -r my_matlab_m_file
+
matlab -nodisplay -r my_matlab_m_file
 
</pre>
 
</pre>
This submission script can be found at /path/to/sample/script
+
 
Matlab  
+
To submit the Matlab job, use sbatch as shown below:
  
 
<pre style="background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
 
<pre style="background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
Line 131: Line 155:
  
 
== Parallel Matlab ==
 
== Parallel Matlab ==
By default Matlab on Viper will run on a single core as mutli-threading conflicts with the schedulers resource management, however there are three ways in which Matlab can utilise multiple processors:
+
By default Matlab on Viper will run on a single core as multi-threading conflicts with the schedulers resource management, however, there are two ways in which Matlab can utilize multiple processors:
  
 
=== Multi-threading ===
 
=== Multi-threading ===
Matlab can use multiple threads for certain built in functions for example linear algebra and numerical functions such as fft, \ (mldivide), eig, svd, and sort. These functions automatically execute on multiple computational threads in a single MATLAB session, allowing them to execute faster on multicore-enabled machines. Additionally, many functions in Image Processing Toolbox are multithreaded
+
Matlab can use multiple threads for certain built-in functions for example linear algebra and numerical functions such as fft, \ (mldivide), eig, svd, and sort. These functions automatically execute on multiple computational threads in a single MATLAB session, allowing them to execute faster on multicore-enabled machines. Additionally, many functions in the Image Processing Toolbox are multithreaded.
 +
 
 +
Firstly, using the '''matlab''' command with the -singleCompThread option:
 +
<pre style="background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
 +
[username@c170 ~]$ matlab -singleCompThread -nodisplay -nojvm -nodesktop -nosplash -r "maxNumCompThreads , exit"
 +
 
 +
                                                    < M A T L A B (R) >
 +
                                          Copyright 1984-2016 The MathWorks, Inc.
 +
                                          R2016a (9.0.0.341360) 64-bit (glnxa64)
 +
                                                    February 11, 2016
 +
 
 +
For online documentation, see http://www.mathworks.com/support
 +
For product information, visit www.mathworks.com.
 +
 
 +
        Academic License
 +
 
 +
Warning: maxNumCompThreads will be removed in a future release. Please remove any instances of this function from your code.
 +
> In maxNumCompThreads (line 26)
 +
 
 +
ans =
 +
 
 +
    1
 +
</pre>
 +
 
 +
Using the standard '''matlab''' command, on Viper this starts Matlab with multithreading support enabled:
 +
<pre style="background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
 +
[username@c170 ~]$ matlab -nodisplay -nojvm -nodesktop -nosplash -r "maxNumCompThreads , exit"
 +
 
 +
                                                    < M A T L A B (R) >
 +
                                          Copyright 1984-2016 The MathWorks, Inc.
 +
                                          R2016a (9.0.0.341360) 64-bit (glnxa64)
 +
                                                    February 11, 2016
 +
 
 +
For online documentation, see http://www.mathworks.com/support
 +
For product information, visit www.mathworks.com.
 +
 
 +
        Academic License
 +
 
 +
Warning: maxNumCompThreads will be removed in a future release. Please remove any instances of this function from your code.
 +
> In maxNumCompThreads (line 26)
 +
 
 +
ans =
 +
 
 +
    28
 +
</pre>
 +
 
 +
When using Matlab with multicore enabled, please ensure you have exclusive access to the node, see [[Quickstart/Interactive#Exclusive_interactive_session | Exclusive interactive]] or [[Quickstart/Batch Jobs#Exclusive Batch Jobs|Exclusive batch jobs]].
  
 
=== Parallel Computing Toolbox ===
 
=== Parallel Computing Toolbox ===
 
The Parallel Computing Toolbox allows you to open a number of workers (separate Matlab engines) on the local node, up to the number of cores on that node (28 for standard nodes in an exclusive session).  
 
The Parallel Computing Toolbox allows you to open a number of workers (separate Matlab engines) on the local node, up to the number of cores on that node (28 for standard nodes in an exclusive session).  
  
<pre style="background-color: #f5f5dc ; color: black; font-family: monospace, sans-serif;">
+
<pre style="background-color: #f5f5dc; color: black; font-family: monospace, sans-serif;">
 
>> parpool('local',28)
 
>> parpool('local',28)
 
Starting parallel pool (parpool) using the 'local' profile ... connected to 28 workers.
 
Starting parallel pool (parpool) using the 'local' profile ... connected to 28 workers.
Line 155: Line 225:
 
</pre>
 
</pre>
  
=== Distributed Computing Toolbox ===
+
When using Matlab with the Parallel Computing Toolbox, please ensure you have exclusive access to the node, see [[Quickstart/Interactive#Exclusive_interactive_session | Exclusive interactive]] or [[Quickstart/Batch Jobs#Exclusive_Batch_Jobs|Exclusive batch jobs]].
The distributed computing toolbox is not currently supported on Viper
 
  
== Change Log ==
+
==Next Steps==
[2017-01-30] Changed default Matlab launch command in module to matlab -singleCompThread to disable multi-threading
 
 
 
== Further Information ==
 
* [https://www.hpc.hull.ac.uk/forum/viewforum.php?f=14 UoH Matlab forum]
 
 
* [https://www.mathworks.com/products/matlab.html Matlab website]
 
* [https://www.mathworks.com/products/matlab.html Matlab website]
 
* [http://www.mathworks.com/academia/student_center/tutorials.html Useful Matlab tutorials]  
 
* [http://www.mathworks.com/academia/student_center/tutorials.html Useful Matlab tutorials]  
* [[Main Page#General_Support|Wiki: General Support]]
+
* [https://uk.mathworks.com/discovery/matlab-multicore.html Matlab multicore]
* [[Main Page|Wiki: Home]]
+
 
 +
{{Modulepagenav}}

Latest revision as of 11:15, 23 March 2023

Application Details

  • Description: MATLAB is a numerical computing environment and programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, and implementation of algorithms. A range of toolboxes is available to extend functionality.
  • Versions: 2016a, 2016b, 2017a, 2018a, 2019a, 2020a
  • Module names: matlab/2016a matlab/2016b matlab/2017a matlab/2018a matlab/2019a matlab/2020a
  • License: University of Hull Total Academic Headcount license, available to members of the university for research use

Toolboxes

Matlab on our HPC has the following toolboxes available:

Toolbox Toolbox Toolbox Toolbox
MATLAB Filter Design HDL Coder MATLAB Report Generator SimRF
Simulink Financial Instruments Toolbox Model Predictive Control Toolbox Simscape
Aerospace Blockset Financial Toolbox Neural Network Toolbox Simscape Electronics
Bioinformatics Toolbox Fixed-Point Designer Optimization Toolbox Simscape Multibody
Communications System Toolbox Fuzzy Logic Toolbox Parallel Computing Toolbox Simscape Power Systems
Computer Vision System Toolbox Global Optimization Toolbox Partial Differential Equation Toolbox Simulink Coder
Control System Toolbox Image Acquisition Toolbox Phased Array System Toolbox Simulink Control Design
Curve Fitting Toolbox Image Processing Toolbox RF Toolbox Simulink Design Optimization
DSP System Toolbox Instrument Control Toolbox Robotics System Toolbox Stateflow
Database Toolbox LTE System Toolbox Robust Control Toolbox Statistics and Machine Learning Toolbox
Datafeed Toolbox MATLAB Coder Signal Processing Toolbox Symbolic Math Toolbox
Econometrics Toolbox MATLAB Compiler SimBiology System Identification Toolbox
Embedded Coder MATLAB Compiler SDK SimEvents Wavelet Toolbox

Usage Examples

Icon exclam3.png By default Matlab will make use of multithreading for certain functions, with the maximum number of computational threads equal to the number of computational cores on the node. If a job or session hasn't requested an appropriate resource, this multithreading can cause contention for CPU resources and negatively impact other users. For this reason when using the standard matlab command please make sure you request appropriate resources by either:
  • Using an exclusive session, e.g. use interactive --exclusive or submit a task with the #SBATCH --exclusive option
  • Starting matlab using matlab ‑singleCompThread which limits Matlab to using a single CPU core

Interactive

Interactive with full graphical interface (note the use of --exclusive when starting the interactive session):

[username@login01 ~]$ interactive --exclusive
salloc: Granted job allocation 289663
Job ID 289663 connecting to c170, please wait...
Last login: Thu Jan 26 12:59:11 2017 from 10.254.5.246
[username@c170 ~]$ module add matlab/2020a
[username@c170 ~]$ matlab 

Interactive with command line only:

[username@c170 ~]$ matlab -nodisplay

                                                    < M A T L A B (R) >
                                          Copyright 1984-2020 The MathWorks, Inc.
                                           R2020a Update 4 (9.8.0.1417392) 64-bit (glnxa64)
                                                     June 24, 2020

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

        Academic License

>>

Batch Submission

To submit a batch job for Matlab, put your code in a .m script file and refer to this in your batch submission script, as shown below in the example MATLABtest.job job script. Remember to leave the .m extension from the script name in the Matlab command line.

#!/bin/bash
#SBATCH -J MATLAB           
#SBATCH -N 1                
#SBATCH -o %N.%j.out       
#SBATCH -e %N.%j.err        
#SBATCH -p compute          
#SBATCH --exclusive 
 
module purge
module add matlab/2020a
 
matlab -nodisplay -r my_matlab_m_file

To submit the Matlab job, use sbatch as shown below:

[username@login01 ~]$ sbatch MATLABtest.job
Submitted batch job 289522

Parallel Matlab

By default Matlab on Viper will run on a single core as multi-threading conflicts with the schedulers resource management, however, there are two ways in which Matlab can utilize multiple processors:

Multi-threading

Matlab can use multiple threads for certain built-in functions for example linear algebra and numerical functions such as fft, \ (mldivide), eig, svd, and sort. These functions automatically execute on multiple computational threads in a single MATLAB session, allowing them to execute faster on multicore-enabled machines. Additionally, many functions in the Image Processing Toolbox are multithreaded.

Firstly, using the matlab command with the -singleCompThread option:

[username@c170 ~]$ matlab -singleCompThread -nodisplay -nojvm -nodesktop -nosplash -r "maxNumCompThreads , exit"

                                                    < M A T L A B (R) >
                                          Copyright 1984-2016 The MathWorks, Inc.
                                           R2016a (9.0.0.341360) 64-bit (glnxa64)
                                                     February 11, 2016

For online documentation, see http://www.mathworks.com/support
For product information, visit www.mathworks.com.

        Academic License

Warning: maxNumCompThreads will be removed in a future release. Please remove any instances of this function from your code.
> In maxNumCompThreads (line 26)

ans =

     1

Using the standard matlab command, on Viper this starts Matlab with multithreading support enabled:

[username@c170 ~]$ matlab -nodisplay -nojvm -nodesktop -nosplash -r "maxNumCompThreads , exit"

                                                    < M A T L A B (R) >
                                          Copyright 1984-2016 The MathWorks, Inc.
                                           R2016a (9.0.0.341360) 64-bit (glnxa64)
                                                     February 11, 2016

For online documentation, see http://www.mathworks.com/support
For product information, visit www.mathworks.com.

        Academic License

Warning: maxNumCompThreads will be removed in a future release. Please remove any instances of this function from your code.
> In maxNumCompThreads (line 26)

ans =

     28

When using Matlab with multicore enabled, please ensure you have exclusive access to the node, see Exclusive interactive or Exclusive batch jobs.

Parallel Computing Toolbox

The Parallel Computing Toolbox allows you to open a number of workers (separate Matlab engines) on the local node, up to the number of cores on that node (28 for standard nodes in an exclusive session).

>> parpool('local',28)
Starting parallel pool (parpool) using the 'local' profile ... connected to 28 workers.

ans = 

 Pool with properties: 

            Connected: true
           NumWorkers: 28
              Cluster: local
        AttachedFiles: {}
          IdleTimeout: 30 minute(s) (30 minutes remaining)
          SpmdEnabled: true

When using Matlab with the Parallel Computing Toolbox, please ensure you have exclusive access to the node, see Exclusive interactive or Exclusive batch jobs.

Next Steps





Modules | Main Page | Further Topics