/* proc 0 use MPI_Isend to send message, proc 1 use MPI_Irecv to receive message, */ #include // for input/output #include //for mpi routines #define BUFSIZE 2048 //The size of the messege being passed main(int argc, char** argv) { int rank; //the rank of this process int i = 0; int tag = 0; int flag = 0; float *sendbuf, *recvbuf; MPI_Status status; //not important here MPI_Request request; //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) { //sleep for 3 sec sleep(3); printf("Hello world! I am proc 0, sending to proc 1\n"); //send to the proc 1 MPI_Isend(sendbuf, BUFSIZE, MPI_FLOAT, 1, tag, MPI_COMM_WORLD, &request); MPI_Wait (&request, &status); } else if(rank == 1) { //recieve from the proc 0 MPI_Irecv(recvbuf, BUFSIZE, MPI_FLOAT, 0, tag, MPI_COMM_WORLD, &request); do { printf("Wait %d\n", i++); MPI_Test (&request, &flag, &status); } while (flag == 0); } printf("Proc %d finished!!\n", rank); MPI_Finalize(); free(sendbuf); free(recvbuf); return 0; }