Distributed MATLAB for Parallel Computing¶
- MATLAB is a multi-paradigm numerical computing environment and proprietary programming language developed by MathWorks.
- This guide will cover how to run distributed MATLAB for parallel computing.
- Review the slides from the PACE-MathWorks Parallel Computing Workshop (May 2021) for more details and training:
Configuration of MATLAB¶
- Log into a PACE cluster via a login node
- From the login node, configure MATLAB to run parallel jobs by calling the shell script configClusterWrapper.sh. This needs to be done once per version on MATLAB on each PACE cluster you use.
module load matlab/r2020b configClusterWrapper.sh
Start an interactive MATLAB session through a command line interactive job or using the MATLAB GUI via VNC. Within this session, you will have MATLAB submit a separate parallel batch job to the scheduler. Complete the following steps from within your MATLAB session.
Prior to submitting the job, we can specify various parameters to pass to our jobs, such as queue, e-mail, walltime, etc. Only
AccountName(for Phoenix or Firebird),
>> % Get a handle to the cluster >> c = parcluster; [REQUIRED] >> % Specify memory to use for MATLAB jobs, per core >> c.AdditionalProperties.MemPerCpu = '4gb'; >> % Specify a queue to use for MATLAB jobs >> c.AdditionalProperties.QueueName = 'queue-name'; >> % Specify account to use for MATLAB jobs (only required on Phoenix and Firebird) >> c.AdditionalProperties.AccountName = 'account-name'; [OPTIONAL] >> % Specify e-mail address to receive notifications about your job >> c.AdditionalProperties.EmailAddress = 'firstname.lastname@example.org'; >> % Request feature (e.g. specific GPU card) >> c.AdditionalProperties.Features = 'V100'; >> % Specify number of GPUs >> c.AdditionalProperties.GpusPerNode = 1; >> % Set the local disk size (if specified in Features) >> c.AdditionalProperties.LocalDiskSize = '100gb'; >> % Specify the walltime (e.g. 5 hours) >> c.AdditionalProperties.WallTime = '05:00:00'; Save changes after modifying AdditionalProperties for the above changes to persist between MATLAB sessions. >> c.saveProfile To see the values of the current configuration options, display AdditionalProperties. >> % To view current properties >> c.AdditionalProperties Unset a value when no longer needed. >> % Turn off email notifications >> c.AdditionalProperties.EmailAddress = ''; >> c.saveProfile
Interactive Parallel Jobs¶
- To run an interactive pool job on the cluster, continue to use parpool as you’ve done before.
>> % Get a handle to the cluster >> c = parcluster; >> % Open a pool of 64 workers on the cluster >> p = c.parpool(64); Rather than running local on the local machine, the pool can now run across multiple nodes on the cluster. >> % Run a parfor over 1000 iterations >> parfor idx = 1:1000 a(idx) = … end Once we’re done with the pool, delete it. >> % Delete the pool >> p.delete
To learn more about the MATLAB Parallel Computing Toolbox, check out these resources: