Trying to compile an MPI programm

  • Thread starter sketos
  • Start date
In summary,The user is trying to learn parallel programming and has downloaded and installed the MPICH2 library. They are having difficulty compiling a Fortran program and are asking for help.
  • #1
sketos
56
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
  • #2
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
  • #3
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
 
  • #4
The -I option means you place the directory path of where the mpif.h file is located not the file itself.
 
  • #5
Ooo that's the same with -L , i just tried it and unfortunately the same result pop-up
 
  • #6
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.
 
  • #7
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.
 
  • #8
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
  • #9
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 !
 

What is MPI?

MPI stands for Message Passing Interface. It is a standardized programming model used for parallel computing, specifically for distributed memory systems. It allows multiple processors to communicate and coordinate with each other in order to solve a problem together.

Why is MPI used?

MPI is used because it allows for efficient and scalable parallel computing. It allows multiple processes to work together and share data in order to solve a problem faster than a single processor could. It is commonly used in scientific and engineering applications that require heavy computational power.

What are the basic components of an MPI program?

The basic components of an MPI program are the processes, the communication between processes, and the collective operations (such as broadcasting or reducing data). Each process has its own data and code, and they communicate with each other using MPI functions.

How do I compile an MPI program?

To compile an MPI program, you will need to have an MPI implementation installed on your system. Then, you will need to use the MPI compiler (usually named mpicc) and specify the necessary MPI libraries. The exact steps may vary depending on your system and compiler, so it is best to consult the documentation of your MPI implementation.

Can I debug an MPI program?

Yes, you can debug an MPI program using a debugger like gdb or a specialized MPI debugger such as ddd or totalview. However, debugging an MPI program can be more challenging than a traditional single-threaded program, so it is important to have a good understanding of your code and the MPI functions being used.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
  • 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