Sharing Data

 

program bcast
      include 'mpif.h'

      call MPI_Init(ierr)
      call MPI_Comm_size(MPI_COMM_WORLD, nprocs, ierr)
      call MPI_Comm_rank(MPI_COMM_WORLD, myrank, ierr)

      if (myrank .eq. 0) then
         read(*,*) ivalue
      else
         ivalue = 0
      endif

      call MPI_Bcast(ivalue, 1, MPI_INTEGER, 0,
     &               MPI_COMM_WORLD, ierr)

      print *, 'Process ', myrank, ' got ', ivalue

      call MPI_Finalize(ierr)
      end