Parallel Computing with MATLAB Modified for 240A UCSB Based on Jemmy Hu University of Waterloo https://www.sharcnet.ca/~jemmyhu/tutorials/ss2011.

Slides:



Advertisements
Similar presentations
NGS computation services: API's,
Advertisements

MATLAB Parallel Computing Toolbox A.Hosseini Course : Professional Architecture.
Parallel Matlab Vikas Argod Research Computing and Cyberinfrastructure
Introduction to Matlab
Parallel Computing in Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Partitioning and Divide-and-Conquer Strategies ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, Jan 23, 2013.
Parallel ISDS Chris Hans 29 November 2004.
Setting up of condor scheduler on computing cluster Raman Sehgal NPD-BARC.
Parallel Computing in Matlab An Introduction. Overview Offload work from client to workers Run as many as eight workers (newest version) Can keep client.
David Adams ATLAS DIAL Distributed Interactive Analysis of Large datasets David Adams BNL March 25, 2003 CHEP 2003 Data Analysis Environment and Visualization.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
6. More on the For-Loop Using the Count Variable Developing For-Loop Solutions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
High Performance Computing 1 Parallelization Strategies and Load Balancing Some material borrowed from lectures of J. Demmel, UC Berkeley.
©Brooks/Cole, 2003 Chapter 7 Operating Systems Dr. Barnawi.
Asynchronous Solution Appendix Eleven. Training Manual Asynchronous Solution August 26, 2005 Inventory # A11-2 Chapter Overview In this chapter,
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Parallel Computing with MATLAB
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
INTRODUCTION TO MATLAB PARALLEL COMPUTING TOOLBOX Kadin Tseng Boston University Scientific Computing and Visualization.
Mapping Techniques for Load Balancing
Flynn’s Taxonomy of Computer Architectures Source: Wikipedia Michael Flynn 1966 CMPS 5433 – Parallel Processing.
18.337: Image Median Filter Rafael Palacios Aeronautics and Astronautics department. Visiting professor (IIT-Institute for Research in Technology, University.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Matlab ® Distributed Computing Server CBI Laboratory Release: R2012a Sept. 28, 2012 By: CBI Development Team.
Introduction to Parallel Programming MapReduce Except where otherwise noted all portions of this work are Copyright (c) 2007 Google and are licensed under.
Parallelization with the Matlab® Distributed Computing Server CBI cluster December 3, Matlab Parallelization with the Matlab Distributed.
Exercise problems for students taking the Programming Parallel Computers course. Janusz Kowalik Piotr Arlukowicz Tadeusz Puzniakowski Informatics Institute.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
© 2008 The MathWorks, Inc. ® ® Parallel Computing with MATLAB ® Silvina Grad-Freilich Manager, Parallel Computing Marketing
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
 Introduction to Operating System Introduction to Operating System  Types Of An Operating System Types Of An Operating System  Single User Single User.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
INTRODUCTION TO MATLAB LAB# 01
Parallel Computing with MATLAB Jemmy Hu SHARCNET HPC Consultant University of Waterloo May 24,
Parallel Computing with Matlab CBI Lab Parallel Computing Toolbox TM An Introduction Oct. 27, 2011 By: CBI Development Team.
1 © 2012 The MathWorks, Inc. Parallel computing with MATLAB.
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Chapter 3 Parallel Programming Models. Abstraction Machine Level – Looks at hardware, OS, buffers Architectural models – Looks at interconnection network,
Computer Science and Engineering Parallel and Distributed Processing CSE 8380 February Session 11.
OUTLINE Overview Numbers, variables and similar in Matlab
Parallel Computing with MATLAB Jemmy Hu SHARCNET HPC Consultant University of Waterloo Feb. 1, 2012.
Parallel execution Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Lab 2 Parallel processing using NIOS II processors
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Introduction to Matlab
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
INTRODUCTION TO MATLAB PARALLEL COMPUTING TOOLBOX Kadin Tseng Boston University Scientific Computing and Visualization.
Parallelization of a Swarm Intelligence System
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
HUBbub 2013: Developing hub tools that submit HPC jobs Rob Campbell Purdue University Thursday, September 5, 2013.
HParC language. Background Shared memory level –Multiple separated shared memory spaces Message passing level-1 –Fast level of k separate message passing.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
Computer Science and Engineering Parallel and Distributed Processing CSE 8380 February Session 12.
Debugging Lab Antonio Gómez-Iglesias Texas Advanced Computing Center.
Active-HDL Server Farm Course 11. All materials updated on: September 30, 2004 Outline 1.Introduction 2.Advantages 3.Requirements 4.Installation 5.Architecture.
Using ROSSMANN to Run GOSET Studies Omar Laldin ( using materials from Jonathan Crider, Harish Suryanarayana ) Feb. 3, 2014.
OpenPBS – Distributed Workload Management System
Scripts & Functions Scripts and functions are contained in .m-files
Matlab Workshop 9/22/2018.
High Performance Computing in Teaching
Oct. 27, By: CBI Development Team
Presentation transcript:

Parallel Computing with MATLAB Modified for 240A UCSB Based on Jemmy Hu University of Waterloo

Parallel Computing Toolbox Parallel Matlab Provides: –Parallel processing constructs such as parallel for-loops and code blocks –distributed arrays –parallel numerical algorithms, –and message-passing functions Run your applications interactively on a local machine, or in batch environments on a remote server.

PCT Architecture (client-server)

Client Machine Cluster Where is the MATLAB client? CPU Worker Scheduler Worker Login Node Distributed Computing Toolbox MATLAB Simulink Blocksets Toolboxes submit jobs Client Machine Distributed Computing Toolbox MATLAB Simulink Blocksets Toolboxes ssh submit jobs No Shared File System between clients and cluster Shared File System

Parallel mode on a MATLAB Pool matlabpoolmatlabpool Open or close pool of MATLAB sessions for parallel computation parforparfor Execute code loop in parallel spmdspmd Execute code in parallel on MATLAB pool batchbatch Run MATLAB script as batch job Interactive Functions helphelp Help for toolbox functions in Command Window pmodepmode Interactive Parallel Command Window

Key Function List Job Creation createJobcreateJob Create job object in scheduler and client createTaskcreateTask Create new task in job dfevaldfeval Evaluate function using cluster Interlab Communication Within a Parallel Job labBarrierlabBarrier Block execution until all labs reach this call labBroadcastlabBroadcast Send data to all labs or receive data sent to all labs labindexlabindex Index of this lab labReceivelabReceive Receive data from another lab labSendlabSend Send data to another lab numlabsnumlabs Total number of labs operating in parallel on current job Job Management cancelcancel Cancel job or task destroy Remove job or task object from parent and memorydestroy getAllOutputArgumentsgetAllOutputArguments Output arguments from evaluation of all tasks in job object submitsubmit Queue job in scheduler waitwait Wait for job to finish or change states

Parallel for-Loops (parfor) execute individual loop iterations simultaneously Large Data Sets distribute that array among multiple MATLAB workers, so that each worker processes only a part of the array Batch Jobs the MATLAB worker can run either on the same machine as the client, or if using MATLAB Distributed Computing Server, on a remote cluster machine. Typical Use Cases

Parallel mode-I: matlabpool Open or close a pool of MATLAB sessions for parallel computation Syntax: MATLABPOOL MATLABPOOL OPEN MATLABPOOL CLOSE MATLABPOOL CLOSE FORCE …… Work on local client PC Without open matlabpool, parallel code will still run but runs sequentially

Task Parallel applications parallel problems by organizing them into independent tasks (units of work) - parallelize Monte Carlo simulations Parallel for-Loops (parfor) parfor (i = 1 : n) % do something with i end - Mix task parallel and serial code in the same function - Run loops on a pool of MATLAB resources - Iterations must be order-independent

matlabpool -Demo

Iterations run in parallel in the MATLAB pool (local workers)

Run a.m file -Demo

Data Parallel applications Single Program Multiple Data (spmd) spmd (n) end For example, create a random matrix on four labs: matlabpool open spmd (2) R = rand(4,4); end matlabpool close create different sized arrays depending on labindex: matlabpool open spmd (2) if labindex==1 R = rand(4,4); else R = rand(2,2); end matlabpool close

Demo

Batch mode Name a.m file as ‘mybatch’ with for i=1:1024 A(i) = sin(i*2*pi/1024); end run in batch mode job = batch('mybatch') The batch command does not block MATLAB, so you must wait for the job to finish before you can retrieve and view its results: wait(job) The load command transfers variables from the workspace of the worker to the workspace of the client, where you can view the results: load(job, 'A') plot(A) When the job is complete, permanently remove its data: destroy(job)

A batch parallel loop % mybatch parfor i=1:1024 A(i) = sin(i*2*pi/1024); end % run job in batch job = batch('mybatch', ‘configuration, ‘local’, 'matlabpool', 2) % To view the results: wait(job) load(job, 'A') plot(A) % remove its data: destroy(job)

Parellel mode-II: pmode >> pmode start P>> pmode exit

pmode demo P>> help magic % ask for help on a function P>> PI = pi % set a variable on all the labs P>> myid = labindex % lab ID P>> all = numlabs % total No. of labs P>> segment = [1 2; 3 4; 5 6] % create a replicated array on all the labs P>> segment = segment + 10*labindex % perform on different labs P>> x = magic(4) % replicated on every lab P>> y=codistirbuted(x) % partitioned among the lab P>> z = y + 10*labindex % operate on the distributed array whole P>> combined = gather(y) % entire array in one workspace The combined is now a 4-by-4 array in the client workspace. whos combined To see the array, type its name. combined

Demo: distributed array operations (repeat)

Parallel pi in pmode use the fact that to approximate pi by approximating the integral on the left. divide the work between the labs by having each lab calculate the integral the function over a subinterval of [0, 1] as shown in the picture

Steps All labs/workers will compute the same function: F=4/(1+x^2) Each worker/lab will calculate over a subinterval [a,b] of [0, 1], for 2 labs, the subinterval will be: [0, 0.50] [0.50, 1.0] a = (labindex-1)/numlabs b = labindex/numlabs Use a MATLAB quadrature method to compute the integral myIntegral = quadl(F, a, b) Add together to form the entire integral over [0,1] piApprox = gplus(myIntegral)

Parallel pi in matlabpool-mode

Example with Communication In this example, four labs run a parallel job with a 4-by-4 magic square. The first lab broadcasts the matrix with labBroadcast to all the other labs, each of which calculates the sum of one column of the matrix. All of these column sums are combined with the gplus function to calculate the total sum of the elements of the original magic square. The function for this example is shown below. function total_sum = colsum if labindex == 1 % Send magic square to other labs A = labBroadcast(1,magic(numlabs)) else % Receive broadcast on other labs A = labBroadcast(1) end % Calculate sum of column identified by labindex for this lab column_sum = sum(A(:,labindex)) % Calculate total sum by combining column sum from all labs total_sum = gplus(column_sum) DEMO: colsum.m, colsum_submit.m

paralleltestfunction.m

Takeaway: Parallel Matlab Provides: –Parallel processing constructs such as parallel for-loops and code blocks –distributed arrays –parallel numerical algorithms, –and message-passing functions Run your applications interactively on a local machine, or in batch environments on a remote server.

References computing/?s_cid=HP_FP_ML_parallelcomptbx