program main include 'mpif.h' parameter (M = 3) integer ierr, rank integer tag, status(MPI_STATUS_SIZE) integer size, messagesize real buf*(*) integer n, i integer blen call MPI_INIT(ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) if( size .ne. 2 ) then if( rank .eq. 0 ) then print *, 'Error: 2 processes required' endif call MPI_Abort(MPI_COMM_WORLD, MPI_ERR_OTHER, ierr); endif if (rank == 0) then blen = M * (4 + MPI_BSEND_OVERHEAD) call MPI_BUFFER_ATTACH(buf, blen, ierr) print *, 'attached ', blen, ' bytes' do i = 0, M - 1 print *, 'starting send ', i n = i call MPI_BSEND(n, 1, MPI_INTEGER, 1 1, i, MPI_COMM_WORLD, ierr) print *, 'complete send ', i call SLEEP(1) enddo call MPI_BUFFER_DETACH(buf, blen, ierr) print *, 'detached ', blen, ' bytes' else if (rank == 1) then do i = M - 1, 0, -1 print *, 'starting recv ...', i call MPI_RECV(n, M, MPI_INTEGER, 1 0, i, MPI_COMM_WORLD, status, ierr) print *, 'complete recv: ', i, ' received ', n enddo endif print *, 'Proc ', rank, ' finished!!' call MPI_FINALIZE(ierr) end