Skip to content
Snippets Groups Projects
Commit f7719cf6 authored by Chao Zhan's avatar Chao Zhan
Browse files

Revert "Revert "add solution to round trip example""

This reverts commit e7b4ada1.
parent e7b4ada1
Branches
No related tags found
No related merge requests found
...@@ -13,21 +13,25 @@ int main(int argc, char** argv) { ...@@ -13,21 +13,25 @@ int main(int argc, char** argv) {
// of the special case when you are the first process to prevent deadlock. // of the special case when you are the first process to prevent deadlock.
if (rank != 0) { if (rank != 0) {
// TODO: Receive the token from the previous process in the ring MPI_Recv(&token, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
printf("Process %d received token %d from process %d\n", rank, token, printf("Process %d received token %d from process %d\n", rank, token,
rank - 1); rank - 1);
} else { } else {
// TODO: Set the token's value if you are process 0 // Set the token's value if you are process 0
token = 1024;
} }
// TODO: send the token to the next process in the ring MPI_Send(&token, 1, MPI_INT, (rank + 1) % num_procs, 0,
MPI_COMM_WORLD);
// Now process 0 can receive from the last process. This makes sure that at // Now process 0 can receive from the last process. This makes sure that at
// least one MPI_Send is initialized before all MPI_Recvs (again, to prevent // least one MPI_Send is initialized before all MPI_Recvs (again, to prevent
// deadlock) // deadlock)
if (rank == 0) { if (rank == 0) {
// TODO: Receive the token from the last process in the ring MPI_Recv(&token, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
printf("Process %d received token %d from process %d\n", rank, token, printf("Process %d received token %d from process %d\n", rank, token,
num_procs - 1); num_procs - 1);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment