You can run MATLAB locally within the UAHPC cluster, and this may be the best option if you are running batch processes or working with a large dataset stored on UAHPC. It is also possible to run MATLAB on your workstation and configure it to run remote computations on UAHPC, copying data back and forth and submitting SLURM jobs on your behalf.

Local usage

Choosing a version

The current MATLAB license is now R2020b. As new versions get loaded, this will get changed to point to the newest one. To get access to the software, type

  • module load math/matlab

The simplest job uses a single thread to run the Matlab code. In that case you specify -n 1 in your allocation and start Matlab with the -singleCompThread option.

There are two ways to run Matlab that take advantage of the cluster resources.

With the first technique the setup works with jobs that use certain algebraic functions that can do multi-threading. In that case you should control how many threads can be created with maxNumCompThreads. Then the node can be allocated with -n 1 and -c (# of threads you have specified in maxNumCompThreads). See Matlab documentation for more information on whether your code can take advantage of this.

In the second technique one would use the parallel toolkit. In that case you would define workers with “parpool” and employ the “parfor” command to run multiple iterations of a loop all at once. For these jobs you would specify -N 1 and -n (# of parallel loops configured).

In either case your code needs to be modified to handle your type of computation. In no case can the matlab job run across more than one node at a time. See the Matlab documentation on how to run your code with “parfor.” Limited tests should be done to make sure you have the correct setup. We do not allow MATLAB to be run directly on the master node ( Short tests should be submitted via the debug queue.

Sample Matlab sbatch file

#SBATCH -J my_job_name # job name 
#SBATCH -n 1       # number of tasks to use (should be 1)
#SBATCH -p main
#SBATCH --qos main
#SBATCH --mem-per-cpu=5G
#SBATCH -e errors.%A
#SBATCH -o output.%A
#SBATCH --mail-user={your email address}

matlab  -nodesktop -nosplash –nojvm –singleCompThread < myprog.m

Remote usage

Using the Parallel Computing Toolkit in MATLAB on your workstation, it is possible to configure it to connect to UAHPC and submit SLURM jobs when you create a parpool. This currently works only from on campus, and may not work over the UA VPN due to the need for MATLAB worker processes on UAHPC compute nodes to open a connection back to the workstation.

  • Versions must match (currently R2020b) on the workstation and the cluster.
  • If prompted, allow MATLAB on your workstation to accept incoming connections.
  • Go to Add-Ons / Get Add-Ons and search for Slurm. You will need to install the “Parallel Computing Toolbox plugin for MATLAB Parallel Server with Slurm”.
  • Go to Parallel / Create and Manage Clusters… and add a cluster profile of the Generic type.
  • Right-click and rename the profile to UAHPC.
  • Click Edit to set the following settings on the profile:
    • Description: UAHPC
    • NumWorkers: 32
    • ClusterMatlabRoot: /share/apps/matlab/R2020b
    • RequiresOnlineLicensing: false
    • OperatingSystem: unix
    • HasSharedFilesystem: false
    • IntegrationScriptsLocation: Under Windows, use C:\ProgramData\MATLAB\SupportPackages\R2020b\parallel\slurm\nonshared and for MacOS, use /Users/username/Documents/MATLAB/SupportPackages/R2020b/parallel/slurm/nonshared
    • AdditionalProperties: add each of the following (shown as Name || Value || Type):
      • AdditionalSubmitArgs || -p main -q main --mem-per-cpu=6G || String
      • ClusterHost || || String
      • RemoteJobStorageLocation || /scratch || String
      • UseUniqueSubfolders || true || Logical
  • Click Done and go to the Validation tab.
  • Click Validate to check whether the profile works. This may take a while, and it may fail with an error message either in the validation report, or on your MATLAB console. If you need to ask for help at this stage, please collect the error message if possible.

Common problems

  • When you start MATLAB, it detects the local hostname of your workstation (e.g., DESKTOP-SVC74G1 or someones-mac.local) and passes that information to the worker processes. Unfortunately these aren’t usually valid hostnames in DNS, so this isn’t going to work for most people.What you’ll need to do is call pctconfig to set the hostname used by MATLAB, after you start MATLAB but before you call any other functions from the Parallel Computing Toolkit. It can’t be set more than once in a given MATLAB session, and it can’t be changed after you’ve tried to start a parpool or called any other PCT functions. We recommend setting the PCT hostname to your IP address. While connected to the UA VPN, it would have to be set to your VPN client IP address.For example, if “ipconfig” on your laptop says your IP is, then right after starting MATLAB, you would enter:

    pctconfig('hostname', '')

    That should be the literal string 'hostname', not the name of your machine. See help pctconfig for more info.

  • This is unlikely to work from off campus or over the UA VPN. It is suitable for workstations on campus that remain in one place, not changing IP addresses or disconnecting from the network during the computation.
  • When MATLAB is upgraded on UAHPC, we will keep the old version around for a while, but eventually everyone with a cluster profile that has ClusterMatlabRoot set to the path of the old version will have to upgrade and edit their profile to use the new version in order to keep working.
  • Jobs can sometimes fail due to insufficient memory. If that happens, you’ll need to edit the cluster profile and increase the --mem-per-cpu option under AdditionalSubmitArgs.