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

Example 1 - PARPOOL

Level: Introductory

The purpose of this example is to introduce you to parallel pools.

Open Example 1

Example 2 - PARFOR Pause

Level: Introductory

The purpose of this example is to introduce you to parfor loops.

Open Example 2

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.

Open Example 3

Example 4 - PARFOR Iteration Independence

Level: Introductory

The purpose is to demonstrate that parfor iterations must be independent.

Open Example 4

Example 5 - PARFOR Iteration Order

Level: Introductory

The purpose is to demonstrate that parfor iterations do not run in a fixed or deterministic order.

Open Example 5

Example 6 - PARFOR Loop Variable

Level: Introductory

The purpose is to introduce you to the requirements of parfor loop variables.

Open Example 6

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.

Open Example 7

Example 8 - PARFOR Load & Save

Level: Moderate

The purpose is to show you how to load and save data from within MATLAB.

Open Example 8

Example 9 - PARFOR Struct & Cell

Level: Moderate

The purpose is to show how cells are better than structs in parfor loops.

Open Example 9

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.

Open Example 10

Example 11 - Batch Interactive

Level: Introductory

The purpose is show how to quickly submit a script as a batch job.

Open Example 11

Example 12 - Batch Interactive

Level: Introductory

The purpose is submit both a serial and parallel function as batch jobs.

Open Example 12

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.

Open Example 13

Example 14 - Tall Intro

Level: Introductory

Requires R2016b or newer.

The purpose is to introduce you to tall arrays for dealing with big data.

Open Example 14

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.

Open Example 15

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.

Open Example 16

Example 17 - Parfeval Order

Level: Advanced

The purpose is to introduce parfeval and a case where it might be considered over parfor.

Open Example 17

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.

  1. Take the for loop in for_break and convert it to a parfor loop. You'll see that this is not allowed.
  2. Now look at parfeval_break. It allows you to stop and cancel the remaining iterations.

Open Example 18

Example 19 - SPMD Intro

Level: Moderate

The purpose is to introduce you to spmd, "Single Program Multiple Data".

Open Example 19

Example 20 - SPMD Labindex

Level: Advanced

The purpose is to introduce you to controlling what happens on each worker during spmd.

Open Example 20

Example 21 - SPMD Distributed

Level: Advanced

The purpose is to introduce you to building codistributed arrays inside of spmd.

Open Example 21

Example 22 - SPMD Message Passing Interface

Level: Advanced

The purpose is to introduce you to using the message passing interface library (MPI) via spmd.

Open Example 22

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.

Open Example 23

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.

Open Example 24

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.

Open Example 25

Copyright 2017, The MathWorks Inc.