! -*- mode: F90 ; mode: font-lock ; column-number-mode: true  -*-
program mpi_hello
  use mpi
  implicit none

  integer :: my_rank, num_procs
  integer :: i,ierror

  !initialise MPI world
  call MPI_init(ierror)
  if (ierror/=MPI_success) stop 'Error in MPI_init'

  !get size (total number of processors) within MPI world
  call MPI_comm_size(MPI_comm_world,num_procs,ierror)
  if (ierror/=MPI_success) stop 'Error in MPI_comm_size'

  !get my rank on each different processor within MPI world (0 to num_procs-1)
  call MPI_comm_rank(MPI_comm_world,my_rank,ierror)
  if (ierror/=MPI_success) stop 'Error in MPI_comm_rank'


  do i=0,num_procs-1
     if (i==my_rank) then
        print *,"Hello world from processor",my_rank+1,"of",num_procs
     end if
     call MPI_barrier(MPI_comm_world,ierror)
     if (ierror/=MPI_success) stop 'Error in MPI_barrier'
  end do

  call MPI_finalize(ierror)
  if (ierror/=MPI_success) stop 'Error in MPI_finalize'

end program mpi_hello

