I don't think this is actually OpenMPI's problem. I know this is getting 
slightly off topic but before I take this to the PGI folks I'd like to make 
sure it isn't actually an OpenMPI problem after all.  Here's my best shot at 
explaining what I think is going on. Please excuse my rusty terminology.

If one uses the PGI compilers to build a shared library based on an f90 module 
the resulting object file and shared library contain references to any 
subroutines defined inside any interfaces defined in said module. This can be 
verified with nm. If you then link against the produced shared library the 
compilation will fail with "undefined references" to any of the subroutines 
that were contained inside any defined interfaces (that aren't defined within 
the code being compiled).  This doesn't seem to happen with the GNU or Intel 
compilers. I have a small test case that I think reproduces the problem here. 
Since I'm not by any means a fortran expert I was wondering if somebody on the 
list who is a little more versed in fortran could verify that this code is 
correct and should compile (it does with gnu and intel compilers). The makefile 
can be found here http://pastebin.com/f7f320b97 and the source files are below. 

mymod.f90:
      module mymod
         interface my_interface
            subroutine my_subroutine
               integer i
            end subroutine my_subroutine
         end interface
      end module 

main.f90:
      program main
         print *, "hello world"
      end program


On Dec 24, 2009, at 6:15 PM, Aaron Knister wrote:

> I'm running into a strange problem with openmpi and the pgi compiler (version 
> 9.0-4). I first stumbled across this when using petsc but have reduced it to 
> a few lines of test code to demonstrate the problem I'm seeing. Essentially 
> it appears as if a shared library contains a fortran-compiled object file 
> that a) was built with "-g" and b) contains "use mpi" will produce errors 
> similar to these when it is linked against:
> 
> ./libfoo.so: undefined reference to `mpi_sizeof3dch_'
> ./libfoo.so: undefined reference to `mpi_sizeof4dl_'
> ./libfoo.so: undefined reference to `mpi_sizeof2dl_'
> ./libfoo.so: undefined reference to `mpi_sizeof2dch_'
> ./libfoo.so: undefined reference to `mpi_sizeof0dl_'
> ./libfoo.so: undefined reference to `mpi_sizeof1dch_'
> ./libfoo.so: undefined reference to `mpi_sizeof3dl_'
> ./libfoo.so: undefined reference to `mpi_sizeof1dl_'
> ./libfoo.so: undefined reference to `mpi_sizeof0dch_'
> ./libfoo.so: undefined reference to `mpi_sizeof4dch_'
> 
> 
> Take the following code-
> 
> libfoo.f90:
>      subroutine printhi()
>         use mpi
> !     do some mpi stuff
>        print *, "Hello"
> 
>      end
> 
> main.f90:
>      program myprog
>          call printhi()
>      end 
> 
> And to compile (using openmpi built with pgi):
> mpif90 -g -c -fPIC libfoo.f90
> cc -shared -Wl -o libfoo.so libfoo.o
> mpif90 -g main.f90 -lfoo -L. -o main
> 
> If I remove the "-g" from the first mpif90 command, then the compile finishes 
> and there are no errors about undefined references.
> 
> This occurs with openmpi-1.4 but ONLY with the pgi fortran compilers. I can't 
> reproduce this behavior with either gnu gfortran or intel's ifort. 
> 
> I'm not sure if this is a pgi problem or an openmpi problem or if I'm missing 
> something.
> 
> Any help would be much appreciated!
> 
> -Aaron


Reply via email to