Message Passing interface introductory question

In summary, the conversation is about a person learning parallel programming with MPI. They are struggling to compile a basic 'hello world' program and are getting an error about not being able to find the included file 'mpif.h'. They are advised to make sure the folder containing the file is in their include path and to use the compiler flag -I to include the directory in the search path. However, they continue to get errors about undefined references to MPI subroutines, indicating that the compiler/linker may not be able to find the library code for the routines.
  • #1
sketos
56
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
  • #2
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.
 
  • #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 )
 
  • #4
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/
 
  • #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.
 
  • #6
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.
 

Related to Message Passing interface introductory question

1. What is Message Passing Interface (MPI)?

Message Passing Interface (MPI) is a standardized communication protocol used for parallel computing. It allows multiple processes to communicate and coordinate with each other, enabling parallel programs to be executed on a distributed memory system.

2. How does MPI work?

MPI works by sending messages between processes using a send and receive communication model. The sending process specifies the target process and the data to be sent, while the receiving process specifies the source process and the data to be received. These messages can be sent synchronously or asynchronously, depending on the needs of the program.

3. What are the benefits of using MPI?

MPI offers several benefits, including improved performance, scalability, and portability. It allows for efficient parallel programming, as well as the ability to run on a variety of architectures and operating systems. Additionally, MPI can handle large amounts of data and complex communication patterns, making it a valuable tool for scientific and high-performance computing.

4. How is MPI different from other parallel programming models?

MPI differs from other parallel programming models in that it is a message passing interface, meaning that processes communicate by explicitly sending and receiving messages. Other models, such as shared memory programming, use a shared memory space for communication. Additionally, MPI is a standardized interface, while other models may be proprietary or specific to a particular programming language or architecture.

5. How can I get started with MPI?

To get started with MPI, you will need an MPI implementation, such as Open MPI, MPICH, or Intel MPI. You will also need a programming language that supports MPI, such as C, C++, or Fortran. There are many online resources and tutorials available to help you learn the basics of MPI programming and develop parallel programs using MPI.

Similar threads

  • Programming and Computer Science
Replies
12
Views
6K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
2
Replies
54
Views
4K
Back
Top