program hello_world
use mpi
implicit none
integer :: rank, nb_mpi_processes, ierror, hostname_len
character (len=MPI_MAX_PROCESSOR_NAME) :: hostname
!To enhance code readability, we let MPI call or MPI native variables in capital letters in Fortran
call MPI_INIT(ierror) ! Init MPI (init MPI_COMM_WORLD communicator, set rank to each process, etc)
call MPI_COMM_SIZE(MPI_COMM_WORLD, nb_mpi_processes, ierror) ! Ask the number of MPI processes running
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror) ! Ask the rank of the current process
call MPI_GET_PROCESSOR_NAME(hostname,hostname_len,ierror) ! Ask the name of the host the process is running on
print*, 'Hello world ! I am process',rank,'on',nb_mpi_processes,'processes. I am running on',hostname ! Say hello
call MPI_FINALIZE(ierror) ! Close MPI
end program hello_world