      program one2allbroadcast
      include 'mpif.h'
      integer nnodes,myid,vdim
      parameter(niters=1000)
      parameter(vdim=1000)
      integer comm,ierr
      integer status(MPI_STATUS_SIZE),root
      double precision time_begin,time_end
      double precision buffer(vdim),temp(vdim)

      comm = MPI_COMM_WORLD
      call MPI_init(ierr)
      call MPI_COMM_RANK(comm,myid,ierr)
      call MPI_COMM_SIZE(comm,nnodes,ierr)
  
      do i = 1,vdim
        buffer(i) =  i
      enddo

!start timer .....
      time_begin =  MPI_Wtime()
    
      do iter = 1,niters
! Do all-to-all personilized communication of matrix blocks
        call MPI_SCAN(buffer,temp,vdim,MPI_DOUBLE_PRECISION,MPI_SUM,&
          comm,ierr)
      enddo
! Stop timer

      time_end =  MPI_Wtime()

      if (myid == 0) then
        print *,'Elapsed time ',niters,'iterations for one2allbroadcast'
        print *,'is'
        print *,time_end-time_begin ,'seconds'   
       endif

      call MPI_FINALIZE(ierr)

      end


      


