- /* Pass the message around the ring. The exit mechanism works as
- follows: the message (a positive integer) is passed around the
- ring. Each time it passes rank 0, it is decremented. When
- each processes receives a message containing a 0 value, it
- passes the message on to the next process and then quits. By
- passing the 0 message first, every process gets the 0 message
- and can quit normally. */
-
- sleep(3);
-
- while (1) {
- MPI_Recv(&message, 1, MPI_INT, prev, tag, MPI_COMM_WORLD,
- MPI_STATUS_IGNORE);
-
- if (0 == rank) {
- --message;
- printf("Process 0 decremented value: %d\n", message);
- }
-
- MPI_Send(&message, 1, MPI_INT, next, tag, MPI_COMM_WORLD);
- if (0 == message) {
- printf("Process %d exiting\n", rank);
- break;
- }
- }
+ printf("Process 0 sending %d to %d, tag %d (%d processes in ring)\n",
+ message, next, tag, size);
+ MPI_Send(&message, 1, MPI_INT, next, tag, MPI_COMM_WORLD);
+ printf("Process 0 sent to %d\n", next);
+ }
+
+ /* Pass the message around the ring. The exit mechanism works as
+ follows: the message (a positive integer) is passed around the
+ ring. Each time it passes rank 0, it is decremented. When
+ each processes receives a message containing a 0 value, it
+ passes the message on to the next process and then quits. By
+ passing the 0 message first, every process gets the 0 message
+ and can quit normally. */
+
+ sleep(3);