MATLAB can be run on taki in two modes: (i) Interactive mode and (ii) batch mode.
(i) Generally, running MATLAB interactively, in particular when using the desktop GUI (graphical user interface), should be done on the actual computer that you are actually sitting at in your office or your own laptop. Displaying graphics, including MATLAB’s desktop GUI across any network, is inherently slow and should also be unnecessary, given that UMBC’s campus license allows the installation of MATLAB with all of its toolboxes on any faculty, staff, or student computer. But if you must, instructions are below for how to get an allocation of a core on the dedicated interactive node for interactive use. Start MATLAB on that node after you have been connected to the node. Remember to exit several times to relinquish your allocation, as explained below! The use of a login node for MATLAB is not allowed.
(ii) Below are also instructions how to run MATLAB in batch mode. This means that your job is submitted just like any other executable to the scheduler, waits in the queue for an available node, and then runs MATLAB for you. You receive the output files and captured stdout and stderr after the run. While no figure windows are displayed on the screen, they actually get created, and MATLAB’s print or saveas functions save each figure to a graphics file (e.g., PNG file). This mode of running MATLAB is suitable to a shared cluster. For a general introduction, see the run tutorial on how to submit production runs on the batch partition. A basic introduction to running MATLAB in the computer labs at UMBC is available on the CIRC webpage here.
For more information about the software, see the MATLAB website.
The current version of MATLAB should be loaded as part of the default environment when you log in to taki. In case of difficulties with that, run again manually the command
[gobbert@taki-usr1 ~]$ module load MATLAB
Running MATLAB interactively
Taki has a dedicated node (inter101) for running software interactively, details of which can be found in the System Description page. Resources from the node can be requested by issuing the following commands on the login node. Since MATLAB requires more memory than typical, we use the ‘–mem=10G’ option which requests 10 GB of memory; this value has proven sufficient for most MATLAB jobs. It can be increased if MATLAB requires more total memory, but doing so might affect how long your jobs wait in the SLURM queue.
[gobbert@taki-usr1 ~]$ salloc --partition=interactive --qos=short -N1 -n1 --mem=10G --time=00:05:00
The command asks slurm to allocate the specified resources to the user. In this case, the user gobbert requests a single core from the interactive node. For more details on these options, see the ‘How to Run Programs on taki‘ webpage. When slurm is able to allocate these resources, a message such as the following appears.
salloc: Granted job allocation 32397 [gobbert@taki-usr1 ~]$
At this point, the node is allocated, but you are still on taki-usr1. In order to log into the allocated node, the following command can be used to preserve the X11 tunnel (providing GUI).
[gobbert@taki-usr1 ~]$ ssh -Y $SLURM_NODELIST
You should see a new prompt now that indicates the assigned node inter101 (in place of “taki-usr1”). You can now launch MATLAB, as shown below. We suggest to use Matlab in non-graphics mode inside the shell for efficiency, that is, without its extensive GUI (graphical user interface) called the MATLAB Desktop; this is accomplished by the
-nodesktop option to MATLAB. We show how to quit MATLAB by saying ‘exit’ at the MATLAB prompt. When finished with MATLAB, you are still logged in on the assigned interactive node, so you must explicitly exit the shell on that node by it by saying ‘exit’ at the Linux prompt. At this point, you still have the node allocated on slurm. One more ‘exit’ relinquishes this allocation. Always make sure to relinquish the interactive node, when done with it! The message at the end below confirms that we have relinquished the node.
[gobbert@inter101 ~]$ matlab -nodesktop -nosplash MATLAB is selecting SOFTWARE OPENGL rendering. Opening log file: /home/gobbert/java.log.13099 Copyright 1984-2018 The MathWorks, Inc. R2020b (184.108.40.2067703) 64-bit (glnxa64) August 26, 2020 To get started, type doc. For product information, visit www.mathworks.com. >> ... ... >> exit [gobbert@inter101 ~]$ exit logout Connection to inter101 closed. [gobbert@taki-usr1 ~]$ exit exit salloc: Relinquishing job allocation 32397 [gobbert@taki-usr1 ~]$
Running MATLAB in batch mode on a cluster node
We will show an example of a MATLAB code, that produces a plot and prints it to file. This demonstrates that this it is possible to obtain a, for instance, a PNG file of the figure, even though the figure was never displayed on the screen.
The following file testplot.m defines (very short) vectors of x- and y-values, then plots them in 2-D using the
plot function in MATLAB, and finally prints the figure to the file testplot.png. This is the m-file that you want to run on a cluster node in batch mode.
As always with slurm, we need a batch script to submit the job to the scheduler. Since MATLAB requires more memory than typical, we use the ‘–mem=10G’ option which requests 10 GB of memory; this value has proven sufficient for most MATLAB jobs. It can be increased if MATLAB requires more total memory, but doing so might affect how long your jobs wait in the SLURM queue.
Note that by default, we are requesting a single core of one node for our job. This will help to yield the best throughput of MATLAB jobs on the cluster. We submit the slurm script in the usual way
[gobbert@taki-usr1 Matlab]$ sbatch run.slurm Submitted batch job 4125
After your job completes, you should see the file testplot.png that was printed by the print command in the MATLAB m-file. On taki, you can use the
display testplot.png command to display this file, if your connection to taki is graphics-enabled, or you need to copy this file to your own computer to display it there.
Also in your directory, there should also be slurm.out and slurm.err files that capture the stdout and stderr, respectively. The slurm.err file should be empty and the slurm.out file should contain the following; since this sample script did not write any output to the MATLAB window, the following does not show anything.
[gobbert@taki-usr1 Matlab]$ more slurm.out Opening log file: /home/gobbert/java.log.42140 Copyright 1984-2018 The MathWorks, Inc. R2020b (220.127.116.117703) 64-bit (glnxa64) August 26, 2020 To get started, type doc. For product information, visit www.mathworks.com.
You are also able to use any of the usual non-graphical MATLAB functionality, of course.