MATLAB

MATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numeric computation. More information can be found at: http://www.mathworks.com/

Imbox_content

Note that as of MATLAB R2024a MathWorks has added a Service Manager to MATLAB startup that adversely affects startup time on the cluster. To keep that from happening, on the HPC3 please run matlab_fixes.sh from anywhere on the HPC3

MATLAB on the HPC3

Interactive MATLAB Sessions

  • Graphical on the FastX HPC3 Desktop:
qlogin -pe openmp 2
matlab -desktop
  • Textual:
qlogin -pe openmp 2
matlab -nodesktop

Submitting a MATLAB Job

Create MATLAB Commands File

Create a .m file with your commands, for example:

for i=1:1024
    A(i) = sin(i*2*pi/1024);
end

disp(A)

Create MATLAB Job Script

Create a .sh file with at least the following contents:

#!/bin/bash

matlab -nodisplay -nodesktop -nosplash < your-commands-file-1.m

or if your MATLAB command file calls functions in separate function files:

#!/bin/bash

matlab -nodisplay -nodesktop -nosplash < your-commands-file-1.m your-func-1.m your-func-2.m

Submit MATLAB Job

More information: HPC3 Job Management

Parallel MATLAB on the HPC3

Remember HPC3 Job Management with job limits for job queues.
  • Required to use parpool() only with an MPI cluster, run (on the command line, not in MATLAB): setup-parMatlab (this sets up your parallel environment in MATLAB). You only need to do this one time. After that, all MATLAB sessions will be ‘ready for parallel’.
  • To open a normal parallel MATLAB session, in your MATLAB, use the myPoolStart() function:

Usage of myPoolStart.m Function

The myPoolStart() function is in the /usr/local/demo/Matlab/parallel folder on all HPC3 systems. You can use the other files in that directory to build your own job scripts.

With MPI (multi-server) Workers

Start a master (could be MATLAB graphical or not):

qlogin -pe openmp 2 -l m_mem_free=2G

Start MATLAB and run the function:

# if you need > 2G RAM / worker:
export MATLAB_WORKER_RAM=3G
matlab -nodisplay
> addpath /usr/local/demo/Matlab/parallel
> myPoolStart("Wharton_HPC3_Matlab_R2023a", 16)
... do your parallel work!
> poolobj = gcp('nocreate'); 
> delete(poolobj)

With SMP (local) Workers

If you only need 8 or less workers (would be running on 4 cores, max), you should instead use the function like:

qlogin -pe openmp 4 -l m_mem_free=3G
matlab -nodisplay
> addpath /usr/local/demo/Matlab/parallel
> myPoolStart("Processes", 8)
... do your work!
> poolobj = gcp('nocreate');
> delete(poolobj)

“Processes” starts a lot faster. NOTE that RAM is per core, so the above example would request and require 12GB of RAM.

That function can be used in a job script as well.

MATLAB on my Laptop and Desktop

Wharton Site License!

Wharton subscribes to a site license for all Faculty, Staff, and Students. It expires annually on September 1st, after which you’ll need to re-authorize, and includes Base MATLAB, and a host of many excellent toolboxes.

To set up your Mathworks account and install MATLAB, please follow the directions HERE.