MATLAB/Parallel
MATLAB's Parallel Computing Toolbox lets you run suitably-written programs in parallel. Several cores calculate different parts of a problem at the same time to reduce the time-to-solution.
For running MATLAB in parallel, you can either use a local parpool (up to 24 cores), an LSF parpool (24+ cores) or use the MATLAB distributed computing server (MDCS), which allows to offload jobs from a local MATLAB instance running on your computer to the Euler cluster. Please find below the documentation about using a local parpool. Instructions for using an SLURM parpool as well as for using the MDCS are provided on separate wiki pages.
Use a parpool
For suitable MATLAB programs (such as those containing parfor loops), using the Parallel Computing Toolbox requires two steps:
- use a parpool in your MATLAB program and
- request multiple cores from Euler's SLURM batch scheduler.
One-time preparation: Before using the SLURM job pool for the first time, you need to import a cluster profile. For that, start MATLAB and then call configCluster . For each cluster, configCluster only needs to be called once per version of MATLAB. Please be aware that running this command more than once per version will reset your cluster profile back to default settings and erase any saved modifications to the profile.
A trivial parallel program (simulation.m) is shown below:
squares = zeros(10,1); local_job = parcluster('local'); pool = parpool(local_job, 4); parfor i = 1:10 squares(i) = i^2; end disp(squares) pool.delete()
Note that the local parpool is limited to 12 cores in releases up to R2016a (8.7/9.0). From release R2016b (9.1) on, you can use all the cores of Euler nodes (effectively 24).
Older versions of MATLAB used a matlabpool instead of a parpool. For using a local pool there is no need to load a cluster profile.
Submit a parallel job
To submit this program, pass the number of cores to the sbatch --cpus-per-task argument. This should be greater or equal to the size of the pool requested in your MATLAB script (e.g., 4).
sbatch --tasks=1 --cpus-per-task=4 --time=1:00:00 --mem-per-cpu=2g --wrap="matlab -nodisplay -singleCompThread -r simulation"
You must not use the -nojvm MATLAB argument but you should include the -singleCompThread MATLAB argument. MATLAB is quite memory-hungry, so request at least 2 GB of memory per core as shown above.
Troubleshoot parallel jobs
Using parallel pools often results in hard-to-diagnose errors. Many of these errors are related to running several pools at the same time, which is not what MATLAB expects. If you encounter persistent problems starting pools, try to perform one of these commands. Before running them, make sure that you do not have a MATLAB processes running.
- Remove the matlab_metadat.mat file in your current working directory.
- Remove the $HOME/.matlab/local_cluster_jobs directory.
- Remove the entire $HOME/.matlab directory. Warning: Your MATLAB settings on Euler will be lost.
In case this does not solve the problem, then please contact cluster support.