-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e7eb23
commit 1328f59
Showing
8 changed files
with
209 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <mpi.h> | ||
#include <stdio.h> | ||
|
||
// Run with two processes. | ||
// Process 0 sends an integer to process 1 and vice-versa. | ||
// Try to run the system: what goes wrong? | ||
|
||
// mpicc deadlock.c -o deadlock | ||
// mpirun -np 2 deadlock | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
MPI_Init(NULL, NULL); | ||
|
||
int my_rank; | ||
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); | ||
int other_rank = 1 - my_rank; | ||
|
||
int msg_to_send = 1; | ||
int msg_to_recv; | ||
|
||
// send and receive messages in a non-blocking way to avoid deadlock | ||
MPI_Isend(&msg_to_send, 1, MPI_INT, other_rank, 0, MPI_COMM_WORLD, MPI_REQUEST_NULL); | ||
MPI_Irecv(&msg_to_recv, 1, MPI_INT, other_rank, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_REQUEST_NULL); | ||
|
||
printf("Rank %d received message %d from rank %d\n", my_rank, msg_to_recv, other_rank); | ||
|
||
MPI_Finalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters