**Table of Contents**

Setting up the environment and invoking from a Research Computing server

Submitting Matlab jobs on a Research Computing server

## Overview

Matlab is a high performance language for technical computing. Computation, visualization, and programming are integrated in an easy-to-use environment. Matlab can be used for mathematics, modeling, simulation, data analysis, visualization, scientific and engineering graphics.

Default Version: |
2013a (Kure/Killdevil) |

Installed Version(s): |
2012a, 2012b, 2013a (Kure/Killdevil) |

Research Computing Servers: |
Kure, Killdevil |

Research Computing purchases the licenses (for university owned machines) for not only the basic Matlab but also for a number of toolboxes. Too see the complete list run the Matlab command

ver

from within Matlab.

You can choose to either install Matlab locally in your personal computer by ordering copy of Matlab from UNC’s Software Acquisition office or run Matlab on ITS lab computers, or the Research Computing server. Campus-wide licenses for the use of Matlab at UNC-CH are checking out from the UNC license server.

## Installation

You can install Matlab locally in your computer but check out licenses from the UNC license server. Matlab is available to faculty/staff and students for various operating systems through UNC Software Acquisition Office. Please visit their webpage for more information.

Matlab will be started locally on your machine, but the application will look for the UNC license servers through the Internet and check out licenses when it starts. **Therefore, a network connection for your machine is required for Matlab to run. **

After you get the installation copy of Matlab, refer to these directions:

- You will need a license file in order to install Matlab. Refer to these instructions to obtain a license file (license.dat).
- Follow these installation instructions to install Matlab locally.

## Setting up the environment and invoking from a Research Computing server

Matlab is available for use on the Research Computing Servers: Kure, and Killdevil. The following documents provide instructions for invoking Matlab and other high performance computing software. These documents include general instructions common to all applications, and specific instructions for each application.

- Invoking applications on a Research Computing Server from a UNIX/Linux desktop computer
- Invoking applications on a Research Computing Server from a Microsoft Windows computer

## Submitting Matlab jobs on a Research Computing server

This section covers specific examples of how to submit various types of Matlab jobs on Research Computing’s two main compute clusters: Kure and KillDevil.

To start you will need to add Matlab to your cluster environment using the module commands:

module add matlab

module initadd matlab

All of the following examples assume you are in the directory where your Matlab script is located.

### Interactive job submission

Finally, to start a Matlab job on the compute cluster which gives you the Matlab GUI you can do the command

xmatlab

For the “xmatlab” command to work you need to have an X connection to the server.

### Serial job submission

The first examples cover submitting serial Matlab jobs. On Kure and KillDevil, the easiest way to submit a serial Matlab job is to use the **bmatlab** script:

bmatlab matlabjob.m

In the above example, “matlabjob.m” is the name of the Matlab script being submitted.

If you do not want to use the bmatlab script then you can use the following command instead and modify it as necessary to suit your job’s requirements:

bsub matlab -nodisplay -nosplash -singleCompThread -r matlabjob

-logfile matlabjob.out

The above command (which should all be on one line) submits the Matlab script “matlabjob.m” (yes, leave the .m off in the “-r” part of job submission command) and creates an output file called “matlabjob.out” in the current working directory.

### Parallel job submission

**Note. MDCS is under a trial license and currently under evaluation.**

Research Computing licenses the Matlab Disbtributed Computing Server (MDCS) which can be used to run parallel Matlab jobs in a distributed fashion on the compute clusters. **To use the MDCS you need to use the matlab/2013a module**, which you can do by using the aforementioned module commands.

To get started, at the top of your Matlab script you should have the line

configCluster(‘killdevil’)

which will change your default cluster profile to the one we have created (“**killdevil_local_r2013a**“) for use with the MDCS and which gives you access to up to 16 workers. Then you can use the “matlabpool open” command to set the poolsize. For example, if I wanted to set a poolsize of 14 then my Matlab script would have

matlabpool open 14

By leaving out the name of a cluster profile in the above “matlabpool open” statement you are by default using the “**killdevil_local_r2013a**” profile we have set up and therefore you will have to specify a poolsize less than or equal to 16. So, for example, something like

matlabpool open 22

would not work since you are using the “**killdevil_local_r2013a**” profile but specifying a poolsize larger than what that profile allows.

If you need access to more than 16 workers then you can create your own cluster profile using the Matlab GUI. If you decide to do this you should use the “**killdevil_local_r2013a**” profile as the model for your new cluster profile. Note that if you don’t see the

**killdevil_local_r2013a (default)**

profile in the Cluster Profile Manager then close the manager, execute the command

configCluster(‘killdevil’)

in the Matlab GUI terminal, reopen the Cluster Profile Manger, and the profile should now be there.

In your new profile, edit only the one field for “Number of workers available to cluster” making sure to keep everything else the same and then give your new cluster profile a name. An example would be creating a new cluster profile called

**killdevil32**

where “Number of workers available to cluster” is set to 32 but is otherwise identical to

**killdevil_local_r2013a (default)**

Using the killdevil32 profile in your Matlab script will give you access to up to 32 workers. In this case, the script would contain

configCluster(‘killdevil’)

and, if you wanted to use 22 workers, the line

matlabpool open killdevil32 22

specifying the cluster profile “**killdevil32**” and a poolsize of 22.

Another thing to keep in mind is that, given how the MDCS works, you should have your matlabpool open and close statements directly around the parfor loop, i.e.

[...Matlab code...]

matlabpool open 14

parfor loop

mablabpool close

[...rest of Matlab code...]

That is, open and close the matlabpools specifically around the portions of your code that are parallel.

To submit the Matlab job, you can use the usual Matlab job submission command:

bsub matlab -nodisplay -nosplash -singleCompThread

-r MyMDCScode -logfile MyMDCScode.out

Note that with the MDCS **it is not necessary to specify the number of job slots** for your job submission. This is because of how the MDCS works, which is that when Matlab executes your script and hits the “matlabpool open” statement it turns around and submits a **n-way** job for you where “**n**” is the size of your matlabpool (as indicated in your “matlabpool open” statement). So, when you submit the original script (i.e. the one containing the matlabpool calls) there is no need to ask for multiple job slots (because Matlab takes care of this detail for you); it is sufficient to ask for just one job slot (which is the default). Because of this behavior, it is important to make sure you open and close matlabpools around the parallel portion of your code (as discussed above).

For further questions regarding how to use the MDCS, please contact Research Computing (research@unc.edu).

## Tutorials

- Introduction to Matlab is an online documentation written by the Research Computing group can help you start learning Matlab. It contains a number of examples.
- The Matlab Tutorial section of the Matlab online documentation provided by MathWorks is also useful for users new to this software.

## FAQs

## Useful links

## References

- D. Redfern and C. Campbell, “The Matlab 5 Handbook”, Springer, New York, 1998.
- D. Hanselman and B. Littlefield, “Mastering Matlab 6 – A Comprehensive Tutorial and Reference”, Prentice Hall, New Jersey, 2001.

## Additional help