MPI Groups, Communicators and Topologies. Groups and communicators In our case studies, we saw examples where collective communication needed to be performed.

Slides:



Advertisements
Similar presentations
MPI Basics Introduction to Parallel Programming and Cluster Computing University of Washington/Idaho State University MPI Basics Charlie Peck Earlham College.
Advertisements

Chapter 3. MPI MPI = Message Passing Interface Specification of message passing libraries for developers and users –Not a library by itself, but specifies.
1 Parallel Programming with MPI- Day 4 Science & Technology Support High Performance Computing Ohio Supercomputer Center 1224 Kinnear Road Columbus, OH.
1 Process Groups & Communicators  Communicator is a group of processes that can communicate with one another.  Can create sub-groups of processes, or.
Virtual Topologies Self Test with solution. Self Test 1.When using MPI_Cart_create, if the cartesian grid size is smaller than processes available in.
Reference: / MPI Program Structure.
MPI Program Structure Self Test with solution. Self Test 1.How would you modify "Hello World" so that only even-numbered processors print the greeting.
MPI_Gatherv CISC372 Fall 2006 Andrew Toy Tom Lynch Bill Meehan.
Communicators. Introduction So far, the communicator that you are familiar with is MPI_COMM_WORLD. This is a communicator defined by MPI to permit all.
1 Friday, October 20, 2006 “Work expands to fill the time available for its completion.” -Parkinson’s 1st Law.
Introduction to MPI. What is Message Passing Interface (MPI)?  Portable standard for communication  Processes can communicate through messages.  Each.
Comp 422: Parallel Programming Lecture 8: Message Passing (MPI)
MPI Majdi Baddourah. Domain Decomposition Communication 160 Cells80 Cells.
1 Tuesday, October 31, 2006 “Data expands to fill the space available for storage.” -Parkinson’s Law.
1 Tuesday, October 10, 2006 To err is human, and to blame it on a computer is even more so. -Robert Orben.
Research Computing UNC - Chapel Hill Instructor: Mark Reed Group and Communicator Management Routines.
CS 179: GPU Programming Lecture 20: Cross-system communication.
IBM Research © 2006 IBM Corporation CDT Static Analysis Features CDT Developer Summit - Ottawa Beth September.
Director of Contra Costa College High Performance Computing Center
Chapter 6 Parallel Sorting Algorithm Sorting Parallel Sorting Bubble Sort Odd-Even (Transposition) Sort Parallel Odd-Even Transposition Sort Related Functions.
1 MPI: Message-Passing Interface Chapter 2. 2 MPI - (Message Passing Interface) Message passing library standard (MPI) is developed by group of academics.
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.
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.
Summary of MPI commands Luis Basurto. Large scale systems Shared Memory systems – Memory is shared among processors Distributed memory systems – Each.
MPI Introduction to MPI Commands. Basics – Send and Receive MPI is a message passing environment. The processors’ method of sharing information is NOT.
Distributed-Memory (Message-Passing) Paradigm FDI 2004 Track M Day 2 – Morning Session #1 C. J. Ribbens.
2.1 Message-Passing Computing Cluster Computing, UNC B. Wilkinson, 2007.
PP Lab MPI programming II. Program#1 Write a program that prints hello from every created process. Like: Hello World from process 0 of 5 Hello World from.
Parallel Programming with MPI By, Santosh K Jena..
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd Edition, by B. Wilkinson & M. Allen, ©
CSCI-455/522 Introduction to High Performance Computing Lecture 4.
1 Message Passing Models CEG 4131 Computer Architecture III Miodrag Bolic.
Chapter 4 Message-Passing Programming. The Message-Passing Model.
Task/ChannelMessage-passing TaskProcess Explicit channelsMessage communication.
Introduction to MPI CDP 1. Shared Memory vs. Message Passing Shared Memory Implicit communication via memory operations (load/store/lock) Global address.
MPI Workshop - III Research Staff Cartesian Topologies in MPI and Passing Structures in MPI Week 3 of 3.
1. 2 The logical view of a machine supporting the message-passing paradigm consists of p processes, each with its own exclusive address space. The logical.
An Introduction to MPI (message passing interface)
Timing in MPI Tarik Booker MPI Presentation May 7, 2003.
MPI Chapter 3 More Beginning MPI. MPI Philosopy One program for all processes – Starts with init – Get my process number Process 0 is usually the “Master”
3/12/2013Computer Engg, IIT(BHU)1 MPI-1. MESSAGE PASSING INTERFACE A message passing library specification Extended message-passing model Not a language.
Message Passing Interface Using resources from
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
PVM and MPI.
Introduction to MPI Programming Ganesh C.N.
MPI Basics.
Auburn University COMP7330/7336 Advanced Parallel and Distributed Computing Message Passing Interface (cont.) Topologies.
CS4402 – Parallel Computing
MPI Message Passing Interface
Send and Receive.
CS 584.
MPI Groups, Communicators and Topologies
Send and Receive.
Programming Using the Message Passing Model
ITCS 4/5145 Parallel Computing, UNC-Charlotte, B
Message Passing Models
CSC 6750: Parallel Programming Fall 2009
Lecture 14: Inter-process Communication
MPI: Message Passing Interface
Parallel Programming with MPI- Day 4
Lab Course CFD Parallelisation Dr. Miriam Mehl.
Hardware Environment VIA cluster - 8 nodes Blade Server – 5 nodes
5- Message-Passing Programming
Parallel Processing - MPI
MPI Message Passing Interface
Some codes for analysis and preparation for programming
CS 584 Lecture 8 Assignment?.
Presentation transcript:

MPI Groups, Communicators and Topologies

Groups and communicators In our case studies, we saw examples where collective communication needed to be performed by subsets of the processes in the computation –(eg) 2-D version of MVM MPI provides routines for –defining new process groups from subsets of existing process groups like MPI_COMM_WORLD –creating a new communicator for a new process group –performing collective communication within that process group –organizing process groups into virtual topologies: most common use: permits processes within a group to be given multidimensional numbers rather than the standard 0...n-1 numbering

Groups and communicators

Facts about groups and communicators Group: –ordered set of processes –each process in group has a unique integer id called its rank within that group –process can belong to more than one group rank is always relative to a group –groups are “opaque objects” use only MPI provided routines for manipulating groups Communicators: –all communication must specify a communicator –from the programming viewpoint, groups and communicators are equivalent –why distinguish between groups and communicators? sometimes you want to create two communicators for the same group useful for supporting libraries –communicators are also “opaque objects” Groups and communicators are dynamic objects and can be created and destroyed during the execution of the program

Typical usage 1.Extract handle of global group from MPI_COMM_WORLD using MPI_Comm_group 2.Form new group as a subset of global group using MPI_Group_incl or MPI_Group_excl 3.Create new communicator for new group using MPI_Comm_create 4.Determine new rank in new communicator using MPI_Comm_rank 5.Conduct communications using any MPI message passing routine 6.When finished, free up new communicator and group (optional) using MPI_Comm_free and MPI_Group_free

Details MPI_Group_excl: –create a new group by removing certain processes from existing group –int MPI_Group_excl(MPI_Group group,int n,int *ranks, MPI_Group *newgroup); –ranks: array of size n containing ranks to be excluded MPI_Group_incl: –create a new group from certain selected processes from existing group –int MPI_Group_incl(MPI_Group group,int n,int *ranks, MPI_Group *newgroup); –ranks: array of size n containing ranks to be included

main(int argc, char **argv) { int me, count, count2; void *send_buf, *recv_buf, *send_buf2, *recv_buf2; MPI_Group MPI_GROUP_WORLD, grprem; MPI_Comm commslave; static int ranks[] = {0}; MPI_Init(&argc, &argv); MPI_Comm_group(MPI_COMM_WORLD, &MPI_GROUP_WORLD); MPI_Comm_rank(MPI_COMM_WORLD, &me); MPI_Group_excl(MPI_GROUP_WORLD, 1, ranks, &grprem); MPI_Comm_create(MPI_COMM_WORLD, grprem, &commslave); if(me != 0){ /* compute on slave */ MPI_Reduce(send_buf,recv_buff,count, MPI_INT, MPI_SUM, 1, commslave); } /* zero falls through immediately to this reduce, others do later... */ MPI_Reduce(send_buf2, recv_buff2, count2, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Comm_free(&commslave); MPI_Group_free(&MPI_GROUP_WORLD); MPI_Group_free(&grprem); MPI_Finalize(); }

#include “mpi.h” #include #define NPROCS 8 int main(argc,argv) int argc; char *argv[]; { int rank, new_rank, sendbuf, recvbuf, numtasks, ranks1[4]={0,1,2,3}, ranks2[4]={4,5,6,7}; MPI_Group orig_group, new_group; MPI_Comm new_comm; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); sendbuf = rank; /* Extract the original group handle */ MPI_Comm_group(MPI_COMM_WORLD, &orig_group); /* Divide tasks into two distinct groups based upon rank */ if (rank < NPROCS/2) { MPI_Group_incl(orig_group, NPROCS/2, ranks1, &new_group); } else { MPI_Group_incl(orig_group, NPROCS/2, ranks2, &new_group); } /* Create new new communicator and then perform collective communications */ MPI_Comm_create(MPI_COMM_WORLD, new_group, &new_comm); MPI_Allreduce(&sendbuf, &recvbuf, 1, MPI_INT, MPI_SUM, new_comm); MPI_Group_rank (new_group, &new_rank); printf("rank= %d newrank= %d recvbuf= %d\n",rank,new_rank,recvbuf); MPI_Finalize(); } Sample output: rank= 7 newrank= 3 recvbuf= 22 rank= 0 newrank= 0 recvbuf= 6 rank= 1 newrank= 1 recvbuf= 6 rank= 2 newrank= 2 recvbuf= 6 rank= 6 newrank= 2 recvbuf= 22 rank= 3 newrank= 3 recvbuf= 6 rank= 4 newrank= 0 recvbuf= 22 rank= 5 newrank= 1 recvbuf= 22

Virtual topologies Current view of group/communicator: one dimensional numbering In many algorithms, it is convenient to view the processes as being arranged in a grid of some number of dimensions One approach: perform the translation from grid co-ordinates to 1D numbers yourself –Hard to write the program –Even harder to read the program MPI solution: –routines for letting you view processes as if they were organized in grid of some dimension –MPI also permits you to organize processes logically into general graphs but we will not worry about this Key routines: –MPI_Cart_Create: create a grid from an existing 1D communicator int MPI_Cart_create ( MPI_Comm comm_old, int ndims, int *dims, int *periods, int reorder, MPI_Comm *comm_cart ) periods: array of booleans to specify wrap-around in each dimension reorder: can ranks be reordered or not? Ignored by most MPI implementations –MPI_Cart_get: my grid coordinates –MPI_Cart_rank: grid coordinates  1D rank –MPI_Cart_shift: offset in some grid dimension  1D rank of sender and receiver

#include #define NP 3 main(int argc, char **argv){ /* Grid setup for 3x3 Grid */ …….. /* MPI Cartesian Grid information */ int ivdim[2] = {NP,NP}, ivper[2]={1,1}; int ivdimx[2], ivperx[2], mygrid[2]; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &npes); MPI_Comm_rank(MPI_COMM_WORLD, &mype); /* Create Cartesian Grid and extract information */ MPI_Cart_create(MPI_COMM_WORLD,2,ivdim,ivper, 0,&igcomm); MPI_Cart_get( igcomm,2,ivdimx,ivperx, mygrid); MPI_Cart_shift( igcomm,1,1, &isrca,&idesa); //column offset of +1 myrow=mygrid[0]; mycol=mygrid[1]; printf("A (%d) [%d,%d]: %2d ->%2d\n",mype,myrow,mycol,isrca,idesa); MPI_Finalize(); }

Output mype[myrow, mycol] srcdst 0[0,0]21 1[0,1]02 2[0,2]10 3[1,0]54 4[1,1]35 5[1,2]43 6[2,0]87 7[2,1]68 8[2,2]76

General splitting of communicators MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm) This is a very powerful routine for splitting a communicator into some number of smaller communicators (depending on color) and assigning ranks within the new communicators Will be useful for 2D MVM: split MPI_COMM_WORLD twice, once to define row communicators and once to define column communicators use row & column indices in Cartesian topology as colors for calls to Comm_split

#include main(int argc, char **argv) { MPI_Comm row_comm, col_comm; int myrank, size, P=4, Q=3, p, q; MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &myrank); MPI_Comm_size (MPI_COMM_WORLD, &size); /* Determine row and column position */ p = myrank / Q; q = myrank % Q; /* pick a row-major mapping */ /* Split comm into row and column comms */ MPI_Comm_split(MPI_COMM_WORLD, p, q, &row_comm); /* color by row, rank by column */ MPI_Comm_split(MPI_COMM_WORLD, q, p, &col_comm); /* color by column, rank by row */ printf("[%d]:My coordinates are (%d,%d)\n",myrank,p,q); MPI_Finalize(); }