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.

Slides:



Advertisements
Similar presentations
Sahalu Junaidu ICS 573: High Performance Computing 8.1 Topic Overview Matrix-Matrix Multiplication Block Matrix Operations A Simple Parallel Matrix-Matrix.
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.
Introduction to MPI Programming (Part III)‏ Michael Griffiths, Deniz Savas & Alan Real January 2006.
1 Process Groups & Communicators  Communicator is a group of processes that can communicate with one another.  Can create sub-groups of processes, or.
Reference: / MPI Program Structure.
MPI Program Performance Self Test with solution. Matching 1.Amdahl's Law 2.Profiles 3.Relative efficiency 4.Load imbalances 5.Timers 6.Asymptotic analysis.
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.
Getting Started with MPI Self Test with solution.
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.
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.
Point-to-Point Communication Self Test with solution.
Collective Communications Self Test with solution.
1 Parallel Programming with MPI: Day 1 Science & Technology Support High Performance Computing Ohio Supercomputer Center 1224 Kinnear Road Columbus, OH.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 8 Matrix-vector Multiplication.
Page 1 Parallel Programming With MPI Self Test. Page 2 Message Passing Fundamentals.
Comp 422: Parallel Programming Lecture 8: Message Passing (MPI)
Communicators Self Test with solution. Self Test 1.MPI_Comm_group may be used to: a)create a new group. b)determine group handle of a communicator. c)create.
Derived Datatypes and Related Features Self Test with solution.
Collective Communications Solution. #include #define N 300 int main(int argc, char **argv) { int i, target;/*local variables*/ int b[N], a[N/4];/*a is.
CS102--Object Oriented Programming Lecture 6: – The Arrays class – Multi-dimensional arrays Copyright © 2008 Xiaoyan Li.
MPI Point-to-Point Communication CS 524 – High-Performance Computing.
ECE 1747H : Parallel Programming Message Passing (MPI)
1 MPI: Message-Passing Interface Chapter 2. 2 MPI - (Message Passing Interface) Message passing library standard (MPI) is developed by group of academics.
1 Why Derived Data Types  Message data contains different data types  Can use several separate messages  performance may not be good  Message data.
Parallel Processing1 Parallel Processing (CS 676) Lecture: Grouping Data and Communicators in MPI Jeremy R. Johnson *Parts of this lecture was derived.
Parallel Programming with MPI Prof. Sivarama Dandamudi School of Computer Science Carleton University.
Message Passing Programming with MPI Introduction to MPI Basic MPI functions Most of the MPI materials are obtained from William Gropp and Rusty Lusk’s.
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.
CS4402 – Parallel Computing
CS 591 x I/O in MPI. MPI exists as many different implementations MPI implementations are based on MPI standards MPI standards are developed and maintained.
Parallel Programming & Cluster Computing MPI Collective Communications Dan Ernst Andrew Fitz Gibbon Tom Murphy Henry Neeman Charlie Peck Stephen Providence.
CSCI-455/522 Introduction to High Performance Computing Lecture 4.
1 Message Passing Models CEG 4131 Computer Architecture III Miodrag Bolic.
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)
Project18 Communication Design + Parallelization Camilo A Silva BIOinformatics Summer 2008.
April 24, 2002 Parallel Port Example. April 24, 2002 Introduction The objective of this lecture is to go over a simple problem that illustrates the use.
Grouping Data and Derived Types in MPI. Grouping Data Messages are expensive in terms of performance Grouping data can improve the performance of your.
MPI Groups, Communicators and Topologies. Groups and communicators In our case studies, we saw examples where collective communication needed to be performed.
MPI Derived Data Types and Collective Communication
Message Passing Interface Using resources from
Lecture 3 Point-to-Point Communications Dr. Muhammad Hanif Durad Department of Computer and Information Sciences Pakistan Institute Engineering and Applied.
CS 116 Object Oriented Programming II Lecture 13 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
COMP7330/7336 Advanced Parallel and Distributed Computing MPI Programming: 1. Collective Operations 2. Overlapping Communication with Computation Dr. Xiao.
Introduction to MPI Programming Ganesh C.N.
Research Staff Passing Structures in MPI Week 3 of 3
Introduction to parallel computing concepts and technics
Auburn University COMP7330/7336 Advanced Parallel and Distributed Computing Message Passing Interface (cont.) Topologies.
Introduction to MPI.
MPI Message Passing Interface
Parallel Programming in C with MPI and OpenMP
Send and Receive.
CS 584.
MPI Groups, Communicators and Topologies
Send and Receive.
CSCE569 Parallel Computing
Parallel Processing - MPI
Lecture 14: Inter-process Communication
Parallel Programming with MPI- Day 4
Pattern Programming Tools
Distributed Memory Programming with Message-Passing
MPI Message Passing Interface
CS 584 Lecture 8 Assignment?.
Presentation transcript:

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 old_comm, then: a)error results. b)new_comm returns MPI_COMM_NULL for calling processes not used for grid. c)new_comm returns MPI_UNDEFINED for calling processes not used for grid.

Self Test 2.When using MPI_Cart_create, if the cartesian grid size is larger than processes available in old_comm, then: a)error results. b)the cartesian grid is automatically reduced to match processes available in old_comm. c)more processes are added to match the requested cartesian grid size if possible; otherwise error results.

Self Test 3.After using MPI_Cart_create to generate a cartesian grid with grid size smaller than processes available in old_comm, a call to MPI_Cart_coords or MPI_Cart_rank unconditionally(i.e., without regard to whether it is appropriate to call) ends in error because: a)calling processes not belonging to group have been assigned the communicator MPI_UNDEFINED, which is not a valid communicator for MPI_Cart_coords or MPI_Cart_rank. b)calling processes not belonging to group have been assigned the communicator MPI_COMM_NULL, which is not a valid communicator for MPI_Cart_coords or MPI_Cart_rank. c)grid size does not match what is in old_comm.

Self Test 4.When using MPI_Cart_rank to translate cartesian coordinates into equivalent rank, if some or all of the indices of the coordinates are outside of the defined range, then a)error results. b)error results unless periodicity is imposed in all dimensions. c)error results unless each of the out-of-range indices is periodic.

Self Test 5.With MPI_Cart_shift(comm, direction, displ, source, dest), if the calling process is the first or the last entry along the shift direction and that displ is greater than 0, then a)error results. b)MPI_Cart_shift returns source and dest if periodicity is imposed along the shift direction. Otherwise, source and/or dest return MPI_UNDEFINED. c)error results unless periodicity is imposed along the shift direction.

Self Test 6.MPI_Cart_sub can be used to subdivide a cartesian grid into subgrids of lower dimensions. These subgrids a)have dimensions one lower than the original grid. b)attributes such as periodicity must be reimposed. c)possess appropriate attributes of the original cartesian grid.

Answer 1.B 2.A 3.B 4.C 5.B 6.C

Course Problem Description –The new problem still implements a parallel search of an integer array. The program should find all occurrences of a certain integer which will be called the target. When a processor of a certain rank finds a target location, it should then calculate the average of The target value An element from the processor with rank one higher (the "right" processor). The right processor should send the first element from its local array. An element from the processor with rank one less (the "left" processor). The left processor should send the first element from its local array.

Course Problem For example, if processor 1 finds the target at index 33 in its local array, it should get from processors 0 (left) and 2 (right) the first element of their local arrays. These three numbers should then be averaged. In terms of right and left neighbors, you should visualize the four processors connected in a ring. That is, the left neighbor for P0 should be P3, and the right neighbor for P3 should be P0. Both the target location and the average should be written to an output file. As usual, the program should read both the target value and all the array elements from an input file.

Course Problem Exercise –Modify your code from Chapter 7 to solve this latest version of the Course Problem using a virtual topology. First, create the topology (which should be called MPI_RING) in which the four processors are connected in a ring. Then, use the utility routines to determine which neighbors a given processor has.

Solution Note: The sections of code shown in red are new code in which the MPI_RING virtual topology is created. The section of code in blue is where the new topology is used by each processor to determine its left and right neighbors.

Solution #include #define N 300 int main(int argc, char **argv) { int i, target;/*local variables*/ int b[N], a[N/4];/*a is name of the array each slave searches*/ int rank, size, err; MPI_Status status; int end_cnt; FILE *sourceFile; FILE *destinationFile; int left, right;/*the left and right processes*/ int lx, rx;/*store the left and right elements*/ int gi;/*global index*/ float ave;/*average*/

Solution int blocklengths[2] = {1, 1};/* initialize blocklengths array */ MPI_Datatype types[2] = {MPI_INT, MPI_FLOAT};/* initialize types array */ MPI_Datatype MPI_Pair; MPI_Aint displacements[2]; MPI_Comm MPI_RING;/* Name of the new cartesian topology */ int dim[1];/* Number of dimensions */ int period[1], reorder;/* Logical array to control if the dimension should "wrap-around" */ int coord[1];/* Coordinate of the processor in the new ring topology */ err = MPI_Init(&argc, &argv); err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); err = MPI_Comm_size(MPI_COMM_WORLD, &size); /* Initialize displacements array with memory addresses */ err = MPI_Address(&gi, &displacements[0]); err = MPI_Address(&ave, &displacements[1]); /* This routine creates the new data type MPI_Pair */ err = MPI_Type_struct(2, blocklengths, displacements, types, &MPI_Pair); err = MPI_Type_commit(&MPI_Pair); /* This routine allows it to be used in communication */

Solution if(size != 4) { printf("Error: You must use 4 processes to run this program.\n"); return 1; } dim[0] = 4;/* Four processors in the one row */ period[0] = 1;/* Have the row "wrap-around" to make a ring */ reorder = 1; /* Create the the new ring cartesian topology with a call to the following routine */ err = MPI_Cart_create(MPI_COMM_WORLD, 1, dim, period, reorder, &MPI_RING); if (rank == 0) { /* File b.data has the target value on the first line */ /* The remaining 300 lines of b.data have the values for the b array */ sourceFile = fopen("b.data", "r"); /* File found.data will contain the indices of b where the target is */ destinationFile = fopen("found.data", "w");

Solution if(sourceFile==NULL) { printf("Error: can't access file.c.\n"); return 1; } else if(destinationFile==NULL) { printf("Error: can't create file for writing.\n"); return 1; } else { /* Read in the target */ fscanf(sourceFile, "%d", &target); } /*Notice the broadcast is outside of the if, all processors must call it*/ err = MPI_Bcast(&target, 1, MPI_INT, 0, MPI_COMM_WORLD); if (rank == 0) { /* Read in b array */ for (i=0; i<N; i++) fscanf(sourceFile,"%d", &b[i]); }

Solution /* Again, the scatter is after the if, all processors must call it */ err = MPI_Scatter(b, N/size, MPI_INT, a, N/size, MPI_INT, 0, MPI_COMM_WORLD); /* Each processor easily determines its left and right neighbors */ /* with the call to the following utility routine */ err = MPI_Cart_shift(MPI_RING, 0, 1, &left, &right); if (rank == 0) { /* P0 sends the first element of its subarray a to its neighbors */ err = MPI_Send(&a[0], 1, MPI_INT, left, 33, MPI_COMM_WORLD); err = MPI_Send(&a[0], 1, MPI_INT, right, 33, MPI_COMM_WORLD); /* P0 gets the first elements of its left and right processor's arrays */ err = MPI_Recv(&lx, 1, MPI_INT, left, 33, MPI_COMM_WORLD, &status); err = MPI_Recv(&rx, 1, MPI_INT, right, 33, MPI_COMM_WORLD, &status); /*Master now searches the first fourth of the array for the target */ for (i=0; i<N/size; i++) { if (a[i] == target) { gi = (rank)*N/size+i+1; ave = (target+lx+rx)/3.0; fprintf(destinationFile,"P %d, %d %f\n", rank, gi, ave); }

Solution end_cnt = 0; while (end_cnt != 3) { err = MPI_Recv(MPI_BOTTOM, 1, MPI_Pair, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); if (status.MPI_TAG == 52) end_cnt++;/*See Comment*/ else fprintf(destinationFile,"P %d, %d %f\n", status.MPI_SOURCE, gi, ave); } fclose(sourceFile); fclose(destinationFile); } else { /* Each slave sends the first element of its subarray a to its neighbors */ err = MPI_Send(&a[0], 1, MPI_INT, left, 33, MPI_COMM_WORLD); err = MPI_Send(&a[0], 1, MPI_INT, right, 33, MPI_COMM_WORLD); /* Each slave gets the first elements of its left and right processor's arrays */ err = MPI_Recv(&lx, 1, MPI_INT, left, 33, MPI_COMM_WORLD, &status); err = MPI_Recv(&rx, 1, MPI_INT, right, 33, MPI_COMM_WORLD, &status);

Solution /* Search the b array and output the target locations */ for (i=0; i<N/size; i++) { if (a[i] == target) { gi = (rank)*N/size+i+1; /*Equation to convert local index to global index*/ ave = (target+lx+rx)/3.0; err = MPI_Send(MPI_BOTTOM, 1, MPI_Pair, 0, 19, MPI_COMM_WORLD); } gi = target; /* Both are fake values */ ave=3.45; /* The point of this send is the "end" tag (See Chapter 4) */ err = MPI_Send(MPI_BOTTOM, 1, MPI_Pair, 0, 52, MPI_COMM_WORLD); /*See Comment*/ } err = MPI_Type_free(&MPI_Pair); err = MPI_Finalize(); return 0; }

Solution The results obtained from running this code are in the file "found.data" which contains the following: P 0, 62, P 2, 183, P 3, 271, P 3, 291, P 3, 296, Notice that in this new version of the code we obtained the same results as the stencil version, which we should have. If you want to confirm that these results are correct, run the parallel code shown above using the input file "b.data" from Chapter 2.