fortranmpiopenmpi

Compile a library that uses mpi (AGMG)


I am trying to compile the library AGMG.

The make file for the parallel example is looking like this:

# MPIopt    = -I/... (where to find mpif.h)
# MUMPSPopt = -I/... (where to find files to be included by 
#                     applications using MUMPS)
# MUMPSlib  = -l...  (link reference for MUMPS)
# SCALAP    = -l...  (link reference for SCALAPACK, needed by MUMPS)
# BLASLAPACK= -l...  (link reference for LAPACK & BLAS)
# MPIlib    = -l...  (link reference for MPI)

On my Debian mpif.h is found:

$ ls /usr/lib/openmpi/include/mpi.h 
/usr/lib/openmpi/include/mpi.h

So I wrote in the Makefile:

MPIopt  =   -I/usr/lib/openmpi/include/
MPIlib    = -lmpi

But never the less, when I try to compile, I get the following errors:

:~/AGMG_3.0/Example_par$ make
cd ../SRC;make dpar
make[1]: Entering directory `AGMG_3.0/SRC'
make[1]: Nothing to be done for `dpar'.
make[1]: Leaving directory `AGMG_3.0/SRC'
gfortran-4.4 -O4 -o Example_par Example_par.o ../SRC/dagmg_par.o   -lmpi 
Example_par.o: In function `MAIN__':
Example_par.f90:(.text+0x77): undefined reference to `mpi_init_'
....
....
....
dagmg_par.f90:(.text+0x19fc9): undefined reference to `mpi_comm_rank_'
dagmg_par.f90:(.text+0x19fdd): undefined reference to `mpi_comm_size_'
collect2: ld returned 1 exit status
make: *** [Example_par] Error 1

I'm quite confused by now, I had tries that succeeded, but than I had problems with scaplap and the other requirements. scalap is found:

$ dpkg -L libscalapack-mpi-dev 
/.
/usr
/usr/lib
/usr/lib/libscalapack-openmpi.a

mumps is found in /usr/lib/libsmumps.a and the header files are in /usr/include/smumps_c.h

So how do I put all this together?

I know that for a more advanced fortran or C developer this would be trivial ...

Thanks in advance for your help.

EDIT: I'm putting here the full Makefile definitions, in hope it might help others:

MPIopt = -I/usr/lib/openmpi/include -I/usr/lib/openmpi/lib -L/usr/lib/openmpi/lib -pthread 
MPIlib = -lmpi_f90 -lmpi_f77 -lmpi 
MUMPSPopt = -I/usr/lib/libsmumps.a -I/usr/lib/libdmumps.a
MUMPSlib = -lsmumps  -ldmumps
BLASLAPACK=-L/usr/lib -llapack -lblas 
BLASLAPACK=-L/usr/lib -llapack -lblas 
SCALAP = -L/usr/lib/libscalapack-openmpi.a -lscalapack-openmpi

F90=gfortran-4.6    

This builds it. Thanks for the replies!


Solution

  • These are linker errors. It looks like your include files have been picked up successfully, but the linker is not seeing the MPI library. Try changing MPIlib = -lmpi to something that includes the path to libmpi.a, such as MPIlib = -L/usr/lib/openmpi/lib -lmpi

    Alternatively, try using the MPI compiler wrappers, as suggested by @haraldkl. These should take care of linking to MPI automatically.