Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <mpi.h>
- #define arr_size 20
- int main (int argc, char **argv)
- {
- char message[arr_size] = {};
- int rank, size;
- strcpy(message, "Hi, process");
- MPI_Status status;
- MPI_Init (&argc, &argv);
- MPI_Comm_rank (MPI_COMM_WORLD, &rank);
- MPI_Comm_size (MPI_COMM_WORLD, &size);
- if ( (rank+1) < size)
- {
- MPI_Send(message, strlen(message), MPI_CHAR, rank+1, 99, MPI_COMM_WORLD);
- printf("I'm %d. Sent msg to %d\n", rank, rank+1);
- MPI_Recv(message, strlen(message), MPI_CHAR, rank-1, 99, MPI_COMM_WORLD, &status);
- if (rank != 0)
- printf("I'm %d. Received msg from %d\n", rank, rank-1);
- else
- printf("I'm %d. Received msg from %d\n", rank, size-1);
- }
- else
- {
- MPI_Send(message, strlen(message), MPI_CHAR, 0, 99, MPI_COMM_WORLD);
- printf("I'm %d. Sent msg to %d\n", rank, 0);
- MPI_Recv(message, strlen(message), MPI_CHAR, rank-1, 99, MPI_COMM_WORLD, &status);
- printf("I'm %d. Received msg from %d\n", rank, rank-1);
- }
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment