Top Banner
1 © 2011 The MathWorks, Inc. Parallel Computing with MATLAB Jiro Doke, Ph.D. Senior Application Engineer Sarah Wait Zaranek, Ph.D. MATLAB Product Marketing
37

Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

Mar 06, 2018

Download

Documents

votruc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

1 © 2011 The MathWorks, Inc.

Parallel Computing with MATLAB

Jiro Doke, Ph.D.

Senior Application Engineer

Sarah Wait Zaranek, Ph.D.

MATLAB Product Marketing

Page 2: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

2

A Question to Consider

Do you want to speed up your

algorithms or deal with large data?

If so…

– Do you have a multi-core or

multi-processor computer?

– Do you have a high-end

graphics processing unit (GPU)?

– Do you have access to a computer

cluster?

Page 3: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

3

Utilizing Additional Processing Power

Built-in multithreading (implicit)

– Core MATLAB and Image Processing Toolbox

– Utility for specific matrix operations (linear algebra, fft, filter, etc)

– No necessary code change

Parallel computing tools (explicit)

– Parallel Computing Toolbox

– MATLAB Distributed Computing Server

– Broad utility controlled by the MATLAB user

Page 4: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

4

Introduction to Parallel Computing Tools

Using Multi-core/Multi-processor Machines

Using Graphics Processing Units (GPUs)

Scaling Up to a Cluster

Agenda

Page 5: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

5

Worker Worker

Worker

Worker

Worker Worker

Worker

Worker TOOLBOXES

BLOCKSETS

Going Beyond Serial MATLAB Applications

Page 6: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

6

Parallel Computing on the Desktop

Use Parallel Computing Toolbox

Speed up parallel applications

on local computer

Take full advantage of desktop

power by using CPUs and GPUs

(up to 12 workers in R2011b)

Separate computer cluster

not required

Desktop Computer

Parallel Computing Toolbox

Page 7: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

7

Scale Up to Clusters, Grids and Clouds

Desktop Computer

Parallel Computing Toolbox

Computer Cluster

MATLAB Distributed Computing Server

Scheduler

Page 8: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

8

Parallel Computing enables you to …

Larger Compute Pool Larger Memory Pool

11 26 41

12 27 42

13 28 43

14 29 44

15 30 45

16 31 46

17 32 47

17 33 48

19 34 49

20 35 50

21 36 51

22 37 52

Speed up Computations Work with Large Data

Page 9: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

9

Introduction to Parallel Computing Tools

Using Multi-core/Multi-processor Machines

Using Graphics Processing Units (GPUs)

Scaling Up to a Cluster

Agenda

Page 10: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

10

Programming Parallel Applications

Ea

se

of

Us

e

Gre

ate

r Co

ntro

l

Page 11: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

11

Using Additional Cores/Processors (CPUs)

Support built into Toolboxes

Ea

se

of

Us

e

Gre

ate

r Co

ntro

l

Page 12: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

12

Example: Built-in Support for Parallelism in Other Tools

Use built-in support for

Parallel Computing Toolbox

in Optimization Toolbox

Run optimization in parallel

Use pool of MATLAB workers

Page 14: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

15

Using Additional Cores/Processors (CPUs)

Support built into Toolboxes

Simple programming constructs:

parfor

Ea

se

of

Us

e

Gre

ate

r Co

ntro

l

Page 15: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

16

Running Independent Tasks or Iterations

Ideal problem for parallel computing

No dependencies or communications between tasks

Examples include parameter sweeps and Monte Carlo

simulations

Time Time

Page 16: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

17

Example: Parameter Sweep of ODEs

Damped spring oscillator

Sweep through different

values of b and k

Record peak value for each

simulation

0,...2,1,...2,1

5

xkxbxm

Parameter sweep of ODE

system

Use pool of MATLAB workers

Convert for to parfor

Interleave serial and

parallel code

Page 17: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

19

Tips for using parfor

Requirement: Task and order independence

Classification of Variables

– One of the most common type of problems people run into

when working with PARFOR.

– At runtime, MATLAB needs determine how each variable would

get treated.

– Documentation: Parallel Computing Toolbox User’s Guide

Parallel for-Loops Advanced Topics

http://blogs.mathworks.com/loren/2009/10/02/using-

parfor-loops-getting-up-and-running/

Page 18: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

20

Using Additional Cores/Processors (CPUs)

Support built into Toolboxes

Simple programming constructs:

parfor

Full control of parallelization:

jobs and tasks

Ea

se

of

Us

e

Gre

ate

r Co

ntro

l

Page 19: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

21

Introduction to Parallel Computing Tools

Using Multi-core/Multi-processor Machines

Using Graphics Processing Units (GPUs)

Scaling Up to a Cluster

Agenda

Page 20: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

22

Core 1

Core 3 Core 4

Core 2

Cache

Gaining Performance with More Hardware

Using More Cores (CPUs) Using GPUs

Device Memory

Page 21: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

23

What is a Graphics Processing Unit (GPU)

Originally for graphics acceleration, now

also used for scientific calculations

Massively parallel array of integer and

floating point processors

– Typically hundreds of processors per card

– GPU cores complement CPU cores

Dedicated high-speed memory

* Parallel Computing Toolbox requires NVIDIA GPUs with Compute Capability 1.3 or

greater, including NVIDIA Tesla 10-series and 20-series products. See

http://www.nvidia.com/object/cuda_gpus.html for a complete listing

Page 22: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

24

Example: GPU Computing in the Parallel Computing Toolbox

Solve 2nd order wave

equation:

𝜕2𝑢

𝜕𝑡2=𝜕2𝑢

𝜕𝑥2+𝜕2𝑢

𝜕𝑦2

Send and create data on

the GPU

Run calculations with

built-in GPU functions

Page 23: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

25

Benchmark: Solving 2D Wave Equation CPU vs GPU

Page 24: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

26

Summary of Options for Targeting GPUs

Use GPU array interface with

MATLAB built-in functions

Execute custom functions on

elements of the GPU array

Create kernels from existing CUDA

code and PTX files

Ea

se

of

Us

e

Gre

ate

r Co

ntro

l

Webinar: “GPU Computing with MATLAB”

http://www.mathworks.com/company/events/webinars/wbnr59816.html

Page 25: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

27

Introduction to Parallel Computing Tools

Using Multi-core/Multi-processor Machines

Using Graphics Processing Units (GPUs)

Scaling Up to a Cluster

Agenda

Page 26: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

28

Setting Up Cluster Computing

(for System Admins)

Desktop Computer

Parallel Computing Toolbox

Computer Cluster

MATLAB Distributed Computing Server

Scheduler

MATLAB Distributed Computing Server

• All-product install

• Worker license per process

• License by packs: 8, 16, 32, 64, etc.

• No additional toolbox licenses needed

Page 27: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

29

Why scale up to a cluster?

Solve larger, computationally-intensive problems with

more processing power

Solve memory-intensive problems

Schedule computations to offload from your local

machine

Page 28: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

30

Scheduling Work (batch)

TOOLBOXES

BLOCKSETS

Scheduler

Work

Result

Worker

Worker

Worker

Worker

Page 29: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

31

Scheduling Work (batch)

TOOLBOXES

BLOCKSETS

Scheduler

Worker

Worker

Worker

Worker

Computer Cluster

Local Machine

Page 30: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

32

Scheduling Work (batch)

TOOLBOXES

BLOCKSETS

Scheduler

Worker

Worker

Worker

Worker

Local Machine

Page 31: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

33

Scheduling Work (batch)

TOOLBOXES

BLOCKSETS

Scheduler

Worker

Worker

Worker

Worker

Computer Cluster

Page 32: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

34

Scheduling Work (batch)

TOOLBOXES

BLOCKSETS

Scheduler

Worker

Worker

Worker

Worker

Computer Cluster

Local

Machine

Local Machine

Remote

Desktop

Page 33: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

35

Example: Scheduled Processing

Damped spring oscillator

Sweep through different

values of b and k

Record peak value for each

simulation

0,...2,1,...2,1

5

xkxbxm

Offload processing to workers

(local or cluster)

Regain control of MATLAB

after offloading

Monitor progress of scheduled

job

Retrieve results from job

Page 34: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

36

Distributed Array

Lives on the Workers

Remotely Manipulate Array

from Client MATLAB

11 26 41

12 27 42

13 28 43

14 29 44

15 30 45

16 31 46

17 32 47

17 33 48

19 34 49

20 35 50

21 36 51

22 37 52

Distributing Large Data

TOOLBOXES

BLOCKSETS

Page 35: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

37

Client-side Distributed Arrays and SPMD

Client-side distributed arrays

– Class distributed

– Can be created and manipulated directly from the client.

– Simpler access to memory on labs

– 100s of built-in functions that operate on distributed arrays,

including client-side visualization functions

spmd

– Block of code executed on workers

– Worker specific commands

– Explicit communication between workers using MPI

– Mixture of parallel and serial code

Page 36: Parallel Computing with MATLAB - Massachusetts …web.mit.edu/8.13/matlab/MatlabTraining_IAP_2012/Parallel_Computing/... · Parallel Computing with MATLAB Jiro Doke, ... Parallel

38

Summary

Speed up parallel applications on desktop by using

Parallel Computing Toolbox

Take full advantage of CPU and GPU hardware

Use MATLAB Distributed Computing Server to

– Scale up to clusters, grids and clouds

– Work with data that is too large to fit on to desktop computers