Trying to compile an MPI programm

  • Thread starter Thread starter sketos
  • Start date Start date
AI Thread Summary
A user new to Linux and parallel programming on Ubuntu 12.04 encountered issues compiling and running a simple MPI "Hello" program written in Fortran. The user initially struggled with the inclusion of the MPI header file, receiving errors related to the file not being found. It was clarified that the correct compilation command should use the -I option to specify the directory of the header file, rather than the file itself. The user eventually switched to using the mpif90 command for compilation, which resolved the initial error but resulted in the program only recognizing a single process. The solution was found by launching the program with mpiexec -n 4, allowing it to run in parallel as intended. The discussion highlighted the importance of using the correct MPI commands and understanding the compilation process for Fortran programs.
sketos
Messages
55
Reaction score
0
Hello, I am relatively new user to Linux system (ubuntu 12.04) and I am trying learn myself parallel programming. At the moment I am trying to run a simple MPI "Hello" programm :

program example1

!--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
  • I have downloaded from the synaptic packahe the mpich2.
  • the location of mpif.h is /usr/include/mpich2/mpif.h
My programms name is "test1.f95" and i can't compile it so far. I have looked around the forums but nothing works. I have tryied:

  • f95 test1.f95 -o new -L/usr/include/mpich2/mpif.h
  • I have also included the compiler to look in this directory: export PATH=$PATH:/usr/include/mpich2
But i keep getting the error: test1.f95:4: Error: Can't open included file 'mpif.h'

If it helps the directory of my programs document program is "/home/sketos/Desktop/parallel programming "

Is there something wrong with my compiler cause i have been using fortran quite a lot ...

Sorry for the silly question but i can't figure out what is wrong
 
Technology news on Phys.org
Have you tried the -I option ( that's the capital letter I) and the directory containing the missing header file mpif.h
 
  • Like
Likes Geofleur
yeah i have tried: f95 test1.f95 -o new -L/usr/include/mpich2/mpif.h -I mpif.h as well and i get the same error
 
The -I option means you place the directory path of where the mpif.h file is located not the file itself.
 
Ooo that's the same with -L , i just tried it and unfortunately the same result pop-up
 
sketos said:
yeah i have tried: f95 test1.f95 -o new -L/usr/include/mpich2/mpif.h -I mpif.h as well and i get the same error
Just a guess here, but I think the -L switch should have the directory that contains the lib files, and the -I switch should have the directory that contains the include files. They shouldn't be in the same directories.

Also, it seems to me that Fortran programs don't normally use header files (*.h). Include files (.h file extension) are more the norm in C and C++ programs.
 
Also, this is a continuation of the thread you started a little while ago. Instead of starting a new thread, you should have continued posting in the older thread. I responded in that thread, but you didn't reply in it.
 
Have you looked at this page - http://www.mpich.org/documentation/guides/ ?
The first three links on the page should be helpful - Installer's Guide, User's Guide, README.

There is also a section with links to tutorials on the page whose link I gave.
 
  • Like
Likes sketos
Mark44 said:
Also, it seems to me that Fortran programs don't normally use header files (*.h). Include files (.h file extension) are more the norm in C and C++ programs.
That's a quirk of MPI. It is a Fortran file (hence the "f" in mpif), but they gave it a .h extension anyway.
 
  • #10
i tried to compile it with " mpif90 test1.f95 -o new "

That way i don't get an error but it's not working as a parallel code ... for instance the result i get on terminal is:

Process 0 of 1 is alive

any thoughts on that? Thank a lot!
 
  • #11
sketos said:
i tried to compile it with " mpif90 test1.f95 -o new "

That way i don't get an error but it's not working as a parallel code ... for instance the result i get on terminal is:

Process 0 of 1 is alive

any thoughts on that? Thank a lot!
Add some debugging code. Each of the MPI subroutines you call has a parameter named ierr, which I'm guessing gets set with a value after the subroutine returns. You'll need to look at the MPI documentation to see what the values represent, although if everything went fine, ierr is probably set to 0.

Add code to print the value of ierr after each subroutine call, and see what that tells you.
 
  • #12
sketos said:
i tried to compile it with " mpif90 test1.f95 -o new "

That way i don't get an error but it's not working as a parallel code ... for instance the result i get on terminal is:

Process 0 of 1 is alive

any thoughts on that? Thank a lot!
What command are you using to launch your program?
 
  • #13
I was trying to lanch it by : ./new

Now I tryied using : mpiexec -n 4 ./new and it worked! THANK YOU ALL FOR YOUR HELP during the whole post and for your patience !
 

Similar threads

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