/* * This program has been tested with MPICH-1.2.5 * Run the program with BUFSIZE 31999, * and 32000 to see the difference */ #include /*for input/output*/ #include /*for mpi routines*/ #define BUFSIZE 31999 /*The size of the messege being passed*/ main(int argc, char** argv) { float *sendbuf, *recvbuf; int rank; /*the rank of this process*/ int tag = 0; MPI_Status status; /*not important here*/ sendbuf = (float *)malloc(sizeof(float)*BUFSIZE); recvbuf = (float *)malloc(sizeof(float)*BUFSIZE); MPI_Init(&argc, &argv); /*Initializing mpi*/ MPI_Comm_rank(MPI_COMM_WORLD, &rank); /*Getting my rank*/ if (rank == 0) { printf("Hello world! I am proc %d, sending to proc 1\n", rank); /*send to the proc 1*/ MPI_Send(sendbuf, BUFSIZE, MPI_FLOAT, 1, tag, MPI_COMM_WORLD); /*recieve from proc 1*/ MPI_Recv(recvbuf, BUFSIZE, MPI_FLOAT, 1, tag, MPI_COMM_WORLD, &status); } else if (rank == 1) { printf("Hello world! I am proc %d, sending to proc 0\n", rank); /*send to the proc 0*/ MPI_Send(sendbuf, BUFSIZE, MPI_FLOAT, 0, tag, MPI_COMM_WORLD); /*recieve from the proc 0*/ MPI_Recv(recvbuf, BUFSIZE, MPI_FLOAT, 0, tag, MPI_COMM_WORLD, &status); } printf("Proc %d finished!!\n", rank); free(sendbuf); free(recvbuf); MPI_Finalize(); return 0; }