Trying to compile an MPI programm

  • Thread starter Thread starter sketos
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around compiling and running a simple MPI (Message Passing Interface) program in Fortran on a Linux system, specifically Ubuntu 12.04. Participants explore issues related to compilation errors, the correct use of compiler flags, and the execution of the program in a parallel environment.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant shares their Fortran MPI program and reports an error related to including the 'mpif.h' header file.
  • Another participant suggests using the -I option to specify the directory of the missing header file, rather than the file itself.
  • A different participant clarifies that the -L option should point to directories containing library files, while the -I option should point to directories containing include files.
  • Some participants note that Fortran programs typically do not use header files with a .h extension, which is more common in C and C++.
  • One participant successfully compiles the program using 'mpif90' but observes that it does not run in parallel, receiving output indicating only one process is active.
  • Another participant suggests adding debugging code to check the 'ierr' values returned by MPI subroutine calls to diagnose issues.
  • A participant later discovers that using 'mpiexec -n 4 ./new' successfully runs the program in parallel.

Areas of Agreement / Disagreement

Participants generally agree on the correct usage of compiler flags and the nature of the issues faced, but there is no consensus on the initial compilation approach. The discussion evolves as participants refine their understanding of MPI and its execution.

Contextual Notes

Some limitations include potential misunderstandings about the use of header files in Fortran, as well as the specific requirements for compiling and executing MPI programs. The discussion does not resolve all uncertainties regarding the best practices for MPI programming.

Who May Find This Useful

Individuals learning parallel programming with MPI in Fortran, users troubleshooting compilation and execution issues on Linux systems, and those seeking to understand the nuances of MPI in a Fortran context.

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   Reactions: 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   Reactions: 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 5 ·
Replies
5
Views
1K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 54 ·
2
Replies
54
Views
5K