Q:

Can't open module file using gfortran

I am using gfortran to run an .F90 code, and I am getting two errors,
program fhello_world_mpi.F90
   1
Error: Invalid form of PROGRAM statement at (1)
fhello_world_mpi.F90:2:6:

   use mpi
       1
 Fatal Error: Can't open module file ‘mpi.mod’ for reading at (1): 
 No such file or directory
 compilation terminated.

I have checked the mpi installation libraries (mpich, openmpi libraries exist in the system).
The program is as follows:
program fhello_world_mpi.F90
  use mpi
  implicit none
   integer ( kind = 4 ) error
   integer ( kind = 4 ) id
   integer p
   character(len=MPI_MAX_PROCESSOR_NAME) :: name
   integer clen
   integer, allocatable :: mype(:)
   real ( kind = 8 ) wtime

   call MPI_Init ( error )
   call MPI_Comm_size ( MPI_COMM_WORLD, p, error )
   call MPI_Comm_rank ( MPI_COMM_WORLD, id, error )
  if ( id == 0 ) then
     wtime = MPI_Wtime ( )

     write ( *, '(a)' ) ' '
     write ( *, '(a)' ) 'HELLO_MPI - Master process:'
     write ( *, '(a)' ) '  FORTRAN90/MPI version'
     write ( *, '(a)' ) ' '
     write ( *, '(a)' ) '  An MPI test program.'
     write ( *, '(a)' ) ' '
     write ( *, '(a,i8)' ) '  The number of processes is ', p
     write ( *, '(a)' ) ' '
  end if
  call MPI_GET_PROCESSOR_NAME(NAME, CLEN, ERROR)
  write ( *, '(a)' ) ' '
  write ( *, '(a,i8,a,a)' ) '  Process ', id, ' says "Hello, world!" ',name(1:clen)

  call MPI_Finalize ( error )
end program

Update1
Removing the period solved the first problem.
I used these commands:
mpif90 fhello_world_mpi.F90 and
mpirun -np 2 ./fhello_world_mpi
It gave the following errors:
mpirun was unable to launch the specified application as it could not 
access or execute an executable:

Executable: ./fhello_world_mpi
Node: user

  while attempting to start process rank 0.

 2 total processes failed to start``

Update2
It worked.
Ran commands:
mpif90 -o fhello_world_mpi fhello_world_mpi.F90
mpirun -np 2 ./fhello_world_mpi
Output
HELLO_MPI - Master process:
  FORTRAN90/MPI version

  An MPI test program.

  The number of processes is        2

   Process        1 says "Hello, world!" user
   Process        0 says "Hello, world!" user

A:

Change the first line of the program to remove the period.  
program fhello_world_mpi

Periods (.) are not allowed in the names of Fortran entities (such as programs, variables, constants, types, etc).
Try mpif90 filename.F90. The MPI feature is usually implemented as a "library" and for the code to compile, you need to provide extra information: location of the .mod files when compiling and of the lib*.so files when linking. This is achieved by the compiler wrapper mpif90 (often, the name may vary):
mpif90 -o fhello_world_mpi fhello_world_mpi.F90

Likewise, to execute the code you need a wrapper:
mpirun -np 2 ./fhello_world_mpi

I assumed the filename was fhello_world_mpi.F90, correct as needed.

In general, you should not try to use the flags manually but if you wish to see them you can use mpif90 -show. mpirun is needed anyway because it initializes the parallel environment.

