Skip to content

Instantly share code, notes, and snippets.

@jacquerie
Created November 19, 2013 16:00
Show Gist options
  • Save jacquerie/7547639 to your computer and use it in GitHub Desktop.
Save jacquerie/7547639 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;
int A[SIZE], B[SIZE];
MPI_Status s1, s2;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
for (i = 0; i < SIZE; i++) {
A[i] = rank;
}
if (rank == 0) {
MPI_Send(A, SIZE, MPI_INT, 1, 0, MPI_COMM_WORLD);
MPI_Recv(B, SIZE, MPI_INT, 1, 1, MPI_COMM_WORLD, &s1);
} else if (rank == 1) {
MPI_Recv(B, SIZE, MPI_INT, 0, 0, MPI_COMM_WORLD, &s2);
MPI_Send(A, SIZE, MPI_INT, 0, 1, MPI_COMM_WORLD);
}
// For some reason, the expected output appends ".00" to integers.
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