Collective barrier

      PROGRAM Barrier
      INCLUDE 'mpif.h'
      integer rank, size, j, k, nloop
      real t1, t2, tmin

      CALL MPI_INIT(IERR)
      CALL MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
      CALL MPI_COMM_RANK(mpi_COMM_WORLD, rank, ierr)

      NUMBER_OF_TESTS=10

      if (rank.eq.0.and.size.eq.1)
     +write(*,*) ' kind     np       time(sec) '

      nloop = 1000
      tmin  = 1000

      do k=1, NUMBER_OF_TESTS
         call MPI_Barrier( MPI_COMM_WORLD, ierr)
         t1 = MPI_Wtime()
         do j=1, nloop
            call MPI_Barrier( MPI_COMM_WORLD, ierr)
         enddo
         t2 = (MPI_Wtime() - t1) / nloop
         if (t2.lt.tmin) tmin = t2
      enddo

      if (rank.eq.0) write(*,*) 'Barrier   ', size, '  ',tmin

      CALL MPI_FINALIZE(ierr)

      END