/* file: nblock.c compile: cc nblock.c -lmpi run: mpirun -np 2 ./a.out rank = 0 : value = 3 rank = 0 : value = 3 rank = 1 : value = 1 rank = 1 : value = 3 */ #include "mpi.h" main( argc, argv ) int argc; char **argv; { int myrank; int other; MPI_Status status; MPI_Request send_request; MPI_Request recv_request; int a[20] = {3,2,3}; int b[20] = {1,2,1}; MPI_Init( &argc, &argv ); MPI_Comm_rank( MPI_COMM_WORLD, &myrank ); if (myrank == 0){ other = 1; }else { other = 0; } MPI_Isend(a, 1, MPI_INT, other, 0, MPI_COMM_WORLD, &send_request); MPI_Irecv(b, 1, MPI_INT, other, 0, MPI_COMM_WORLD, &send_request); MPI_Isend(b, 1, MPI_INT, other, 0, MPI_COMM_WORLD, &send_request); MPI_Irecv(a, 1, MPI_INT, other, 0, MPI_COMM_WORLD, &send_request); MPI_Wait(&send_request, &status); MPI_Wait(&recv_request, &status); printf("rank = %d : value = %d \n", myrank, a[0]); printf("rank = %d : value = %d \n", myrank, b[0]); MPI_Finalize(); }