Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mpi.h>
- #include <stdio.h>
- int main(int argc, char** argv)
- {
- int size, rank, a = 5, b = 1;
- MPI_Status status;
- MPI_Init(&argc, &argv);
- MPI_Comm_size(MPI_COMM_WORLD, &size);
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- for (int i = 0; i < 50; i++)
- {
- if(rank == i)
- {
- MPI_Send(&a, 1, MPI_INT, i+1, 123, MPI_COMM_WORLD);
- MPI_Recv(&b, 1, MPI_INT, i+1, 123, MPI_COMM_WORLD, &status);
- }
- if(rank == i+1)
- {
- MPI_Recv(&b, 1, MPI_INT, i, 123, MPI_COMM_WORLD, &status);
- MPI_Send(&b, 1, MPI_INT, i, 123, MPI_COMM_WORLD);
- printf("%d\n", b);
- }
- }
- //printf("%d\n%d\n", size, rank);
- MPI_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement