MATLAB on UL HPC Checkpointing & parallel execution UL High - - PowerPoint PPT Presentation

matlab on ul hpc
SMART_READER_LITE
LIVE PREVIEW

MATLAB on UL HPC Checkpointing & parallel execution UL High - - PowerPoint PPT Presentation

MATLAB on UL HPC Checkpointing & parallel execution UL High Performance Computing (HPC) Team Valentin Plugaru University of Luxembourg (UL), Luxembourg http://hpc.uni.lu Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC 1 / 21


slide-1
SLIDE 1

MATLAB on UL HPC

Checkpointing & parallel execution

UL High Performance Computing (HPC) Team Valentin Plugaru University of Luxembourg (UL), Luxembourg http://hpc.uni.lu

1 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-2
SLIDE 2

Latest versions available on Github: UL HPC tutorials:

https://github.com/ULHPC/tutorials

UL HPC School:

https://hpc.uni.lu/hpc-school

This tutorial’s sources:

https://github.com/ULHPC/tutorials/tree/devel/advanced/MATLAB2 2 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-3
SLIDE 3

Summary

1 Pre-requisites 2 Objectives 3 Checkpointing Example 1 revisited 4 Parallelization Example 2 revisited 5 Conclusion

3 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-4
SLIDE 4

Pre-requisites

Summary

1 Pre-requisites 2 Objectives 3 Checkpointing Example 1 revisited 4 Parallelization Example 2 revisited 5 Conclusion

4 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-5
SLIDE 5

Pre-requisites

Tutorial files

Sample MATLAB scripts used in the tutorial

download only the scripts:

(frontend)$> mkdir $HOME/matlab-tutorial2 (frontend)$> cd $HOME/matlab-tutorial2 (frontend)$> wget https://raw.github.com/ULHPC/tutorials/devel/advanced/MATLAB2/code/example1.m (frontend)$> wget https://raw.github.com/ULHPC/tutorials/devel/advanced/MATLAB2/code/example2.m (frontend)$> wget https://raw.github.com/ULHPC/tutorials/devel/advanced/MATLAB2/code/google_finance_data.m

  • r download the full repository and link to the MATLAB tutorial:

(frontend)$> git clone https://github.com/ULHPC/tutorials.git (frontend)$> ln -s tutorials/advanced/MATLAB2/

$HOME/matlab-tutorial2

5 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-6
SLIDE 6

Pre-requisites

X Window System

In order to see locally the MATLAB graphical interface, a package providing the X Window System is required:

  • n OS X: XQuartz

http://xquartz.macosforge.org/landing/

  • n Windows: VcXsrv

http://sourceforge.net/projects/vcxsrv/

Now you will be able to connect with X11 forwarding enabled:

  • n Linux & OS X:

$> ssh access-gaia.uni.lu -X

  • n Windows, with Putty

Connection → SSH → X11 → Enable X11 forwarding

6 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-7
SLIDE 7

Objectives

Summary

1 Pre-requisites 2 Objectives 3 Checkpointing Example 1 revisited 4 Parallelization Example 2 revisited 5 Conclusion

7 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-8
SLIDE 8

Objectives

Objectives of this PS

Better understand the usage of MATLAB on the UL HPC Platform

application-level checkpointing

֒ → using in-built MATLAB functions

8 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-9
SLIDE 9

Objectives

Objectives of this PS

Better understand the usage of MATLAB on the UL HPC Platform

application-level checkpointing

֒ → using in-built MATLAB functions

taking advantage of some parallelization capabilities

֒ → use of parfor ֒ → use of GPU-enabled functions

8 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-10
SLIDE 10

Objectives

Objectives of this PS

Better understand the usage of MATLAB on the UL HPC Platform

application-level checkpointing

֒ → using in-built MATLAB functions

taking advantage of some parallelization capabilities

֒ → use of parfor ֒ → use of GPU-enabled functions

adapting the parallel code with checkpoint/restart features

8 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-11
SLIDE 11

Checkpointing

Summary

1 Pre-requisites 2 Objectives 3 Checkpointing Example 1 revisited 4 Parallelization Example 2 revisited 5 Conclusion

9 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-12
SLIDE 12

Checkpointing

Checkpointing

What is it? Technique for adding fault tolerance to your application. You adapt your code to (regularly) save a snapshot of the envi- ronment (workspace), and restart execution from the snapshot in case of failure.

10 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-13
SLIDE 13

Checkpointing

Checkpointing

What is it? Technique for adding fault tolerance to your application. You adapt your code to (regularly) save a snapshot of the envi- ronment (workspace), and restart execution from the snapshot in case of failure. Why make the effort to checkpoint?

because your code may take longer to execute than the maximum walltime allowed because losing (precious) hours or days of computation when something fails may (should!) not be acceptable

10 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-14
SLIDE 14

Checkpointing

Checkpointing pitfalls

checkpointing (too) often can be counterproductive

֒ → saving state in each loop may take longer than its actual computing time ֒ → saving state incrementally can lead to fast exhaustion of your $HOME space ֒ → in extreme cases can lead to platform instability – especially if running parallel jobs!

11 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-15
SLIDE 15

Checkpointing

Checkpointing pitfalls

checkpointing (too) often can be counterproductive

֒ → saving state in each loop may take longer than its actual computing time ֒ → saving state incrementally can lead to fast exhaustion of your $HOME space ֒ → in extreme cases can lead to platform instability – especially if running parallel jobs!

checkpointing (especially parallel) code can be tricky extra-care required if checkpointing simulations involving RNG (e.g. Monte Carlo-based experiments) ensure results consistency after you add checkpointing

11 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-16
SLIDE 16

Checkpointing

Checkpointing basics

1 Check that a checkpoint file exists:

exist(’save.mat’,’file’)

2 If it exists, restore workspace data from it:

load(’save.mat’) 12 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-17
SLIDE 17

Checkpointing

Checkpointing basics

1 Check that a checkpoint file exists:

exist(’save.mat’,’file’)

2 If it exists, restore workspace data from it:

load(’save.mat’)

3 During computing steps, use control variables to direct (re)start of computation

12 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-18
SLIDE 18

Checkpointing

Checkpointing basics

1 Check that a checkpoint file exists:

exist(’save.mat’,’file’)

2 If it exists, restore workspace data from it:

load(’save.mat’)

3 During computing steps, use control variables to direct (re)start of computation 4 Every n loops, or if execution time (in loop or since startup) is above threshold, checkpoint:

֒ → save full workspace state:

save(’save.tmp’)

֒ → save partial state:

save(’save.tmp’, ’var1’, ’var2’) 12 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-19
SLIDE 19

Checkpointing

Checkpointing basics

1 Check that a checkpoint file exists:

exist(’save.mat’,’file’)

2 If it exists, restore workspace data from it:

load(’save.mat’)

3 During computing steps, use control variables to direct (re)start of computation 4 Every n loops, or if execution time (in loop or since startup) is above threshold, checkpoint:

֒ → save full workspace state:

save(’save.tmp’)

֒ → save partial state:

save(’save.tmp’, ’var1’, ’var2’)

5 Rename state file to final name:

system(’mv save.tmp save.mat’)

֒ → this process ensures that in case of failure during checkpointing, next execution doesn’t try to restart from incomplete state

12 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-20
SLIDE 20

Checkpointing

When to trigger checkpointing?

when (loop) execution time is above threshold (e.g. 1h):

֒ → use tic and toc stopwatch functions, remember they can be assigned to variables ֒ → use the clock function ֒ → add some randomness to the threshold if you run several instances in parallel!

13 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-21
SLIDE 21

Checkpointing

When to trigger checkpointing?

when (loop) execution time is above threshold (e.g. 1h):

֒ → use tic and toc stopwatch functions, remember they can be assigned to variables ֒ → use the clock function ֒ → add some randomness to the threshold if you run several instances in parallel!

every n loop executions

֒ → remember that saving state takes time, depending on workspace size & shared filesystem usage, and ֒ → if loops finish fast your code may be slowed down considerably ֒ → add some randomness to n if you run several instances in parallel!

13 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-22
SLIDE 22

Checkpointing

Adding checkpointing to seq. code

example1.m: non-interactive script that shows:

the use of a stopwatch timer how to use an external function (financial data retrieval) how to use different plotting methods how to export the plots in different graphic formats

Tasks to tackle with checkpointing

modify the script to download data for Fortune100 companies add & test checkpointing to save state after each company’s data is downloaded more granular downloads - modify download period from 1 year to 1 month, add & test checkpointing to save state after each download

14 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-23
SLIDE 23

Parallelization

Summary

1 Pre-requisites 2 Objectives 3 Checkpointing Example 1 revisited 4 Parallelization Example 2 revisited 5 Conclusion

15 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-24
SLIDE 24

Parallelization

Reference documentation

Parallel Computing Toolbox

http://www.mathworks.nl/help/distcomp/index.html

Parallel for-Loops (parfor)

http://www.mathworks.nl/help/distcomp/getting-started-with-parfor.html

GPU Computing

http://www.mathworks.nl/discovery/matlab-gpu.html 16 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-25
SLIDE 25

Parallelization

Accelerate the time to result

Option 1: Split input over several parallel, independent, MATLAB jobs

֒ → great if it’s possible (embarrassingly parallel problem)

17 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-26
SLIDE 26

Parallelization

Accelerate the time to result

Option 1: Split input over several parallel, independent, MATLAB jobs

֒ → great if it’s possible (embarrassingly parallel problem)

Option 2: Use parfor to execute loop iterations in parallel

֒ → single node only ֒ → we have 120 & 160 core nodes on which big problems can be tackled

17 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-27
SLIDE 27

Parallelization

Accelerate the time to result

Option 1: Split input over several parallel, independent, MATLAB jobs

֒ → great if it’s possible (embarrassingly parallel problem)

Option 2: Use parfor to execute loop iterations in parallel

֒ → single node only ֒ → we have 120 & 160 core nodes on which big problems can be tackled

Option 3: Use GPU-enabled functions that work on the gpuArray data type

֒ → require the code to be run on GPU nodes (subset of Gaia) ֒ → great speedup for some workloads ֒ → 295 in-built MATLAB functions work on gpuArray

including discrete Fourier transform, matrix multiplication, left matrix division 17 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-28
SLIDE 28

Parallelization

Accelerate the time to result

Option 1: Split input over several parallel, independent, MATLAB jobs

֒ → great if it’s possible (embarrassingly parallel problem)

Option 2: Use parfor to execute loop iterations in parallel

֒ → single node only ֒ → we have 120 & 160 core nodes on which big problems can be tackled

Option 3: Use GPU-enabled functions that work on the gpuArray data type

֒ → require the code to be run on GPU nodes (subset of Gaia) ֒ → great speedup for some workloads ֒ → 295 in-built MATLAB functions work on gpuArray

including discrete Fourier transform, matrix multiplication, left matrix division

Option 4: MATLAB Distributed Computing Server (MDCS)

֒ → allows multi-node parallel execution ֒ → not yet part of the UL MATLAB license

17 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-29
SLIDE 29

Parallelization

Speed up your seq. code

example2.m: non-interactive script that shows:

the serial execution of time consuming operations

֒ → the parallel execution and relative speedup vs serial execution ֒ → setting the # of parallel threads through environment variables ֒ → GPU-based parallel execution

1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 Number of cores Parallel speedup parfor−based parallel speedup vs serial execution speedup speedup with overhead

18 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-30
SLIDE 30

Parallelization

Speed up your seq. code

example2.m: non-interactive script that shows:

the serial execution of time consuming operations

֒ → the parallel execution and relative speedup vs serial execution ֒ → setting the # of parallel threads through environment variables ֒ → GPU-based parallel execution

Tasks to tackle

execute the script on regular vs GPU nodes (with different GPUs) increase # of iterations, matrix size increase # of workers with/without changing the # of requested cores modify the script with other GPU-enabled functions

18 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-31
SLIDE 31

Conclusion

Summary

1 Pre-requisites 2 Objectives 3 Checkpointing Example 1 revisited 4 Parallelization Example 2 revisited 5 Conclusion

19 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-32
SLIDE 32

Conclusion

What we’ve seen in this session

Checkpointing basics Specific MATLAB instructions for checkpointing Current MATLAB parallelization capabilities on UL HPC Platform

Perspectives

(incrementally) modify your own MATLAB code for fault tolerance parallelize your own tasks using parfor/GPU-enabled instructions

20 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC

slide-33
SLIDE 33

Thank you for your attention...

Questions?

Valentin Plugaru Mail: valentin.plugaru@uni.lu Office: MNO, E04 0445-070 Maison du Nombre 6, Avenue de la Fonte L-4364 Esch-sur-Alzette UL HPC Management Team mail: hpc-sysadmins@uni.lu

1

Pre-requisites

2

Objectives

3

Checkpointing Example 1 revisited

4

Parallelization Example 2 revisited

5

Conclusion 21 / 21 Valentin Plugaru (University of Luxembourg) MATLAB on UL HPC