Message Passing interface introductory question

AI Thread Summary
The discussion centers on troubleshooting a basic MPI (Message Passing Interface) "hello world" program in Fortran. The user encounters an error stating that the compiler cannot open the included file 'mpif.h'. It is suggested that the user check if the folder containing 'mpif.h' is in the include path. Commands like "whereis mpif.h" and "locate mpif.h" are recommended for locating the file. The user is advised to use the compiler flag -I to include the directory containing 'mpif.h' during compilation. However, after making these adjustments, the user faces a new issue with "undefined reference to `mpi_init_'" and similar errors for other MPI subroutines. This indicates that the compiler or linker cannot find the necessary MPI library code, which is essential for linking the MPI functions used in the program. The discussion highlights the importance of both the include path for header files and the library path for linking in MPI programming.
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!​

 
Technology 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
12
Views
7K
Replies
12
Views
3K
Replies
1
Views
3K
Replies
1
Views
2K
Replies
54
Views
5K
Back
Top