10 #define KEY 1234 // tag for control messages
12 int main(int argc, char *argv[])
16 char name[MPI_MAX_PROCESSOR_NAME];
19 MPI_Init(&argc,&argv);
21 // get rank and size from communicator
22 MPI_Comm_size(MPI_COMM_WORLD,&size);
23 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
25 MPI_Get_processor_name(name,&nlen);
28 printf("Rank %d initializing, total %d\n",rank,size);
30 MPI_Recv(&prev,1,MPI_INT,rank-1,KEY,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
31 printf("Rank %d on %s received from %d, passing on\n",rank,name,prev);
33 if (rank+1<size) MPI_Send(&rank,1,MPI_INT,rank+1,KEY,MPI_COMM_WORLD);