       include 'mpif.h'
       integer numtasks, rank,stat(MPI_STATUS_SIZE),ierr
       character*20 inmsg, outmsg
       character*1 packdata(50),unpackdata(50)
       call MPI_INIT(ierr)
       if(ierr.ne.0)then
       print*,'error setting MPI'
       call mpi_abort(mpi_comm_world,ierr)
       endif
       call mpi_comm_size(mpi_comm_world,numtasks,ierr)
       call mpi_comm_rank(mpi_comm_world,rank,ierr)
       if(rank.eq.0)then
       outmsg='from master'
       iposition=0
       call MPI_PACK(outmsg,20,MPI_CHARACTER,PACKDATA,50,iPOSITION,
     1 MPI_COMM_WORLD,Ierr)
       call MPI_PACK(rank,1,MPI_INTEGER,PACKDATA,50,iPOSITION,
     1 MPI_COMM_WORLD,Ierr)
       do i=1,numtasks-1
       call MPI_SEND(packdata,50,MPI_PACKED,i,i,MPI_COMM_WORLD,ierr)
       enddo
       else
       call MPI_RECV(unpackdata,50,MPI_PACKED,0,rank,
     1 MPI_COMM_WORLD, stat,ierr)
       iposition=0
       call MPI_UNPACK(unpackdata,50,iposition,inmsg,20,
     1 MPI_CHARACTER,MPI_COMM_WORLD,ierr)
       call MPI_UNPACK(unpackdata,50,iposition,ifrom,1,
     1 MPI_INTEGER,MPI_COMM_WORLD,ierr)
       print*,'rank=',ifrom,'received ',inmsg
       endif
       call mpi_finalize(ierr)
       stop
       end

