Skip to content

Instantly share code, notes, and snippets.

@jacquerie
Created November 19, 2013 16:15
Show Gist options
  • Save jacquerie/7547872 to your computer and use it in GitHub Desktop.
Save jacquerie/7547872 to your computer and use it in GitHub Desktop.
#include <mpi.h>
#include <stdio.h>
#define SIZE 10000
int main (int argc, char** argv) {
int i, rank, size, left, right;
int A[SIZE], B[SIZE];
MPI_Request request;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
for (i = 0; i < SIZE; i++) {
A[i] = rank;
}
left = (rank == 0) ? size - 1 : rank - 1;
right = (rank == size - 1) ? 0 : rank + 1;
MPI_Isend(A, SIZE, MPI_INT, right, 0, MPI_COMM_WORLD, &request);
MPI_Recv(B, SIZE, MPI_INT, left, 0, MPI_COMM_WORLD, &status);
printf("I am task %d and I have received B[0] = %d.00\n", rank, B[0]);
MPI_Finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment