Top Banner
1 © 2016 The MathWorks, Inc. Distributed Computing with MATLAB Mandar Gujrathi Applications Engineer, MathWorks. [email protected]
27

Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

Aug 23, 2018

Download

Documents

NguyễnHạnh
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: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

1© 2016 The MathWorks, Inc.

Distributed Computing with MATLAB

Mandar Gujrathi

Applications Engineer,

MathWorks.

[email protected]

Page 2: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

2

Agenda

Methods to improve productivity

Why Distributed Computing

Methods to distribute the computations

Using remote resources distribute computations

Page 3: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

3

Improving Productivity

Page 4: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

4

How can we speed up?

Distributing Jobs.

Computing Jobs.

Why ?

Page 5: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

5

Why Distributed Computing ?

Reduce computation time by

– Using more cores

– Accessing Graphical Processing

Units

Solve large data problems by

distributing data to available

hardware

Offload applications to a cluster

Parallel Computing Toolbox

MATLAB Distributed Computing Server

Cloud / Cluster

Page 6: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

6

Some terminologies

Job ?

– Large Operation to be performed in MATLAB session

Task ?

– A job is divided into several tasks. A task could be independent or dependent.

Client ?

– Your computer, which has MATLAB, PCT & toolboxes.

Worker ?

– Additional Instance of MATLAB.

Worker could be on your machine* or on remote machine

Cluster ?

– Machines configured (where MDCS is installed) to run Jobs

*To start multiple workers on your machine (LOCAL) you need PCT only.

Page 7: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

7

What are the Components?

There are two separately licensed components of MATLAB Distributing

Computing:

– Parallel Computing Toolbox (PCT):

Unlimited local workers (R2014a and higher)

Required for MDCS – sends jobs to the scheduler

– MATLAB Distributed Computing Server (MDCS):

Allows you to utilize a large number of machines or one machine with a large number of cores

Allows you to send jobs to other machines

Page 8: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

8

Distributed Computing - PCT

As of MATLAB Parallel Computing allows “local scheduling” of jobs,

i.e., making use of multi-core functionalities of the hardware.

Speed up jobs by dividing them among local cores

Each additional task spawns an extra worker

PCT doesn’t require any configuration of schedulers

Parallel

Computing

ToolboxToolboxes

Blocksets

Page 9: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

9

Ways to speed up (PCT) : parfor pRunBirthday.m

Loop Variable MUST be an INTEGER

The loop variable MUST be consecutive &

increasing

The loop iterations MUST be independent

Nested parfor WILL NOT work.

You could call a function using parfor

within a parfor

All for loops CANNOT be converted to

parfor

Page 10: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

10

Distributed Computing – MDCS

– If the local scheduler is not enough, a user can submit to a computing cluster that is running MDCS

– Jobs that are submitted to the scheduler are distributed among workers

– Licensing and physical resources define how many workers a cluster may have

– PCT must be installed on the client’s MATLAB

– MDCS will be generally installed on a cluster of powerful machines

Page 11: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

11

Simulink, Blocksets,

and Other Toolboxes

Local

Desktop Computer

MATLAB

……

MATLAB Distributed Computing Workflow

Profile

(Local)

1. Prototype code

Page 12: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

12

Cluster

Scheduler

Computer Cluster

… … …

MATLAB Distributed Computing Workflow

Profile

(Cluster)

1. Prototype code

2. Get access to an enabled

cluster

Page 13: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

13

Simulink, Blocksets,

and Other Toolboxes

Local

Desktop Computer

MATLAB

……

MATLAB Distributed Computing Server Workflow

1. Prototype code

2. Get access to an enabled

cluster

3. Switch cluster profile and

run on cluster resources

Cluster

Scheduler

Computer Cluster

… … …

Profile

(Local)Profile

(Cluster)

Page 14: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

14

How to distribute jobs

There are two methods of distributing jobs:

– Using the multi core functionalities of your machine (PCT)

– Get access to the resources of a remote machine/s.

(PCT+MDCS)

Page 15: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

15

Some more terminologies

Distributed job?

– Multiple tasks running independently on multiple workers with no information passed among them.

Distributed Array?

– Splitting large dataset among several MATLAB workers.

Communicating Job?

– Task running concurrently on multiple workers that may communicate with each other.

Page 16: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

16

Agenda

Methods of improving performance

Why Distributed Computing

Methods to distribute the computations locally

Using remote resources distribute computations

Page 17: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

17

Methods of Distributed Computing

Using Parallel For Loops (parfor)

Create an Independent Job

Create a Communicating Job

Create a Batch Job

Distribute the data between sessions.

Page 18: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

18

Independent and Communicating Jobs Workflow

Independent Job Communicating Job

Workers perform tasks without communication.

Ability to choose workers.>>createJob

Communication between the workers happen while

running the job>>createCommunicatingJob

User defines independent tasks within the job. >>createTask

User defines communicating task within the job

(SPMD)>>createTask

Tasks are distributed to workers as their availability>>submit

Tasks run simultaneously. Job may be delayed as

workers become available.>>submit

Get the results from the workers. >>load (Scripts)

>>fetchOutputs (Functions)

Get results from workers>>load (Scripts)

>>fetchOutputs (Functions)

Example: birthdayjobs.m Worker communications:>>labSend

>>labReceive

>>labSendReceive

Page 19: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

19

Batch Job >>batch birthdayBatchWithFile.m

Useful to offload work from MATLAB session to another session (cluster)

Job runs in the background without blocking the input.

Allows to submit job, close current session and return later

Allows to attach files, provide additional paths, etc.

Page 20: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

20

Overcoming Memory LimitationsDistribute Memory

A = rand(5e5,2);A = distributed.rand(5e5,2);

MATLAB functions on distributed and codistributed arrays (doc)

MATLAB

Desktop (Client)

1 …

… …

… … … …

1 …

… …

… …

… 1e6

… …

… …

… …

Page 21: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

21

Example: Overcoming Memory Limitations

Page 22: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

22

Agenda

Methods of improving performance

Why Distributed Computing

Methods to distribute the computations locally

Using remote resources distribute computations

Page 23: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

23

Scaling your parallel applications to the cloud

MATLAB +

Parallel Computing Toolbox

MDCS on Amazon EC2

MDCS on Private Cloud

Benefit:

Easy replication and anywhere access.

Page 24: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

25

MATLAB on Amazon EC2

Requires Amazon Web Services account

Supports both MATLAB and MDCS

MathWorks’ Cloud Center web application allows you to

customize MDCS cluster size, machine type, and storage

options.

Page 25: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

26

MDCS on Private Cloud

Private cloud, other cloud services, on premise and ad-hoc

clusters, and grids.

MDCS can be integrated with a variety of cluster schedulers.

Preinstalled options:

– Amazon EC2

– Penguin Computing

MHLM provides added convenience with cloud-based

licensing.

Limited support for custom cloud. Recommend using pre-

installed options.

Page 26: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

27

MathWorks Hosting Providers in Australia

Licensed for BYOL

Pre-installed with MATLAB and MDCS

Australia:

– NCI (Active)

– QCIF (Active)

Page 27: Distributed Computing with MATLAB - MathWorks · 5 Why Distributed Computing ? Reduce computation time by –Using more cores –Accessing Graphical Processing Units Solve large data

28

Summary

For computationally expensive operations,

– Parallel Computing Toolbox (PCT)

– MATLAB Distributed Computing Server (MDCS)

PCT allows distributing the computations locally on your machine

MDCS along with PCT allows distributing the computations to a remote

machine or a cloud.

Resources: Distributed Computing, Training