program example8 include 'mpif.h' integer ierr, rank, size, i, n, lmax, NMAX, NTIMES parameter (NMAX = 1 000 000, NTIMES = 10) double precision time_start, time, bandwidth, max real*8 a(NMAX) integer status(MPI_STATUS_SIZE) call MPI_INIT(ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) time_start = MPI_WTIME(ierr) n = 0 max = 0.0 lmax = 0 do while(n .le. NMAX) time_start = MPI_WTIME(ierr) do i = 1, NTIMES if(rank .eq. 0) then call MPI_SEND(a, n, MPI_DOUBLE_PRECISION, 1, 1, & MPI_COMM_WORLD, ierr) call MPI_RECV(a, n, MPI_DOUBLE_PRECISION, 1, 1, & MPI_COMM_WORLD, status, ierr) end if if(rank .eq. 1) then call MPI_RECV(a, n, MPI_DOUBLE_PRECISION, 0, 1, & MPI_COMM_WORLD, status, ierr) call MPI_SEND(a, n, MPI_DOUBLE_PRECISION, 0, 1, & MPI_COMM_WORLD, ierr) end if enddo time = (MPI_WTIME(ierr)-time_start)/2/NTIMES bandwidth = (8*n*1.d0/(2**20))/time if(max .lt. bandwidth) then max = bandwidth lmax = 8*n end if if(rank .eq. 0) then if(n .eq. 0) then print *, 'latency = ', time, ' seconds' else print *, 8*n, ' bytes, bandwidth =', bandwidth, & ' Mb/s' end if end if if(n .eq. 0) then n = 1 else n = 2*n end if end do if(rank .eq. 0) then print *, 'max bandwidth =', max, ' Mb/s , length =', & lmax, ' bytes' end if call MPI_FINALIZE(ierr) end