parallel computing with matlab and · pdf fileparallel computing with matlab ... load data...

22
© 2008 The MathWorks, Inc. ® ® Parallel Computing with MATLAB ® and Simulink ® Dr. Frank M. Graeber Application Engineering Group The MathWorks GmbH

Upload: lexuyen

Post on 06-Feb-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

©20

08 T

he M

athW

orks

, Inc

.

® ®

Parallel Computing with MATLAB ® and Simulink ®

Dr. Frank M. GraeberApplication Engineering Group

The MathWorks GmbH

Page 2: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

2

® ®

Solving Large Technical Problems

Large data set

Difficulties

Long running

Computationally intensive

Wait

Load data onto multiple machines that work together in parallel

Solutions

Run similar tasks on independent processors in parallel

Reduce sizeof problem

You could…

Page 3: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

3

® ®

Development of Parallel Code

Challenges Solution

Work interactivelyin parallel

Jobs often run in scheduled mode

Hard to debug

Cannot access intermediate answers

Hard to diagnose bottlenecks in algorithm

Page 4: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

4

® ®

Using Fortran and MPI Using MATLAB and MPIUsing Distributed Arrays

P>> D = distributed(A)P>> E = D’

Easier Parallel Programming

Example: Transposing a Distributed Matrix

4

4

Page 5: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

5

® ®

� Toolbox Support:- Optimization Toolbox™- Genetic Algorithm and Direct Search Toolbox™- SystemTest™

� Parallel for-loops� Distributed arrays

� Scheduling jobs and tasks

� MATLAB with Message Passing

Parallel Computing with MATLAB

No code changes

Trivial changes

Extensive changes

Page 6: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

6

® ®

Task Parallel for Distributing Tasks

Time Time

Pro

cess

es /

Tas

ks

Page 7: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

7

® ®

Demo: Monte Carlo Simulation of Coin Tossing

11

Number of Heads Out of 207 12 15 7 9 9 7 8 1211

10 Simulations of Flipping 20 Coins at a Time

Page 8: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

8

® ®

Parallel for -Loops

parfor i = 1 : n

% do something with i

end

� Mix task-parallel and serial code in the same function� Run loops on a pool of MATLAB resources� Iterations must be order-independent� M-Lint analysis helps in converting existing for -loops into

to parfor -loops

Page 9: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

9

® ®

Distributing Jobs with SystemTest

Page 10: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

10

® ®

Data Parallel for Handling Large Data Sets

1111 2626 4141

1212 2727 4242

1313 2828 4343

1414 2929 4444

1515 3030 4545

1616 3131 4646

1717 3232 4747

1717 3333 4848

1919 3434 4949

2020 3535 5050

2121 3636 5151

2222 3737 5252

1111 2626 4141

1212 2727 4242

1313 2828 4343

1414 2929 4444

1515 3030 4545

1616 3131 4646

1717 3232 4747

1717 3333 4848

1919 3434 4949

2020 3535 5050

2121 3636 5151

2222 3737 5252

Page 11: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

11

® ®

Demo: Conjugate Gradient Benchmark

Page 12: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

12

® ®

Distributed Arrays and Parallel Algorithms

� Distributed arrays� Store segments of data across participating workers� Create from any built-in class in MATLAB

� Examples: doubles, sparse, logicals, cell arrays, and arrays of structs

� Parallel algorithms for distributed arrays� Matrix manipulation operations

� Examples: indexing, data type conversion, and transpose

� Parallel linear algebra functions, such as svd and lu

� Data distribution� Automatic, specify your own, or change at any time

Page 13: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

13

® ®

>150 Enhanced MATLAB Functions That Operate on Distributed Arrays

Page 14: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

14

® ®

MPI-Based Functions in Parallel Computing Toolbox™Use when a high degree of control over parallel algorithm is required

� High-level abstractions of MPI functions� labSendReceive , labBroadcast , and others

� Send, receive, and broadcast any data type in MATLAB

� Automatic bookkeeping� Setup: communication, ranks, etc.� Error detection: deadlocks and miscommunications

� Pluggable � Use any MPI implementation that is binary-compatible with MPICH2

Page 15: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

15

® ®

Options for Scheduling Jobs

Task Parallel Data Parallel

>> createParallelJob

>> createMatlabPoolJobor>> batch

>> createJob(…) >> createTask(…)

Page 16: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

16

® ®

Parallel Computing with MATLAB

TOOLBOXES

BLOCKSETS

Pool of MATLAB Workers

Page 17: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

17

® ®

Run Four Local Workers with a Parallel Computing Toolbox License

� Easily experiment with explicit parallelism on multicore machines

� Rapidly develop parallel applications on local computer

� Take full advantage of desktop power

� Separate computer cluster not required

Parallel Computing

Toolbox

Page 18: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

18

® ®

Scale Up to Cluster Configuration with No Code Changes

Parallel Computing

Toolbox

Computer ClusterComputer Cluster

MATLAB Distributed Computing ServerMATLAB Distributed Computing Server

Scheduler

CPU

CPU

CPU

CPU

Worker

Worker

Worker

Worker

Page 19: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

19

® ®

Configurations

� Save environment-specific parameters for your cluster(s)

� Benefits� Enter cluster information only once� Modify configurations without changing MATLAB code� Apply multiple configurations when running within same session

Page 20: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

20

® ®

Compute ClusterCompute Cluster

CPU

CPU

CPU

CPU

MATLAB® Distributed Computing Server™MATLAB® Distributed Computing Server™

Scheduler

Third-PartyScheduler

Result

Result

Result

Result

Client MachineClient Machine

Task

Task

Task

Task

Worker

Worker

Worker

Worker

Components / Terminology

ParallelComputing

ToolboxTOOLBOXES

BLOCKSETS

Result

Job Lab

Lab

Lab

Lab

Page 21: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

21

® ®

Three User Communities

PERSONAL SUPERCOMPUTING WITH MATLAB

System Administrator

Hardware Utilization

and Optimal License

Use

Larger Data and Faster

ProcessingTechnical Computing

User

Easier Programming

HPC User

CCCC

FortranFortranFortranFortran

Page 22: Parallel Computing with MATLAB and  · PDF fileParallel Computing with MATLAB ... Load data onto ... Use when a high degree of control over parallel algorithm is required

22

® ®

Documentation on the The MathWorks Website

http://www.mathworks.com/products/parallel-computin g/