.. _matlab:
################################################################################
Matlab
################################################################################
.. image:: images/Matlab.jpg
:align: center
MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use interactive environment where problems and solutions are expressed in familiar mathematical notation. This high-level language and interactive environment enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++, and Fortran.
...........................................
Toolboxes
===============================================================================
The MATLAB Toolboxes licensed by ND changes each year based on user demand (measured by an annual survey). Faculty may also purchase toolbox licenses which were not centrally funded based on broad user demand. To see what toolboxes are currently available simply type **ver** in the Matlab Command Window.
...........................................
Submitting Single Core Jobs
===============================================================================
To submit a single core MATLAB job (running the your_file.m file) to CRC systems use the following template:
.. code-block:: shell
#!/bin/bash
#$ -q long
#$ -pe smp 1
module load matlab
matlab -singleCompThread -nodisplay -nosplash -batch "your_file;exit"
By default, recent versions of MATLAB will try to automatically multithread processing on all the cores available on a machine. If you are only requesting one core in your submission script, you need to invoke MATLAB with the ``-singleCompThread`` option (to avoid interfering with other user's running jobs):
.. code-block:: shell
matlab -singleCompThread ...
.. warning::
If you request more than 1 core, maxNumCompThreads function should be used to control the maximum number of computational threads.
For example, adding the following line in your MATLAB code will limit the number of threads to the same number as that you entered for the ``-pe smp`` flag in your job script:
.. code-block:: shell
maxNumCompThreads(str2num(getenv("NSLOTS")));
...........................................
Submitting Multicore Jobs
===============================================================================
To submit multicore MATLAB jobs (up to 64 cores with current CRC systems) using the PCT (Parallel Computing Toolbox), use the following template. Note that there are normally multiple versions of MATLAB available, see the :ref:`modules` page for more information on how software is organized within the CRC.
.. code-block:: shell
#!/bin/bash
#$ -q long
#$ -pe smp 12
export MATLABPATH=~/path/to/matlab_file
cd ~/path/to/matlab_file
module load matlab
matlab -nodisplay -nosplash -batch "matlab_file;exit"
The matlab file above includes the command ``parpool('local',12)``, allowing MATLAB to use the 12 cores on the machine.
Parallelization can also be accomplished using a parfor within your matlab file:
.. code-block:: shell
parpool('local', 12);
parfor i=1:N
end
% In Matlab 8.5 need to use "delete(gcp('nocreate'))"
...........................................
MATLAB and Array Jobs
===============================================================================
An example for combining MATLAB and job arrays is as follows:
.. code-block:: shell
#!/bin/bash
#$ -N testarray
#$ -t 1-4:1
#$ -M netid@nd.edu
#$ -m abe
export MATLABPATH=directory_path_to_your_files.m:other_user_contrib_directory_path
matlab -nodisplay -nosplash -nojvm -batch "myFunction(${SGE_TASK_ID});exit"
The myfunction.m will receive respectively for each task 1,2,3 and 4 as an input parameter.
...........................................
Memory Profiling
===============================================================================
User can use the builtin MATLAB profiler to understand memory usage in your scripts. To enable memory profiling add the following line to your scripts:
.. code-block:: shell
profile -memory on;
...........................................
License Information
===============================================================================
* MATLAB Parallel Computing Toolbox can be currently configured up to 64 cores (SMP) per simulation.
...........................................
Tutorials and Training
===============================================================================
* For more information, please visit the official MATLAB training `page `_ for a wealth of video tutorials and training content.
...........................................
Dynare Support
=============================================================================
Looking to use MATLAB with ``dynare``? Simply load the ``dynare`` module, this will automatically bring in all dependencies. You can check which versions of dynare are available with::
module avail dynare
Further Information
===============================================================================
See the official site: `MATLAB `__