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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danbeibei opened this issue Jun 2, 2020 · 1 comment · Fixed by #16730
Closed

f2py undefined symbol with PGI fortran compiler and MPI calls #16481

danbeibei opened this issue Jun 2, 2020 · 1 comment · Fixed by #16730

Comments

@danbeibei
Copy link
Contributor
danbeibei commented Jun 2, 2020

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.

@danbeibei
Copy link
Contributor Author

An other possible workaround is to define LDSHARED environment variable:
LDSHARED=mpif90 CC=gcc f2py --verbose --f90exec=mpif90 --fcompiler=pg -c helloworld.f90 -m helloworld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0