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