Parallel Computing Hands-on Workshop
Overview
This hands-on workshop is meant to make you familiar with Parallel Computing Toolbox constructs and some of the common patterns you'll encounter.
The examples are ordered based on construct from simple to advanced. It is not expected that you will complete all of the examples as some are for very specialized use-cases.
Instructions
- Make sure that you are either viewing this as a Live Script (Requires R2016a or newer) or open the html file with the MATLAB web command: web('WorkshopNavigation.html');
- Use the hyperlinks in this document to open the examples.
- Many of the examples use Code Sections. You can evaluate one section at a time using the Run Section button in the toolstrip.
Example 1 - PARPOOL
Level: Introductory
The purpose of this example is to introduce you to parallel pools.
Example 2 - PARFOR Pause
Level: Introductory
The purpose of this example is to introduce you to parfor loops.
Example 3 - PARFOR Quick Success
Level: Introductory
The purpose of this example is to have you convert a for loop into a parfor loop, time the difference, and compare the results.
Example 4 - PARFOR Iteration Independence
Level: Introductory
The purpose is to demonstrate that parfor iterations must be independent.
Example 5 - PARFOR Iteration Order
Level: Introductory
The purpose is to demonstrate that parfor iterations do not run in a fixed or deterministic order.
Example 6 - PARFOR Loop Variable
Level: Introductory
The purpose is to introduce you to the requirements of parfor loop variables.
Example 7 - PARFOR Nested
Level: Moderate
The purpose is to show that parfor loops cannot be directly nested inside of each other. It is okay if a function with a parfor loop is called from within a parfor loop.
Example 8 - PARFOR Load & Save
Level: Moderate
The purpose is to show you how to load and save data from within MATLAB.
Example 9 - PARFOR Struct & Cell
Level: Moderate
The purpose is to show how cells are better than structs in parfor loops.
Example 10 - PARFOR Parameter Sweep
Level: Advanced, Practical Example
The purpose is show a practical example of a parameter sweep study using a parfor loop.
Example 11 - Batch Interactive
Level: Introductory
The purpose is show how to quickly submit a script as a batch job.
Example 12 - Batch Interactive
Level: Introductory
The purpose is submit both a serial and parallel function as batch jobs.
Example 13 - Batch Parameter Sweep
Level: Introductory, Practical Example
The purpose is submit more realistic serial and parallel functions as batch jobs and to investigate more of the batch job settings.
Example 14 - Tall Intro
Level: Introductory
Requires R2016b or newer.
The purpose is to introduce you to tall arrays for dealing with big data.
Example 15 - GPU Intro
Level: Introductory
Requires an NVidia GPU with Compute Capability 2.0 or greater.
The purpose is to introduce you to GPU computing in MATLAB.
Example 16 - Distributed Intro
Level: Introductory
The purpose is to introduce you to distributed arrays. Distributed arrays are useful when you need to do array or linear algebra on data that is too big to fit into the memory of one machine.
Example 17 - Parfeval Order
Level: Advanced
The purpose is to introduce parfeval and a case where it might be considered over parfor.
Example 18 - Parfeval Break
Level: Advanced
This example shows how to solve needle in the haystack type problems with parfeval. I.e. problems where you can break out of a loop after some criteria are met.
- Take the for loop in for_break and convert it to a parfor loop. You'll see that this is not allowed.
- Now look at parfeval_break. It allows you to stop and cancel the remaining iterations.
Example 19 - SPMD Intro
Level: Moderate
The purpose is to introduce you to spmd, "Single Program Multiple Data".
Example 20 - SPMD Labindex
Level: Advanced
The purpose is to introduce you to controlling what happens on each worker during spmd.
Example 21 - SPMD Distributed
Level: Advanced
The purpose is to introduce you to building codistributed arrays inside of spmd.
Example 22 - SPMD Message Passing Interface
Level: Advanced
The purpose is to introduce you to using the message passing interface library (MPI) via spmd.
Example 23 - SPMD Distributed
Level: Advanced
The purpose is to introduce you to scheduling jobs and tasks using the low level interface. This would be used when batch is not sufficient.
Example 24 - PARFOR Simulink
Level: Moderate, Practical Example
This example requires Simulink.
The purpose is to show how you can parallelize calls to Simulink for this example with a parameter sweep.
Example 25 - GPU CUDA
Level: Advanced
Requires an NVidia GPU with Compute Capability 2.0 or greater.
The purpose is to show how you can incorporate CUDA code in MATLAB and run it against a gpuArray.
Copyright 2017, The MathWorks Inc.