Please also put IMPICIT NONE to your SUBROUTINE and replace INCLUDE 'mpif.h' by USE mpi. This comes with the benefit of interface checking. The compiler will throw an error due to missing tags.
It is even better style to write: PROGRAM main USE MPI ... CONTAINS SUBROUTINE ... ... END SUBROUTINE ... END PROGRAM main For more complex programs please use modules instead.