      program vecsum

      include 'mpif.h'
      integer, parameter:: dim1=80,dim2=10
      integer ierr,rank,size,root
      real, dimension(dim1):: x,y,z
      real, dimension(dim2) :: xpart,ypart, zpart
      real, dimension(2) :: coeff

      root = 0

      ! Initiate mpi.

      call MPI_INIT(ierr)
      call MPI_COMM_RANK(mpi_comm_world, rank, ierr)
      call MPI_COMM_SIZE(mpi_comm_world, size,ierr)

      print *, 'start process on process ', rank

      if (rank == root) then
         
         coeff(1) = 1.
         coeff(2) = 2.
         x = 2.0
         y = 3.0

      endif   

      call MPI_SCATTER(x,dim2,mpi_real,xpart,dim2,mpi_real, &
        root,mpi_comm_world,ierr)
      
      call MPI_SCATTER(y,dim2,mpi_real,ypart,dim2,mpi_real, &
        root, mpi_comm_world,ierr)
      
      call MPI_BCAST(coeff,2,mpi_real,root,mpi_comm_world, &
        ierr)

      do i = 1,dim2
      
         zpart(i) = coeff(1)*xpart(i) + coeff(2)*ypart(i)
      
      enddo

      call MPI_GATHER(zpart, dim2,mpi_real,z,dim2,mpi_real, &
        root,mpi_comm_world,ierr)

      print *, 'Finish processor ',rank
      
      if (rank == root) then
      
         print * ,'VECTOR SUM, elements 10 and 60, are:', &
           z(10),z(60)
      
      endif

      call MPI_FINALIZE(ierr)

      end 
