Parallel Toolbox (spmd)¶
The MATLAB Parallel Computing Toolbox (PCT) extends the MATLAB language with high-level parallel-processing features such as parallel for loops, parallel regions, message passing, distributed arrays, and parallel numerical methods.
It offers a shared-memory computing environment with a maximum number of MATLAB workers running on the local configuration in addition to your MATLAB client. MATLAB Distributed Computing Server (DCS) can scale PCT applications up to the limit of your DCS licenses.
This example shows how to submit a small parallel MATLAB program with a parallel region, using an spmd statement, as a MATLAB pool job to a batch queue.
This method uses the job submission command to submit a MATLAB client to compute nodes. The MATLAB client interprets a MATLAB .m file with a user-defined cluster profile, which scatters the MATLAB workers onto different compute nodes.
This method uses the MATLAB interpreter, the Parallel Computing Toolbox, and the Distributed Computing Server. It requires and checks out six licenses:
- one MATLAB license for the client running on the compute node
- one Parallel Computing Toolbox license
- four Distributed Computing Server licenses
Four DCS licenses run the four copies of the spmd statement. This job is completely off the front end.
MATLAB spmd Script¶
Prepare a MATLAB script called myscript.m:
SLURM Job Submission File¶
Prepare a job submission file with an appropriate filename. In this example, the file is named myjob.sub.
Run with the name of the script:
Set the Default Parallel Configuration¶
Run MATLAB to set the default parallel configuration to your job configuration:
Then, inside MATLAB:
Submit the Job¶
Submit the job using sbatch.
Once this job starts, a second job submission is made by MATLAB through the configured SLURM cluster profile.
Example Output¶
The output may look similar to this:
The output shows that one compute node, gilbreth-a001, processed the job submission file myjob.sub and the two serial regions.
The job submission scattered four processor cores, or four MATLAB labs, among four different compute nodes:
gilbreth-a001gilbreth-a002gilbreth-a003gilbreth-a004
These nodes processed the four parallel regions. The total elapsed time demonstrates that the jobs ran in parallel.