parallel computing with matlab - uvacollab€¦ · originally for graphics acceleration, now also...
TRANSCRIPT
![Page 1: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/1.jpg)
1 © 2013 The MathWorks, Inc.
Parallel Computing with MATLAB
Scott Benway
Senior Account Manager
Jiro Doke, Ph.D.
Senior Application Engineer
![Page 2: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/2.jpg)
3
Approach Options
Best coding practices Preallocation, vectorization, profiling
(“Speeding Up MATLAB Applications”)
More hardware More Processors, Cores, or GPUs
(MATLAB Parallel Computing Tools)
Integration with other
languages
C/C++, Fortran
(MEX, MATLAB Coder)
Acceleration Strategies Applied in MATLAB
![Page 3: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/3.jpg)
4
Introduction to parallel computing tools
Using multicore/multi-processor computers
Using graphics processing units (GPUs)
Scaling up to a cluster
Agenda
![Page 4: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/4.jpg)
5
Using More Hardware
Built-in multithreading
– Automatically enabled in MATLAB since R2008a
– Multiple threads in a single MATLAB computation engine
Parallel Computing using explicit techniques
– Multiple computation engines controlled by a single session
– Perform MATLAB Computations on GPUs
– High-level constructs to let you parallelize MATLAB applications
www.mathworks.com/discovery/multicore-matlab.html
![Page 5: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/5.jpg)
6
Going Beyond Serial MATLAB Applications
MATLAB
Desktop (Client)
Worker
Worker
Worker
Worker
Worker
Worker
![Page 6: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/6.jpg)
7
Parallel Computing Toolbox for the Desktop
Speed up parallel applications
Take advantage of GPUs
Prototype code for your cluster
MATLAB
Desktop (Client)
Local
Desktop Computer
![Page 7: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/7.jpg)
8
Scale Up to Clusters and Clouds
MATLAB
Desktop (Client)
Local
Desktop Computer
Cluster
Computer Cluster
Scheduler
![Page 8: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/8.jpg)
9
Introduction to parallel computing tools
Using multicore/multi-processor computers
Using graphics processing units (GPUs)
Scaling up to a cluster
Agenda
![Page 9: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/9.jpg)
10
Programming Parallel Applications (CPU)
Built-in support with Toolboxes
Ea
se
of
Us
e
Gre
ate
r Co
ntro
l
![Page 10: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/10.jpg)
11
Example: Optimizing Cell Tower Position Built-in parallel support
With Parallel Computing Toolbox
use built-in parallel algorithms in
Optimization Toolbox
Run optimization in parallel
Use pool of MATLAB workers
![Page 11: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/11.jpg)
12
Tools Providing Parallel Computing Support
Optimization Toolbox, Global Optimization Toolbox
Statistics Toolbox
Signal Processing Toolbox
Neural Network Toolbox
Image Processing Toolbox
…
BLOCKSETS
Directly leverage functions in Parallel Computing Toolbox
www.mathworks.com/builtin-parallel-support
![Page 12: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/12.jpg)
13
Programming Parallel Applications (CPU)
Built-in support with Toolboxes
Simple programming constructs:
parfor, batch, distributed
Ea
se
of
Us
e
Gre
ate
r Co
ntro
l
![Page 13: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/13.jpg)
14
Ideal problem for parallel computing
No dependencies or communications between tasks
Examples: parameter sweeps, Monte Carlo simulations
Independent Tasks or Iterations
Time Time
blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/
![Page 14: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/14.jpg)
15
Example: Parameter Sweep of ODEs Parallel for-loops
Parameter sweep of ODE system
– Damped spring oscillator
– Sweep through different values
of damping and stiffness
– Record peak value for each
simulation
Convert for to parfor
Use pool of MATLAB workers
0,...2,1,...2,1
5
xkxbxm
![Page 15: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/15.jpg)
17
Programming Parallel Applications (CPU)
Built-in support with Toolboxes
Simple programming constructs: parfor, batch, distributed
Advanced programming constructs: createJob, labSend, spmd
Ea
se
of
Us
e
Gre
ate
r Co
ntro
l
![Page 16: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/16.jpg)
18
Introduction to parallel computing tools
Using multicore/multi-processor computers
Using graphics processing units (GPUs)
Scaling up to a cluster
Agenda
![Page 17: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/17.jpg)
19
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
higher, including NVIDIA Tesla 20-series products. See a complete listing at
www.nvidia.com/object/cuda_gpus.html
![Page 18: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/18.jpg)
20
Core 1
Core 3 Core 4
Core 2
Cache
Performance Gain with More Hardware
Using More Cores (CPUs) Using GPUs
Device Memory
GPU cores
Device Memory
![Page 19: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/19.jpg)
21
Programming Parallel Applications (GPU)
Built-in support with Toolboxes
Simple programming constructs: gpuArray, gather
Advanced programming constructs: arrayfun, bsxfun, spmd
Interface for experts:
CUDAKernel, MEX support
Ea
se
of
Us
e
Gre
ate
r Co
ntro
l
www.mathworks.com/gpu
![Page 20: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/20.jpg)
22
Example: Solving 2D Wave Equation GPU Computing
Intel Xeon Processor W3690 (3.47GHz),
NVIDIA Tesla K20 GPU
𝜕2𝑢
𝜕𝑡2 =𝜕2𝑢
𝜕𝑥2 +𝜕2𝑢
𝜕𝑦2
![Page 21: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/21.jpg)
23
Introduction to parallel computing tools
Using multicore/multi-processor computers
Using graphics processing units (GPUs)
Scaling up to a cluster
Agenda
![Page 22: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/22.jpg)
24
Example: Migrate from Desktop to Cloud
Change hardware without
changing algorithmic code
0,...2,1,...2,1
5
xkxbxm
![Page 23: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/23.jpg)
25
Use MATLAB Distributed Computing Server
MATLAB
Desktop (Client)
Local
Desktop Computer
Profile (Local)
1. Prototype code
MATLAB code
![Page 24: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/24.jpg)
26
Use MATLAB Distributed Computing Server
Cluster
Computer Cluster
Scheduler
Profile (Cluster)
1. Prototype code
2. Get access to an
enabled cluster
![Page 25: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/25.jpg)
27
Use MATLAB Distributed Computing Server
MATLAB
Desktop (Client)
Local
Desktop Computer
Cluster
Computer Cluster
Scheduler
Profile (Local)
Profile (Cluster)
MATLAB code
MATLAB code
1. Prototype code
2. Get access to an
enabled cluster
3. Switch cluster
profile to run on
cluster resources
![Page 26: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/26.jpg)
28
Offload computation:
– Free up desktop
– Access better computers
Scale speed-up:
– Use more cores
– Go from hours to minutes
Scale memory:
– Utilize distributed arrays
– Solve larger problems without re-coding algorithms
Cluster
Computer Cluster
Scheduler
Take Advantage of Cluster Hardware
MATLAB
Desktop (Client)
![Page 27: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/27.jpg)
29
Offloading Computations
Send desktop code to cluster resources
– No parallelism required within code
– Submit directly from MATLAB
Leverage supplied infrastructure
– File transfer / path augmentation
– Job monitoring
– Simplified retrieval of results
Scale offloaded computations
MATLAB code
Cluster
Computer Cluster
Scheduler
![Page 28: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/28.jpg)
30
MATLAB
Desktop (Client)
Offload Computations with batch
Result
Work
Worker
Worker
Worker
Worker
batch(…)
![Page 29: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/29.jpg)
31
MATLAB
Desktop (Client)
Offload and Scale Computations with batch
Result
Work
Worker
Worker
Worker
Worker
batch(…,'Pool',…)
![Page 30: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/30.jpg)
32
Example: Parameter Sweep of ODEs Offload and Scale Processing
Offload processing to workers:
batch
Scale offloaded processing:
batch(…,'Pool',…)
Retrieve results from job:
fetchOutputs
0,...2,1,...2,1
5
xkxbxm
![Page 31: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/31.jpg)
33
Benchmark: Parameter Sweep of ODEs Scaling case study for a fixed problem size with a cluster
Processor: Intel Xeon E5-2670
16 cores per node
Workers Computation
(minutes) Speed-up
1 173 1
16 13 13
32 6.4 27
64 3.2 55
96 2.1 83
128 1.6 109
160 1.3 134
192 1.1 158
![Page 32: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/32.jpg)
34
Distributed Array
Lives on the Workers
Remotely Manipulate Array
from Client
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
Worker
Worker
Worker
Worker
MATLAB
Desktop (Client)
![Page 33: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/33.jpg)
35
Investigation: Distributed Calculations
Effect of number of computers on execution time
Processor: Intel Xeon E5-2670
16 cores, 60 GB RAM per compute node
10 Gigabit Ethernet
N
Time (s)
1 node,
multi-
threaded
Distributed
2 nodes,
32W
4 nodes,
64W
4000 2 3 3
8000 16 14 12
16000 126 102 67
20000 244 187 118
32000 - 664 394
40000 - - 710
![Page 34: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/34.jpg)
36
MATLAB Distributed Computing Server
Extension of desktop parallel computing
Pre-built framework and infrastructure
Simplified license and maintenance
Cluster
Computer Cluster
Scheduler
![Page 35: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/35.jpg)
37
Dynamic Licensing Model
Users have access to their
licensed products
Server does not check out
any licenses on the client
User can exit MATLAB once
the job is queued
Cluster
Computer Cluster
Scheduler MATLAB
User A
MATLAB
User B
![Page 36: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/36.jpg)
38
Job Schedulers
MathWorks Job Scheduler
Direct support for specific schedulers
(Platform LSF, Microsoft HPCS, PBS)
Open API to support other schedulers
Ea
se
of
Us
e
Gre
ate
r Co
ntro
l
www.mathworks.com/products/distriben/supported
![Page 37: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/37.jpg)
39
Summary
Easily develop parallel MATLAB applications without
being a parallel programming expert
Speed up the execution of your MATLAB applications
using additional hardware
Develop parallel applications on your desktop and
easily scale to a cluster when needed
![Page 38: Parallel Computing with MATLAB - UVACollab€¦ · Originally for graphics acceleration, now also used for scientific calculations Massively parallel array of integer and floating](https://reader034.vdocuments.mx/reader034/viewer/2022051900/5fef3bbfcaa6fe479c02db6c/html5/thumbnails/38.jpg)
40
For more information
Visit
http://www.mathworks.com/products/parallel-computing
© 2013 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc.
See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names
may be trademarks or registered trademarks of their respective holders.