1 / 7

PP Lab

PP Lab. MPI programming III. Program 1. Write a program in which every process sends a number to process 0 and process 0 prints the numbers. 1. 2. 0. n-1. Function to be used. MPI_Send : Performs a basic send Synopsis: # include " mpi.h "

Download Presentation

PP Lab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PP Lab MPI programming III

  2. Program 1 Write a program in which every process sends a number to process 0 and process 0 prints the numbers. 1 2 0 n-1

  3. Function to be used • MPI_Send: Performs a basic send • Synopsis: #include "mpi.h" intMPI_Send( void *buf, int count, MPI_Datatypedatatype, intdest, int tag, MPI_Commcomm ) • Input Parameters: • buf: initial address of send buffer (choice) • count: number of elements in send buffer (nonnegative integer) • datatype: datatype of each send buffer element (handle) • dest: rank of destination (integer) • tag: message tag (integer) • comm:communicator(handle)

  4. Function to be used • MPI_Recv: Basic receive • Synopsis: #include "mpi.h" intMPI_Recv( void *buf, int count, MPI_Datatypedatatype, int source, int tag, MPI_Commcomm, MPI_Status *status ) • Output Parameters: • buf initial address of receive buffer (choice) • status status object (Status) • Input Parameters: • count maximum number of elements in receive buffer (integer) • datatypedatatype of each receive buffer element (handle) • source rank of source (integer) • tag message tag (integer) • commcommunicator (handle)

  5. MPI_Status structure • Public Attributes: • intMPI_ERROR • intMPI_SOURCE • intMPI_TAG • intreserved [2] • intsize

  6. Code #include <stdio.h> #include "mpi.h” main(intargc, char **argv) {inti, myrank, size, message, recv_buf, dest, tag, count; MPI_Status status; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); //tell me my rank MPI_Comm_size(MPI_COMM_WORLD,&size); //tell me the size of cluster message=myrank*8; dest=0; count=1; tag=0; if(myrank!= 0) MPI_Send(&message,count,MPI_INT,dest,tag,MPI_COMM_WORLD); else {for (i=1;i<size;i++) {MPI_Recv(&recv_buf,count,MPI_INT,i,tag,MPI_COMM_WORLD, &status); printf( “process %d sent %d\n",i,recv_buf);} } MPI_Finalize();}

  7. Assignment Write a program in which process 0 sends an array of five numbers to process 1.

More Related