Parallel MATLAB: profile setup and batch submission¶
Setting up the cluster profile¶
In order to submit a batch script that takes advantage of MATLAB Parallel Server you first need to set up a cluster profile. Thankfully this has already been done and all you need to do as a user is import the profile and that only needs to be done once. If you would like to do this interactively you can start an interactive session with the following:
Once you have a node allocated to you load the MATLAB module and start a MATLAB session:wheeler001:~$ module load matlab
wheeler001:~$ matlab
To get started, type doc.
For product information, visit www.mathworks.com.
>>
>> poolobj = parpool(profile, 16)
>> tic
>> n = 200
>> A = 500
>> a = zeros(1,n)
>> parfor i = 1:n
>> a(i) = max(abs(eig(rand(A))))
>> end % You may need to hit enter more than once to get the prompt back.
>> toc
>> delete(poolobj);
parallel_matlab.m that will import our cluster profile and compare the time of computation for a sequential for loop and a parallel for loop with 16 cores ('workers' in MATLAB speak):
profile = parallel.importProfile('/opt/local/MATLAB/<cluster>-normal.settings')
poolobj = parpool(profile, 16);
tic
n = 200;
A = 500;
a = zeros(1,n);
for i=1:n;
a(i) = max(abs(eig(rand(A))))
end
toc
tic
n = 200;
A = 500;
a = zeros(1,n);
parfor i=1:n;
a(i) = max(abs(eig(rand(A))))
end
toc
delete(poolobj);
parallel_matlab.pbs to submit your sample MATLAB program:
#!/bin/bash
#PBS -N parallel_matlab
#PBS -l walltime=01:00:00
#PBS -l nodes=1:ppn=8
#PBS -j oe
cd #PBS_O_WORKDIR
module load matlab/R2019a
matlab -r -nodisplay parallel_matlab > parallel_matlab.out
qsub parallel_matlab.pbs and hopefully all goes swimmingly. If you require assistance with MATLAB parallel computing please send an email to help@carc.unm.edu.
Migrated from UNM-CARC QuickBytes (last source update 2022-05-11). Spotted a problem? Open an issue or pull request.