Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Message Passing interface introductory question

  1. Oct 4, 2014 #1

    I have just started to learn myself parallel programming specifically MPI. I know that this is gonna be a silly question. I am trying to run the most basic 'hello world' program :

    program example1
    implicit none
    !--Include the mpi header file
    include 'mpif.h'
    integer ierr,myid,numprocs
    integer irc
    !--Initialize MPI
    call MPI_INIT( ierr )
    !--Who am I? --- get my rank=myid
    call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
    !--How many processes in the global group?
    call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
    print *, "Process ",myid," of ",numprocs," is alive"
    !--Finalize MPI
    call MPI_FINALIZE(irc)

    to compile ( test.f95 in my file's name )
    f95 test.95 -o new
    But i get the Error: Can't open included file 'mpif.h'

    What is going on exactly?? is there something missing that i have to install??

    Is there something wrong with the way i am trying to compile it ( if there was no error i should just type mpirun -np 3 new)

    Sorry for the silly question!!!​

  2. jcsd
  3. Oct 4, 2014 #2


    User Avatar
    Science Advisor
    Gold Member

    Is the folder containing the file 'mpif.h' in your include path? If the compiler can't find the file named 'mpif.h' then it'll probably throw an error that looks like that.
  4. Oct 4, 2014 #3
    By typing in the command line " whereis mpif.h " i get :

    mpif: /usr/bin/mpif90.mpich2 /usr/bin/mpif77.mpich2 /usr/bin/X11/mpif90.mpich2 /usr/bin/X11/mpif77.mpich2

    how exactly can i include a path??

    *( My expression in the post was wrong ... by folder i meant document's name )
  5. Oct 4, 2014 #4


    User Avatar
    Science Advisor
    Gold Member

    Try "locate mpif.h" instead. whereis doesn't really work that way. It looks from your first post that you're using the SunStudio f95 compiler. From Oracle's documentation page, you can use the compiler flag -I ( that's an an uppercase i ) to include directories in your search path. So for example:
    Code (Text):
    f95 foo.bar -o foo -I /directory-path-containing-mpif.h/
  6. Oct 5, 2014 #5
    Thanks a lot!!!

    Unfortunately the problems keep coming! Now that i try to compile it that way i get: undefined reference to `mpi_init_'

    and also the same error for the other MPI subroutines.
  7. Oct 5, 2014 #6


    Staff: Mentor

    My guess is that the compiler/linker can't find the lib code for the MPI routines. Fortran doesn't ordinarily use include files (that I'm aware of), but the C-based languages do. The header files contain function declarations (and a few other things), but the code for the functions typically resides in a library, either static (usually *.lib) or dynamic (*.dll in Windows). If the linker is unable to find the lib code, you'll get an error like the one you show.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook