Uni.lu HPC School 2019 PS07: Scientific computing using MATLAB - - PowerPoint PPT Presentation

uni lu hpc school 2019
SMART_READER_LITE
LIVE PREVIEW

Uni.lu HPC School 2019 PS07: Scientific computing using MATLAB - - PowerPoint PPT Presentation

Uni.lu HPC School 2019 PS07: Scientific computing using MATLAB Uni.lu High Performance Computing (HPC) Team V. Plugaru University of Luxembourg (UL), Luxembourg http://hpc.uni.lu V. Plugaru & Uni.lu HPC Team (University of Luxembourg)


slide-1
SLIDE 1

Uni.lu HPC School 2019

PS07: Scientific computing using MATLAB

Uni.lu High Performance Computing (HPC) Team

  • V. Plugaru

University of Luxembourg (UL), Luxembourg http://hpc.uni.lu

1 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-2
SLIDE 2

Latest versions available on Github: UL HPC tutorials:

https://github.com/ULHPC/tutorials

UL HPC School:

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

PS07 tutorial sources:

https://ulhpc-tutorials.rtfd.io.rtfd.io/en/latest/maths/matlab/basics/ 2 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-3
SLIDE 3

Practical Session Objectives

Summary

1 Practical Session Objectives 2 MATLAB on UL HPC Prerequisites Using MATLAB 3 Conclusion

3 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-4
SLIDE 4

Practical Session Objectives

Session Objectives

Better understand the usage of MATLAB on the Uni.lu HPC Platform

running in interactive mode

֒ → with either the full graphical or the text-mode interface ֒ → graphical web portal based on OnDemand coming soon

4 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-5
SLIDE 5

Practical Session Objectives

Session Objectives

Better understand the usage of MATLAB on the Uni.lu HPC Platform

running in interactive mode

֒ → with either the full graphical or the text-mode interface ֒ → graphical web portal based on OnDemand coming soon

running in passive mode

֒ → several ways of submitting MATLAB jobs ֒ → example launchers for SLURM

4 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-6
SLIDE 6

Practical Session Objectives

Session Objectives

Better understand the usage of MATLAB on the Uni.lu HPC Platform

running in interactive mode

֒ → with either the full graphical or the text-mode interface ֒ → graphical web portal based on OnDemand coming soon

running in passive mode

֒ → several ways of submitting MATLAB jobs ֒ → example launchers for SLURM

checking available toolboxes & licenses status

4 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-7
SLIDE 7

Practical Session Objectives

Session Objectives

Better understand the usage of MATLAB on the Uni.lu HPC Platform

running in interactive mode

֒ → with either the full graphical or the text-mode interface ֒ → graphical web portal based on OnDemand coming soon

running in passive mode

֒ → several ways of submitting MATLAB jobs ֒ → example launchers for SLURM

checking available toolboxes & licenses status using script (.m) files

4 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-8
SLIDE 8

Practical Session Objectives

Session Objectives

Better understand the usage of MATLAB on the Uni.lu HPC Platform

running in interactive mode

֒ → with either the full graphical or the text-mode interface ֒ → graphical web portal based on OnDemand coming soon

running in passive mode

֒ → several ways of submitting MATLAB jobs ֒ → example launchers for SLURM

checking available toolboxes & licenses status using script (.m) files plotting data, saving the plots to file

4 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-9
SLIDE 9

MATLAB on UL HPC

Summary

1 Practical Session Objectives 2 MATLAB on UL HPC Prerequisites Using MATLAB 3 Conclusion

5 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-10
SLIDE 10

MATLAB on UL HPC

Tutorial files

Sample MATLAB scripts used in the tutorial

download only the scripts

mkdir $HOME/matlab-tutorial cd $HOME/matlab-tutorial wget https://raw.github.com/ULHPC/tutorials/devel/maths/\ matlab/basics/code/ example1.m example2.m google_finance_data.m file_data_source.m AAPL.csv

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

git clone https://github.com/ULHPC/tutorials.git ln -s tutorials/maths/matlab/basics $HOME/matlab-tutorial

6 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-11
SLIDE 11

MATLAB on UL HPC

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:

֒ → in combination with Putty: VcXsrv http://sourceforge.net/projects/vcxsrv/ ֒ → with MobaXTerm: nothing additional needed

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

  • n Linux & macOS: ssh iris-cluster -X
  • n Windows

֒ → with Putty: Connection → SSH → X11 → Enable X11 forwarding ֒ → with MobaXTerm: remote GUI applications should work by default

7 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-12
SLIDE 12

MATLAB on UL HPC

Scripts and plots

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

12/02 01/21 03/11 04/30 06/19 08/08 09/27 11/16 01/05 Date 90 95 100 105 110 115 120 Price (USD) Closing stock prices for AAPL between 4-Jan-16 and 30-Dec-16 120 2 4 6 17/01/05 10 7 Trading volume 110 8 10 16/09/27 Closing stock prices and trading volumes for AAPL between 4-Jan-16 and 30-Dec-16 Price (USD) 12 Date 16/06/19 14 100 16/03/11 90 15/12/02

8 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-13
SLIDE 13

MATLAB on UL HPC

Parallelization

example2.m: non-interactive script that shows

the serial execution of time consuming operations

9 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-14
SLIDE 14

MATLAB on UL HPC

Parallelization

example2.m: non-interactive script that shows

the serial execution of time consuming operations and revisited in the second part of the tutorial:

֒ → 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

9 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-15
SLIDE 15

MATLAB on UL HPC

Beyond simple executions

application-level checkpointing

֒ → using in-built MATLAB functions

10 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-16
SLIDE 16

MATLAB on UL HPC

Beyond simple executions

application-level checkpointing

֒ → using in-built MATLAB functions

taking advantage of some parallelization capabilities

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

10 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-17
SLIDE 17

MATLAB on UL HPC

Beyond simple executions

application-level checkpointing

֒ → using in-built MATLAB functions

taking advantage of some parallelization capabilities

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

adapting parallel code with checkpoint/restart features

10 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-18
SLIDE 18

MATLAB on UL HPC

Checkpointing

What is it? Technique for adding fault tolerance to your application.

You adapt your code to (regularly) save a snapshot of the environment (workspace) . . . and restart execution from the snapshot in case of failure.

11 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-19
SLIDE 19

MATLAB on UL HPC

Checkpointing

What is it? Technique for adding fault tolerance to your application.

You adapt your code to (regularly) save a snapshot of the environment (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

11 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-20
SLIDE 20

MATLAB on UL HPC

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!

12 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-21
SLIDE 21

MATLAB on UL HPC

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 PRNG (e.g. Monte Carlo-based experiments) ensure results consistency after you add checkpointing

12 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-22
SLIDE 22

MATLAB on UL HPC

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’) 13 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-23
SLIDE 23

MATLAB on UL HPC

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

13 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-24
SLIDE 24

MATLAB on UL HPC

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’) 13 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-25
SLIDE 25

MATLAB on UL HPC

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

13 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-26
SLIDE 26

MATLAB on UL HPC

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!

14 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-27
SLIDE 27

MATLAB on UL HPC

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!

14 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-28
SLIDE 28

MATLAB on UL HPC

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

15 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-29
SLIDE 29

MATLAB on UL HPC

  • Ref. documentation - parallelization

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

Multi-GPU computing examples

https://nl.mathworks.com/help/parallel-computing/examples/ run-matlab-functions-on-multiple-gpus.html 16 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-30
SLIDE 30

MATLAB on UL HPC

Accelerating the time to result

Option 1: Split input over several parallel, independent jobs

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

17 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-31
SLIDE 31

MATLAB on UL HPC

Accelerating the time to result

Option 1: Split input over several parallel, independent jobs

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

Option 2: Use parfor to execute loop iterations in parallel

֒ → single node only ֒ → Iris bigmem partition nodes with 112 cores for big problems

17 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-32
SLIDE 32

MATLAB on UL HPC

Accelerating the time to result

Option 1: Split input over several parallel, independent jobs

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

Option 2: Use parfor to execute loop iterations in parallel

֒ → single node only ֒ → Iris bigmem partition nodes with 112 cores for big problems

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

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

  • including discrete Fourier transform, matrix multiplication, left matrix division

17 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-33
SLIDE 33

MATLAB on UL HPC

Accelerating the time to result

Option 1: Split input over several parallel, independent jobs

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

Option 2: Use parfor to execute loop iterations in parallel

֒ → single node only ֒ → Iris bigmem partition nodes with 112 cores for big problems

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

֒ → require the code to be run on GPU nodes (subset of Iris) ֒ → great speedup for some workloads ֒ → multiple hundreds of 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 MATLAB license

17 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-34
SLIDE 34

MATLAB on UL HPC

Speed up your seq. code

example2.m: non-interactive script that shows

the serial execution of time consuming operations

18 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-35
SLIDE 35

MATLAB on UL HPC

Speed up your seq. code

example2.m: non-interactive script that shows

the serial execution of time consuming operations and revisited in the second part of the tutorial:

֒ → 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 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-36
SLIDE 36

MATLAB on UL HPC

Speed up your seq. code

example2.m: non-interactive script that shows

the serial execution of time consuming operations and revisited in the second part of the tutorial:

֒ → 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 diff. GPUs) increase # of iterations, matrix size increase # of workers with/out changing # of req. cores modify the script with other GPU-enabled functions

18 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-37
SLIDE 37

Conclusion

Summary

1 Practical Session Objectives 2 MATLAB on UL HPC Prerequisites Using MATLAB 3 Conclusion

19 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-38
SLIDE 38

Conclusion

Exercises - your mission today

Read and understand the MATLAB tutorial

https://github.com/ULHPC/tutorials/tree/devel/maths/matlab

֒ → all provided scripts are fully commented

Run all the examples

֒ → launching interactive/passive mode MATLAB ֒ → plotting script ֒ → parallel execution script

20 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-39
SLIDE 39

Conclusion

Useful links

Getting Started with Parallel Computing Toolbox

http://nl.mathworks.com/help/distcomp/getting-started-with-parallel-computing-toolbox.html

Parallel for-Loops (parfor) documentation

https://nl.mathworks.com/help/distcomp/parfor.html

GPU Computing documentation

https://nl.mathworks.com/discovery/matlab-gpu.html

Multi-GPU computing examples

https: //nl.mathworks.com/help/parallel-computing/examples/run-matlab-functions-on-multiple-gpus.html 21 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-40
SLIDE 40

Conclusion

What we’ve seen so far (I)

MATLAB execution modes on the Uni.lu HPC Platform Checking for available toolboxes and licenses Basics of plotting

Perspectives

Personalize the UL HPC launchers with the MATLAB commands Check example #2 M-file for insight into basic parallel execution Parallelize your own tasks using parfor/GPU-enabled instructions

22 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-41
SLIDE 41

Conclusion

What we’ve seen so far (II)

Checkpointing basics Specific MATLAB instructions for checkpointing MATLAB parallelization capabilities

Perspectives

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

23 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07

slide-42
SLIDE 42

Thank you for your attention...

Questions?

http://hpc.uni.lu High Performance Computing @ uni.lu

  • Prof. Pascal Bouvry
  • Dr. Sebastien Varrette

Valentin Plugaru Sarah Peter Hyacinthe Cartiaux Clement Parisot

  • Dr. FrÃľderic Pinel
  • Dr. Emmanuel Kieffer

University of Luxembourg, Belval Campus Maison du Nombre, 4th floor 2, avenue de l’Université L-4365 Esch-sur-Alzette mail: hpc@uni.lu

1

Practical Session Objectives

2

MATLAB on UL HPC Prerequisites Using MATLAB

3

Conclusion 24 / 24

  • V. Plugaru & Uni.lu HPC Team (University of Luxembourg)

Uni.lu HPC School 2019/ PS07