Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28988 Discussions

ifort and mpi: Undefined reference errors

tanksnr
Beginner
7,163 Views
Hi,

I am trying to compile a simple piece of code using ifort 11 and a local installation of mpich.
This is on an IBM e1350 cluster running SuSE Linux Enterprise 9 SP3.

It is basically the 'hello world' for mpi.

[plain]      program main

      include 'mpif.h'

      integer myrank, mysize, rc

      call MPI_INIT( ierr )
      call MPI_COMM_SIZE(MPI_COMM_WORLD,mysize,ierr)
      call MPI_COMM_RANK(MPI_COMM_WORLD,myrank,ierr)

      print *, 'Hello World! I am ', myrank, ' of ', mysize, '.'

      call MPI_FINALIZE(rc)

      stop
      end
[/plain]

I cannot seem to compile this using ifort, i.e.
ifort hello_mpi.f -o hello-mpi.out -I/

I get:
/tmp/ifort3DEBtP.o(.text+0x3f): In function `MAIN__':
: undefined reference to `mpi_init_'
/tmp/ifort3DEBtP.o(.text+0x5b): In function `MAIN__':
: undefined reference to `mpi_comm_size_'
/tmp/ifort3DEBtP.o(.text+0x77): In function `MAIN__':
: undefined reference to `mpi_comm_rank_'
/tmp/ifort3DEBtP.o(.text+0x152): In function `MAIN__':
: undefined reference to `mpi_finalize_'

I've tried many variations of adding or removing underscores etc but nothing seems to work.

The code does however compile via the pathscale compiler. And mpich is built with pathscale.
Sorry i'm new to MPI. Do I have to have an ifort version of mpich? Is there no other way?

regards,
Tanksnr.
0 Kudos
1 Solution
TimP
Honored Contributor III
7,163 Views
At a minimum, you must build the mpi Fortran library with the same compiler you are using for your application, and link against that library. If you aren't on speaking terms with your sysadmin, you have serious obstacles, but you could certainly make you own copy of mpi libraries. What do other people do on your cluster? It may be understandable when a cluster has only an obsolete version of gfortran installed, but why a partly commercial compiler from an organization which has been disbanded?

View solution in original post

0 Kudos
5 Replies
rreis
New Contributor I
7,163 Views
Quoting - tanksnr
Hi,

I am trying to compile a simple piece of code using ifort 11 and a local installation of mpich.
This is on an IBM e1350 cluster running SuSE Linux Enterprise 9 SP3.

It is basically the 'hello world' for mpi.

[plain]      program main

include 'mpif.h'

integer myrank, mysize, rc

call MPI_INIT( ierr )
call MPI_COMM_SIZE(MPI_COMM_WORLD,mysize,ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,myrank,ierr)

print *, 'Hello World! I am ', myrank, ' of ', mysize, '.'

call MPI_FINALIZE(rc)

stop
end
[/plain]

I cannot seem to compile this using ifort, i.e.
ifort hello_mpi.f -o hello-mpi.out -I/

I get:
/tmp/ifort3DEBtP.o(.text+0x3f): In function `MAIN__':
: undefined reference to `mpi_init_'
/tmp/ifort3DEBtP.o(.text+0x5b): In function `MAIN__':
: undefined reference to `mpi_comm_size_'
/tmp/ifort3DEBtP.o(.text+0x77): In function `MAIN__':
: undefined reference to `mpi_comm_rank_'
/tmp/ifort3DEBtP.o(.text+0x152): In function `MAIN__':
: undefined reference to `mpi_finalize_'

I've tried many variations of adding or removing underscores etc but nothing seems to work.

The code does however compile via the pathscale compiler. And mpich is built with pathscale.
Sorry i'm new to MPI. Do I have to have an ifort version of mpich? Is there no other way?

regards,
Tanksnr.

you should use a mpich version compiled with the intel compilers and the use mpif90 to compile your code...
0 Kudos
Ron_Green
Moderator
7,162 Views
Quoting - rreis

you should use a mpich version compiled with the intel compilers and the use mpif90 to compile your code...

Ricardo is correct: the mpich compiler wrappers such as mpif90 when mpich is built with the Intel Fortran compiler will include all the necessary libraries.

Otherwise, your compiler line will require -L and -lmpi or -lmpich (I can't remember which one). But if you use mpif90 to compile, all the lib paths and includes are taken care of.

ron
0 Kudos
tanksnr
Beginner
7,163 Views

Ricardo is correct: the mpich compiler wrappers such as mpif90 when mpich is built with the Intel Fortran compiler will include all the necessary libraries.

Otherwise, your compiler line will require -L and -lmpi or -lmpich (I can't remember which one). But if you use mpif90 to compile, all the lib paths and includes are taken care of.

ron

Is this all mpif90 does? i.e. just add more flags?
So if I include all the libraries in my ifort compiler line it should work?
It doesn't though.
And my mpif90 uses pathscale (since mpich was built with pathscale), but I really need to use ifort.

Sorry i'm really looking for ways to do this without rebuilding mpich with Intel compiler since I don't have that much control of our cluster.
0 Kudos
TimP
Honored Contributor III
7,164 Views
At a minimum, you must build the mpi Fortran library with the same compiler you are using for your application, and link against that library. If you aren't on speaking terms with your sysadmin, you have serious obstacles, but you could certainly make you own copy of mpi libraries. What do other people do on your cluster? It may be understandable when a cluster has only an obsolete version of gfortran installed, but why a partly commercial compiler from an organization which has been disbanded?
0 Kudos
Dmitry_K_Intel2
Employee
7,163 Views
Quoting - tanksnr
Is this all mpif90 does? i.e. just add more flags?
So if I include all the libraries in my ifort compiler line it should work?
It doesn't though.
And my mpif90 uses pathscale (since mpich was built with pathscale), but I really need to use ifort.

Sorry i'm really looking for ways to do this without rebuilding mpich with Intel compiler since I don't have that much control of our cluster.

The problem here not in flags only but in libraries also. For fortran programs binding libraries are needed.

The simplest way is to install Intel MPI Library and you'll get native support of all Intel tools. In this case you just need to compile your application by mpiifort - all needed options and libraries will be used automatically.

Best wishes,
Dmitry
0 Kudos
Reply