software:matlab:matlab

This is an old revision of the document!


Using Matlab

MATLAB® is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java™

See Computational model for running Matlab on a shared Cluster

License information

MATLAB is product licensed by Mathworks. The MATLAB product and related toolboxes are usually installed, on campus, to use the UD license server. When MATLAB is started a license token is checked out from the license server. Each toolbox function also requires the availability of a license token to start during a MATLAB session. The UD license server currently has tokens for core MATLAB and about 40 toolboxes.

The Mathworks R2013b and newer license server is being queried every 6 minutes on each cluster for available seats licensed for Matlab, Simulink and associated toolboxes.

Project directory

MATLAB is a language for scientific computing. A MATLAB project consists of a main program, called a MATLAB script, that when executed will read data, call MATLAB functions, and write data. This data may be in the form of text files, image files, MATLAB save files (MAT-file), or any of many standard file formats, e.g., HDF5. To keep your project portable you should put your scripts, functions and data in one directory. This directory is called the Current Folder on the MATLAB desktop.

MATLAB has tools to help you make your project portable, and you should use them. For example, you should specify all files using MATLAB file construction functions.

MAT-file save format:

Your preferences at

MATLAB → General → MAT-files

may have a older MAT-file save format selected as the default. You should check to make sure you can save large files (greater than 2GB) for all versions of MATLAB where you may write .mat files. There is another advantage to using the newest file format:

You can load parts of variables from a MAT-file.

When you have a MATLAB job tested and debugged in a project directory, you are ready run on a cluster.

Copy the project folder to a directory on the cluster. Use any file transfer client to copy your entire project directory.

Batch job

See cluster details for running MATLAB as a batch job since each cluster will have different job templates based on the job scheduler such as Slurm or Grid Engine. You should have a copy of your MATLAB project directory on the cluster.

Versions of MATLAB

MATLAB has a new version twice a year. It is important to keep the version you use on your desktop the same as the one on the cluster. The command

vpkg_versions matlab

will show you the versions available on a cluster. Choose the one that matches the version on your desktop. We recommend you do not upgrade MATLAB in the middle of a project, unless there is a new feature or bug fix you need.

Two directories

It is frequently advisable to keep your MATLAB project clean from non-MATLAB files such as the queue script file and the script output file. But you may combine them, and even use the MATLAB editor to create the script file and look at the output file. If you create the file on a PC, take care to not transfer the files as binary. See Transfer Files for the appropriate cluster.

When you have one combined directory, do not put the cd command in the queue script; instead, change to the project directory using cd on the command line, before submitting your job.

You should create a job script file to submit a batch job. Start by modifying a job template file (/opt/templates), for example, to submit a serial job on one core of a compute node, copy the serial template. In your copy change the commented vpkg_require command to require MATLAB, and then add your shell commands to the end of the file. Your copy may contain the lines:

# Add vpkg_require commands after this line:
vpkg_require matlab

# Now append all of your shell commands necessary to run your program
# after this line:
cd project_directory
matlab -nodisplay -singleCompThread -r main_script

The project_directory should have a file named main_script.m with your script. It could have just one line display 'Hello World'.

For more examples, including examples that use multiple computational threads or the Parallel toolbox, see the cluster details

Parallel job

You can use multicore or multiprocessor MATLAB for your project. There are three ways do this using the cluster scheduler and/or MATLAB toolboxes.

Multiple, independent, single-threaded MATLAB scripts can be run on the same node, or different nodes. The only communication between the jobs is through reading and writing files. Your script should be compiled using mcc so it can be deployed on the cluster to run in a MATLAB Runtime environment.

MATLAB will detect you are on a multicore host and use all the cores it can to speed up its internal calculations. Use MATLAB builtin functions to take advantage of these multiple computational threads. You should scedule a computing node with exclusive access, so your job does not interfere with other jobs on the node.

Using the MATLAB Parallel Computing Toolbox you can create a pool of workers and take control of the parallelism in your algorithm using MATLAB functions such as parfor. You can run this on one node using the default local scheduler, but the real benefit comes with a separate Mathworks product called the MATLAB Distributed Computing Server

Additional Resources

  • software/matlab/matlab.1566937643.txt.gz
  • Last modified: 2019-08-27 16:27
  • by anita