L15: Putting it together: N-body (Ch. 6) October 30, 2012.

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
Advertisements

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Practical techniques & Examples
Its.unc.edu 1 Collective Communication University of North Carolina - Chapel Hill ITS - Research Computing Instructor: Mark Reed
MPI Collective Communications
1 Collective Operations Dr. Stephen Tse Lesson 12.
Sahalu Junaidu ICS 573: High Performance Computing 8.1 Topic Overview Matrix-Matrix Multiplication Block Matrix Operations A Simple Parallel Matrix-Matrix.
MPI_Gatherv CISC372 Fall 2006 Andrew Toy Tom Lynch Bill Meehan.
MPI_AlltoAllv Function Outline int MPI_Alltoallv ( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype sendtype, void *recvbuf, int *recvcnts, int.
CISC October Goals for today: Foster’s parallel algorithm design –Partitioning –Task dependency graph Granularity Concurrency Collective communication.
A Message Passing Standard for MPP and Workstations Communications of the ACM, July 1996 J.J. Dongarra, S.W. Otto, M. Snir, and D.W. Walker.
SOME BASIC MPI ROUTINES With formal datatypes specified.
Chapter 6 Floyd’s Algorithm. 2 Chapter Objectives Creating 2-D arrays Thinking about “grain size” Introducing point-to-point communications Reading and.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 8 Matrix-vector Multiplication.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
MPI Workshop - II Research Staff Week 2 of 3.
Collective Communication.  Collective communication is defined as communication that involves a group of processes  More restrictive than point to point.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Principles of Parallel Programming First Edition by Calvin Lin Lawrence Snyder.
Distributed Systems CS Programming Models- Part II Lecture 17, Nov 2, 2011 Majd F. Sakr, Mohammad Hammoud andVinay Kolar 1.
Today Objectives Chapter 6 of Quinn Creating 2-D arrays Thinking about “grain size” Introducing point-to-point communications Reading and printing 2-D.
1 TRAPEZOIDAL RULE IN MPI Copyright © 2010, Elsevier Inc. All rights Reserved.
L20: Putting it together: Tree Search (Ch. 6) November 29, 2011.
Exercise problems for students taking the Programming Parallel Computers course. Janusz Kowalik Piotr Arlukowicz Tadeusz Puzniakowski Informatics Institute.
Lecture 10 CSS314 Parallel Computing
Chapter 6 Parallel Sorting Algorithm Sorting Parallel Sorting Bubble Sort Odd-Even (Transposition) Sort Parallel Odd-Even Transposition Sort Related Functions.
Parallel Programming and Algorithms – MPI Collective Operations David Monismith CS599 Feb. 10, 2015 Based upon MPI: A Message-Passing Interface Standard.
2a.1 Message-Passing Computing More MPI routines: Collective routines Synchronous routines Non-blocking routines ITCS 4/5145 Parallel Computing, UNC-Charlotte,
1 Collective Communications. 2 Overview  All processes in a group participate in communication, by calling the same function with matching arguments.
Chapter 3 Parallel Algorithm Design. Outline Task/channel model Task/channel model Algorithm design methodology Algorithm design methodology Case studies.
L21: Final Preparation and Course Retrospective (also very brief introduction to Map Reduce) December 1, 2011.
PP Lab MPI programming VI. Program 1 Break up a long vector into subvectors of equal length. Distribute subvectors to processes. Let them compute the.
Parallel Programming with MPI Prof. Sivarama Dandamudi School of Computer Science Carleton University.
L17: Introduction to “Irregular” Algorithms and MPI, cont. November 8, 2011.
CS 838: Pervasive Parallelism Introduction to MPI Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from an online tutorial.
Message Passing Programming Model AMANO, Hideharu Textbook pp. 140-147.
Design Issues. How to parallelize  Task decomposition  Data decomposition  Dataflow decomposition Jaruloj Chongstitvatana 2 Parallel Programming: Parallelization.
MPI (continue) An example for designing explicit message passing programs Advanced MPI concepts.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Principles of Parallel Programming First Edition by Calvin Lin Lawrence Snyder.
Parallel Programming with MPI By, Santosh K Jena..
Lecture 4 TTH 03:30AM-04:45PM Dr. Jianjun Hu CSCE569 Parallel Computing University of South Carolina Department of.
CSCI-455/522 Introduction to High Performance Computing Lecture 4.
L17: MPI, cont. October 25, Final Project Purpose: -A chance to dig in deeper into a parallel programming model and explore concepts. -Research.
1 BİL 542 Parallel Computing. 2 Message Passing Chapter 2.
An Efficient CUDA Implementation of the Tree-Based Barnes Hut n-body Algorithm By Martin Burtscher and Keshav Pingali Jason Wengert.
L19: Putting it together: N-body (Ch. 6) November 22, 2011.
1/46 PARALLEL SOFTWARE ( SECTION 2.4). 2/46 The burden is on software From now on… In shared memory programs: Start a single process and fork threads.
Message Passing Programming Based on MPI Collective Communication I Bora AKAYDIN
Distributed Systems CS Programming Models- Part II Lecture 14, Oct 28, 2013 Mohammad Hammoud 1.
COMP7330/7336 Advanced Parallel and Distributed Computing MPI Programming: 1. Collective Operations 2. Overlapping Communication with Computation Dr. Xiao.
ITCS 4/5145 Parallel Computing, UNC-Charlotte, B
Computer Science Department
Parallel Programming By J. H. Wang May 2, 2017.
CS4402 – Parallel Computing
Computer Science Department
Parallel Programming in C with MPI and OpenMP
L21: Putting it together: Tree Search (Ch. 6)
Parallel Programming with MPI and OpenMP
An Introduction to Parallel Programming with MPI
Collective Communication Operations
CSCE569 Parallel Computing
Distributed Systems CS
CSCE569 Parallel Computing
All-to-All Pattern A pattern where all (slave) processes can communicate with each other Somewhat the worst case scenario! ITCS 4/5145 Parallel Computing,
All-to-All Pattern A pattern where all (slave) processes can communicate with each other Somewhat the worst case scenario! ITCS 4/5145 Parallel Computing,
Barriers implementations
Hardware Environment VIA cluster - 8 nodes Blade Server – 5 nodes
Parallel Programming in C with MPI and OpenMP
Synchronizing Computations
Computer Science Department
Presentation transcript:

L15: Putting it together: N-body (Ch. 6) October 30, 2012

Outline Review MPI Communication -Blocking -Non-Blocking -One-Sided -Point-to-Point vs. Collective Chapter 6 shows two algorithms (N-body and Tree Search) written in the three programming models (OpenMP, Pthreads, MPI) -How to approach parallelization of an entire algorithm (Foster’s methodology is used in the book) -What do you have to worry about that is different for each programming model?

Review p2p example: 2D relaxation Replaces each interior value by the average of its four nearest neighbors. Sequential code: for (i=1; i<n-1; i++) for (j=1; j<n-1; j++) b[i,j] = (a[i-1][j]+a[i][j-1]+ a[i+1][j]+a[i][j+1])/4.0; Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 10/25/2012CS4230

MPI code, main loop of 2D SOR computation Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 10/25/2012CS4230

MPI code, main loop of 2D SOR computation, cont. Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 10/25/2012CS4230

MPI code, main loop of 2D SOR computation, cont. Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 10/25/2012CS4230

Question: Does this lead to deadlock? No! Why not? Even though communication is blocking, -Send returns when MPI library on receiving end acknowledges that data has been received -The receiving process may not yet have received the data -So, a sequence of blocking Sends will not block What about receives? -Receiving process must wait until data arrives before proceeding -A sequence of blocking receives must be received in order 11/09/10

Foster’s methodology (Chapter 2) 1.Partitioning: divide the computation to be performed and the data operated on by the computation into small tasks. The focus here should be on identifying tasks that can be executed in parallel. 2.Communication: determine what communication needs to be carried out among the tasks identified in the previous step. 3.Agglomeration or aggregation: combine tasks and communications identified in the first step into larger tasks. For example, if task A must be executed before task B can be executed, it may make sense to aggregate them into a single composite task. 4.Mapping: assign the composite tasks identified in the previous step to processes/threads. This should be done so that communication is minimized, and each process/thread gets roughly the same amount of work. Copyright © 2010, Elsevier Inc. All rights Reserved

The n-body problem Find the positions and velocities of a collection of interacting particles over a period of time. An n-body solver is a program that finds the solution to an n-body problem by simulating the behavior of the particles. Copyright © 2010, Elsevier Inc. All rights Reserved mass Position time 0 Velocity time 0 N-body solver Position time x Velocity time x

2. Overlying mesh defined 1. Lagrangian material points carry all state data (position, velocity, stress, etc.) 5. Particle positions/velocities updated from mesh solution. 6. Discard deformed mesh. Define new mesh and repeat Example N-Body: Material Point Method (MPM) 3. Particle state projected to mesh, e.g.: 4. Conservation of momentum solved on mesh giving updated mesh velocity and (in principal) position. Stress at particles computed based on gradient of the mesh velocity. 6 10

Copyright © 2010, Elsevier Inc. All rights Reserved Calculate Force as a function of mass and positions Force between two particles Total force on a particle

Copyright © 2010, Elsevier Inc. All rights Reserved Calculate acceleration

Serial pseudo-code: calculates position of particles at each time step Copyright © 2010, Elsevier Inc. All rights Reserved

Computation of the forces: Basic Algorithm Copyright © 2010, Elsevier Inc. All rights Reserved For all pairs (except ) compute Total Force

Copyright © 2010, Elsevier Inc. All rights Reserved Computation of the forces: Reduced Algorithm Reduce calculation of Total Force, capitalizing on f qk = -f kq Compute half the pairs

Compute position using Euler’s Method Copyright © 2010, Elsevier Inc. All rights Reserved Use tangent to compute position at later time step

OpenMP parallelization: Basic Algorithm Copyright © 2010, Elsevier Inc. All rights Reserved For all pairs (except ) compute Total Force Parallelization? Scheduling?

Copyright © 2010, Elsevier Inc. All rights Reserved Computation of the forces: Reduced Algorithm Reduce calculation of Total Force, capitalizing on f qk = -f kq Compute half the pairs Parallelization? Scheduling?

Other topics on OpenMP parallelization Data structure choice – group together in structure or separate arrays? Thread creation Alternative synchronization (reduced method) Private data (reduced method) Nowait I/O (single)

What’s different with Pthreads Must write more code to do basic OpenMP things: Create threads, pass parameters, determine number and mapping of iterations and initiate “parallel loop” Explicit barriers between “loops” Explicit synchronization Explicit declaration of global data that is shared, or thread-local declaration of private data

Choices with respect to the data structures: -Each process stores the entire global array of particle masses. -Each process only uses a single n-element array for the positions. -Each process uses a pointer loc_pos that refers to the start of its block of pos. -So on process 0 local_pos = pos; on process 1 local_pos = pos + loc_n; etc. Copyright © 2010, Elsevier Inc. All rights Reserved MPI Parallelization: Basic version

Copyright © 2010, Elsevier Inc. All rights Reserved

Detour: MPI_Scatter() Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Distribute Data from input using a scatter operation Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

MPI_Gather is analogous MPI_Gather: Gathers together values from a group of processes int MPI_Gather(void *sendbuf, int sendcnt, MPI_Datatype sendtype, void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm) Input Parameters sendbuf starting address of send buffer (choice) sendcount number of elements in send buffer (integer) sendtype data type of send buffer elements (handle) recvcount number of elements for any single receive (integer, significant only at root) recvtype data type of recv buffer elements (significant only at root) (handle) root rank of receiving process (integer) comm communicator (handle) Output Parameter recvbuf address of receive buffer (choice, significant only at root)

Detour: MPI_Allgather (a collective) MPI_Allgather: Gathers data from all tasks and distributes the combined data to all tasks int MPI_Allgather (void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) Input Parameters sendbuf starting address of send buffer (choice) sendcount number of elements in send buffer (integer) sendtype data type of send buffer elements (handle) recvcount number of elements received from any process (integer) recvtype data type of receive buffer elements (handle) comm communicator (handle) Output Parameter recvbufaddress of receive buffer (choice)

I/O: Ch. 6, p. 291 if (my_rank == 0) { for each particle, read masses[particle], pos[particle], vel[particle]; } MPI_Bcast(masses, n, MPI_DOUBLE, 0, comm); MPI_Bcast(pos, n, vect_mpi_t, loc_vel, loc_n, vect_mpi_t, 0, comm) MPI_Scatter(vel, loc_n, vect_mpi_t, 0, comm);

MPI Issues Communicating standard data types performs much better than derived data types like structures Separate fields (position, velocity, mass) into arrays that can be communicated independently Is it feasible for each processor to have all of the processor mass data locally? The position data? Depends on how many bodies and capacity constraints

MPI Parallelization: Basic version Copyright © 2010, Elsevier Inc. All rights Reserved

Communication In A Possible MPI Implementation of the N-Body Solver (for a reduced solver) Copyright © 2010, Elsevier Inc. All rights Reserved

Ring Pass of Positions Copyright © 2010, Elsevier Inc. All rights Reserved

Pseudo-code for the MPI implementation of the reduced n-body solver Copyright © 2010, Elsevier Inc. All rights Reserved

Loops iterating through global particle indexes Copyright © 2010, Elsevier Inc. All rights Reserved