cea-hpc / wi4mpi

Wrapper interface for MPI
BSD 3-Clause "New" or "Revised" License
80 stars 15 forks source link

wi4mpi, mpi4py and mpich: undefined symbol: MPI_UNWEIGHTED #49

Closed laurent-nguyen closed 9 months ago

laurent-nguyen commented 1 year ago

HI wi4mpi team,

I got an error with wi4mpi, mpi4py and mpich when I use the preload mode from mpich to openmpi. Here the way to reproduce on Rhel8:

$ which mpicc
/usr/lib64/mpich/bin/mpicc
$ spack install wi4mpi
$ pip3 install mpi4py
Collecting mpi4py
  Downloading mpi4py-3.1.4.tar.gz (2.5 MB)
     |████████████████████████████████| 2.5 MB 6.5 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: mpi4py
  Building wheel for mpi4py (PEP 517) ... done
  Created wheel for mpi4py: filename=mpi4py-3.1.4-cp39-cp39-linux_x86_64.whl size=3006388 sha256=489b8a2bd60afa88788b2e14a5026d06ac49c5b4e0651a8e1fe2269ef4aa8d85
  Stored in directory: ~/.cache/pip/wheels/db/81/9f/43a031fce121c845baca1c5d9a1468cad98208286aa2832de9
Successfully built mpi4py
Installing collected packages: mpi4py
Successfully installed mpi4py-3.1.4
$ cat hello.py
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
if rank == 0:
    print("There are {} processes".format(size))
print("Rank: {}".format(rank))
$ python3 ./hello.py
There are 1 processes
Rank: 0
$ ldd ~/mypython/lib64/python3.9/site-packages/mpi4py/MPI.cpython-39-x86_64-linux-gnu.so
    linux-vdso.so.1 (0x00007ffc4d7f8000)
    libdl.so.2 => /usr/lib64/libdl.so.2 (0x00007f78c8bfd000)
    libmpi.so.12 => /usr/lib64/mpich/lib/libmpi.so.12 (0x00007f78c7ef9000)
    libpthread.so.0 => /usr/lib64/libpthread.so.0 (0x00007f78c7cd9000)
    libc.so.6 => /usr/lib64/libc.so.6 (0x00007f78c7913000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f78c9163000)
    libhwloc.so.15 => /lib64/libhwloc.so.15 (0x00007f78c76c3000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f78c74bb000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f78c7139000)
$ spack load wi4mpi
$ wi4mpi -f mpich -t openmpi python3 ./hello.py
File "~/tests/mpi4py/./hello.py", line 1, in <module>
    from mpi4py import MPI
ImportError: ~/mypython/lib64/python3.9/site-packages/mpi4py/MPI.cpython-39-x86_64-linux-gnu.so: undefined symbol: MPI_UNWEIGHTED

Note that if mpi4py is compiled with OpenMPI, it does work!

Regards,

spoutn1k commented 1 year ago

It would seem that, comparably to my #44 pull request, a symbol defined by MPICH is defined as a macro by OpenMPI, so the symbol does not appear in the final binary.

#defined here: https://github.com/open-mpi/ompi/blob/1a737357b7f9704f7795187c3cf3e0bb0261eba7/ompi/include/mpi.h.in#L564

I will try and make a similar PR to define this value.

Edit: I naively added an override so that in the MPICH_OMPI library, a MPI_UNWEIGHTED integer pointer is created, toward what seemed to be the default MPICH value found here, and that resulted in a nice old segmentation fault.

I need help understanding what transformations the mpi.h.in goes through. In the OpenMPI permalink above, the value of MPI_UNWEIGHTED is defined like so:

#define MPI_UNWEIGHTED           ((int *) 2)           /* unweighted graph */

What does that 2 stand for ?