Message Passing interface introductory question

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 1K views
sketos
Messages
55
Reaction score
0
Hello,

I have just started to learn myself parallel programming specifically MPI. I know that this is going to 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)
stop
end

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!​

 
Physics news on Phys.org
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.
 
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 )
 
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:
f95 foo.bar -o foo -I /directory-path-containing-mpif.h/
 
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.
 
sketos said:
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.
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.