1 /************************************************************************
2 * This file has been written as a sample solution to an exercise in a
3 * course given at the Edinburgh Parallel Computing Centre. It is made
4 * freely available with the understanding that every copy of this file
5 * must include this header and that EPCC takes no responsibility for
6 * the use of the enclosed teaching material.
10 * Contact: epcc-tec@epcc.ed.ac.uk
12 * Purpose: A program to try out non-blocking point-to-point
15 * Contents: C source code.
17 ************************************************************************/
24 int main (int argc, char *argv[])
26 int ierror, rank, size;
27 int right, left, count, i;
30 MPI_Status send_status;
31 MPI_Status recv_status;
34 MPI_Init(&argc, &argv);
35 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
36 MPI_Comm_size(MPI_COMM_WORLD, &size);
38 count = 1; /* only sending a single MPI_INT */
39 right = (rank + 1) % size;
40 left = (rank - 1 + size) % size; /* the '+ size' ensures 'left >= 0'. */
45 for (i=0; i < size; i++) {
47 MPI_Issend(&message, count, MPI_INT, right, TAG_RIGHT,
48 MPI_COMM_WORLD, &request);
50 MPI_Recv(&message, count, MPI_INT, left, TAG_RIGHT,
51 MPI_COMM_WORLD, &recv_status);
54 MPI_Wait(&request, &send_status);
59 printf ("PE%d:\tSum = %d\n", rank, sum);