8000 f2py undefined symbol with PGI fortran compiler and MPI calls · Issue #16481 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
f2py undefined symbol with PGI fortran compiler and MPI calls #16481
@danbeibei

Description

@danbeibei

I am trying to wrap fortran code with f2py. The fortran code includes some MPI calls and is compiled with the PGI compiler.
When importing the wrapped module in python I get this error: undefined symbol: mpi_comm_rank_

Reproducing code example:

1 ! file: helloworld.f90
2 subroutine sayhello(comm)
3   use mpi
4   implicit none
5   integer :: comm, rank, size, ierr
6   call MPI_Comm_size(comm, size, ierr)
7   call MPI_Comm_rank(comm, rank, ierr)
8   print *, 'Hello, World! I am process ',rank,' of ',size,'.'
9 end subroutine sayhello

Compilation

CC=gcc f2py --verbose --f90exec=mpif90 --fcompiler=pg -c helloworld.f90 -m helloworld

Partial output

[...]
<class 'numpy.distutils.fcompiler.pg.PGroupFCompiler'>
version_cmd     = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-V']
compiler_f77    = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']
compiler_fix    = ['***/spectrum_mpi/10.03.00.01rtm3-rh7_20190611/bin/mpif90', '-Mfixed', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']
compiler_f90    = ['***/spectrum_mpi/10.03.00.01rtm3-rh7_20190611/bin/mpif90', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']
linker_so       = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-shared', '-fpic']
archiver        = None
ranlib          = None
linker_exe      = None
version         = LooseVersion ('19.9-0')
libraries       = []
library_dirs    = []
object_switch   = '-o '
compile_switch  = '-c'
include_dirs    = ['***/python_venv/python_numpy_pgi_reproducer/include', '***/anaconda3/2019.03/include/python3.7m']
[...]
***/pgi/linuxpower/19.9/bin/pgfortran -shared -fpic /tmp/tmpfy731xy8/tmp/tmpfy731xy8/src.linux-ppc64le-3.7/helloworldmodule.o /tmp/tmpfy731xy8/tmp/tmpfy731xy8/src.linux-ppc64le-3.7/fortranobject.o /tmp/tmpfy731xy8/helloworld.o -o ./helloworld.cpython-37m-powerpc64le-linux-gnu.so
Removing build directory /tmp/tmpfy731xy8

The "linker_so" executable is chosen to be the pgfortran executable, whereas I would like to use the mpif90 executable instead.
This leads to the following error when importing the wrapped module from python:

$ python -c "import helloworld"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: ***/helloworld.cpython-37m-powerpc64le-linux-gnu.so: undefined symbol: mpi_comm_rank_

System informations

$ mpif90 --version
pgf90 19.9-0 linuxpower target on Linuxpower
$ python --version
Python 3.7.3
$ python -c "import sys, numpy; print(numpy.__version__, sys.version)"
1.18.4 3.7.3 (default, Mar 27 2019, 22:31:02)
[GCC 7.3.0]

Workarround

This solves the problem in my case:
In file numpy/distutils/fcompiler/pg.py - line 36 (numpy installed version)

-'linker_so': ["pgfortran"],
+'linker_so': ["<F90>"],

The executable supplied with the --f90exec option is then the one picked to be the linker executable and the ImportError does not occur.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0