matlab on a - researchcomputing.github.com by...

28
Research Computing @ CU Boulder Matlab on a Supercomputer Shelley L. Knuth Research Computing April 9, 2015

Upload: phungthu

Post on 14-May-2018

225 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Matlab on a Supercomputer Shelley L. Knuth Research Computing April 9, 2015

Page 2: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Outline •  Description of Matlab and supercomputing •  Interactive Matlab jobs •  Non-interactive Matlab jobs •  Parallel Computing

4/9/2015 Meetup   2

Slides  available  at  

h0p://researchcompu7ng.github.io/meetup_spring_2015/  

Page 3: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

What Is Matlab? •  A high performance tool for technical computing

•  Integrates computation, visualization, and programming •  Analyze data, develop algorithms, create applications www.mathworks.com

•  Uses many specialized toolboxes to make our lives easier

•  Used by many in the sciences, engineering, math •  Academia and industry

4/9/2015 Meetup   3

Page 4: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

What Is a Supercomputer? • One large computer made up of many smaller

computers and processors • Each different computer is called a node • Each node has processors/cores

• Carry out the instructions of the computer • With a supercomputer, all these different

computers talk to each other through a communications network

Meetup   4 4/9/2015

Page 5: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Janus Supercomputer •  1368 nodes, 16,000+ cores •  Resource available to all of CU •  RC environment has login, compile, and compute

nodes •  Login nodes

•  Virtual machine •  Presents a development environment •  Where you land when you log in •  Used for:

•  Editing scripts •  Job submission

4/9/2015 Meetup   5

Page 6: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Janus Supercomputer •  Compile nodes

•  Used for: •  Compiling/installing software •  Compiling large programs

•  Nodes on Janus that have the same setup as computational nodes

•  Hardware and software

•  Compute nodes •  Where jobs are run •  Jobs are scheduled to run on the compute nodes via a

scheduler

4/9/2015 Meetup   6

Page 7: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Setting up to run Matlab •  Different than running Matlab on your local machine •  Must login, set environment to run

•  Login: ssh –X [email protected] Enter password: 4-digit PIN + OTP number

•  Setting environment up to run Matlab:

module load matlab

4/9/2015 Meetup   7

Page 8: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

How to Run Matlab

• Once you have your environment set up to run Matlab, there are two main ways you can run Matlab •  Interactively •  In the background

• We will examine both methods, and their pros and cons

4/9/2015 Meetup   8

Page 9: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Interactive Matlab

•  “Interactive” means working with software where you input commands and the software gives a response

•  One common mistake people make is to login, be on a login node, and then type “matlab” •  Similar to how they would run it on their laptop •  This is a great example of WHAT NOT TO DO •  Login nodes are a shared resource •  Running software that requires a lot of resources can

impact other’s usability of the node

4/9/2015 Meetup   9

Page 10: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Batch job submission

•  Matlab can also be run interactively through a batch job •  Achieves the same effect, more efficient

•  Batch jobs are scheduled to run on a supercomputer once the required resources are available and after it is your turn in the queue

•  RC uses SLURM to submit/schedule jobs •  Common commands: sbatch sinteractive salloc

4/9/2015 Meetup   10

Page 11: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Interactive Batch Jobs - Matlab •  To submit a batch job to run Matlab interactively:

•  Request CPU time on the compute nodes •  Wait for this the resources to become available •  Open Matlab •  Do your thing!

•  Interactive batch jobs are mainly used for •  Debugging •  Short job runs

4/9/2015 Meetup   11

Page 12: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Submission – Interactive Batch Jobs •  To submit an interactive batch job on Janus, do the

following: module load matlab (described earlier) module load slurm Then to request compute time, either use: salloc sinteractive

4/9/2015 Meetup   12

Page 13: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Salloc vs. Sinteractive

•  Both are SLURM commands •  salloc

•  Use this if you don’t need X11 forwarding •  If you don’t need the GUI

•  sinteractive •  Use this if you do need X11 forwarding

salloc --qos=janus-debug sinteractive --qos=janus-debug

4/9/2015 Meetup   13

Page 14: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Length – Interactive Batch Jobs

•  NEVER run for a long time •  Your job will start when resources become available •  This could be at 2 am •  Want job to start asap •  Ask for as few resources as possible

•  Small wall-time •  Good for the janus-debug queue

•  Keeps you to under 1 hour

4/9/2015 Meetup   14

Page 15: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Interactive Batch Jobs •  Once salloc or sinteractive runs

salloc --qos=janus-debug •  And resources become available you are granted a job

allocation on a node salloc: Granted job allocation 602576 (output)

•  Once this comes on the screen your compute allocation is being used •  If you type hostname you will be told which node you are

on bash-4.1$ hostname node0211

4/9/2015 Meetup   15

Page 16: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Interactive Matlab •  Now you can run Matlab

matlab •  If you use salloc you will get Matlab without the GUI •  If you use sinteractive you will get Matlab with the GUI •  Let’s try it!

•  One thing to remember – you are burning compute time •  If finish earlier than time asked for type exit!

4/9/2015 Meetup   16

Page 17: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Non-Interactive Batch Jobs

•  Submit job that will be executed when resources are available

•  Create a text file containing information about the job •  Or submit on the command line •  Submit the job file to a queue

sbatch !

4/9/2015 Meetup   17

Page 18: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Batch Job example •  Contents of scripts

•  Matlab_tutorial_general.sh •  Wrapper script loads the slurm commands •  Changes to the appropriate directory •  Calls the matlab .m files

•  Matlab_tutorial_general_code.m

•  Run matlab program as a batch job •  sbatch matlab_tutorial_general.sh

•  Check job status: •  squeue –q janus-debug •  cat SERIAL.out

Meetup   18 4/9/2015

Page 19: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Parallel Processing

•  In parallel processing we use several CPUs to solve one problem

•  One node with several cores

•  Several nodes with many cores

•  Embarrassingly parallel

Source:  h0ps://compu7ng.llnl.gov/tutorials/parallel_comp/  

4/9/2015 Meetup   19

Page 20: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Parallel Computing Toolbox (PCT)

• Additional toolbox as part of Matlab • Perform parallel computations on multicore

computers, GPUs, and computer clusters • Allows you to parallelize Matlab code without

MPI programming • Many Matlab functions work in concert with the

PCT • Simple to utilize with just the use of certain

commands

4/9/2015 Meetup   20

Page 21: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Parallel and Not Parallel

Parallel: matlabpool open 3 parfor i=1:10 x=x(i)+1; end matlabpool close

Not  Parallel:  

for  i=1:10  

     x=x(i)+1;  

end  

 

4/9/2015 Meetup   21

Page 22: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Running Matlab in Parallel

•  Workers: copies of the original client created to assist in computation

4/9/2015 Meetup   22

Page 23: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Running Matlab in Parallel

•  On Janus at CU can run up to 12 workers on one node •  Used to be able to only

run one Matlab job at a time

•  Now can run as many as you want

•  Can also run as many workers on the high memory nodes

4/9/2015 Meetup   23

Page 24: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

parfor

•  Easy to use •  Allows parallelism in terms of loops •  When client reaches a parfor loop iterations of loop are

automatically divided up among workers •  Parfor requires results be completely independent •  Cannot determine how loops are divided

4/9/2015 Meetup   24

Page 25: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Running Matlab in Parallel On Lots of Cores

•  Typically see a significant speed up when using parfor vs. when not • If code is parallelizable

•  However, this might not always be the case •  Might spend more time in overhead

•  If code isn’t parallelizable •  If code isn’t that complicated

4/9/2015 Meetup   25

Page 26: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Spmd Command

•  Single process, multiple data •  The spmd command ensures more control •  Can parallelize much more than just loops •  Like a very simplified version of MPI •  More flexibility than parfor •  However, need to know what you’re doing

4/9/2015 Meetup   26

Page 27: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Distributed Computing Toolbox

•  PCT allows you to run programs in parallel across many processors

•  DCT allows you to run across nodes •  Allows you to run easily on clusters •  Supports resource managers •  Not an option for Janus

4/9/2015 Meetup   27

Page 28: Matlab on a - Researchcomputing.github.com by ...researchcomputing.github.io/meetup_spring_2015/pdfs/matlab... · Matlab on a Supercomputer ... • If you use sinteractive you will

Research Computing @ CU Boulder

Questions?

[email protected]

4/9/2015 Meetup   28