So I am trying to figure out the communication overhead of sending and receiving information between processors using MPI in C code.
I need to pass a buffer in both the send and receive, but all I want to do is to time how long it takes to do n communications between two processors.
Here is the my entire code:
main(int argc, char** argv){
int n;
int rank;
int time;
int i;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if(rank == 0){
n = atoi(argv[1]);
printf("Size of data set = %d\n", n);
}
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
for(i = 0; i < n; i++){
if(rank == 0){
MPI_Send(&n, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}
else{
MPI_Recv(&n, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
}
}
MPI_Barrier(MPI_COMM_WORLD);
time = clock();
printf("Time: %d\n", time);
MPI_Finalize();
}
I did some testing and I have found that it works the way I want it to when I take out the for loop. So what is wrong with the for loop that causes either an infinite loop or seg fault?