mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.51k stars 1.6k forks source link

MPI detection independent of compilers (mpich, openmpi, intel mpi) needed for conda-forge #13615

Open paugier opened 2 weeks ago

paugier commented 2 weeks ago

Describe the bug

Meson does not detect mpich on conda-forge (using GCC) (see an example of failing build here).

Conda-forge usually builds packages depending on MPI with different implementations. For example, in https://github.com/conda-forge/mpi4py-feedstock/blob/main/recipe/conda_build_config.yaml, there is

mpi:
  - mpich    # [not win]
  - openmpi  # [not win]
  - impi     # [not osx and x86_64]
  - msmpi    # [win]

~At least for mpich,~ the build uses GCC for mpich, openmpi and impi (see for example https://github.com/conda-forge/mpi4py-feedstock/blob/main/.ci_support/linux_64_mpiimpipython3.10.____cpython.yaml).

This issue is very similar to https://github.com/mesonbuild/meson/issues/7045 except that it is about mpich.

More generally, (I think) mpich, openmpi and Intel MPI can be compiled both with GCC and icc and this is very common to have on clusters different modules for the different cases.

To Reproduce

One can for example try to build https://foss.heptapod.net/fluiddyn/fluidfft/-/tree/branch/default/plugins/fluidfft-fftwmpi (simple meson.build) in an environment created with:

conda create -n env-fluidfft-mpich -c conda-forge \
  fluidfft h5py[build=mpi*] mpi4py mpich fftw[build=mpi*] cxx-compiler \
  meson meson-python pkg-config fluidfft-builder transonic cython

In this environment we have (as expected):

$ which mpicc
/data/mambaforge/envs/env-fluidfft-mpich/bin/mpicc
$ mpicc --version
x86_64-conda-linux-gnu-cc (conda-forge gcc 12.4.0-1) 12.4.0
$ mpichversion
MPICH Version:      4.2.2
MPICH Release date: Wed Jul  3 09:16:22 AM CDT 2024
MPICH ABI:          16:2:4
MPICH Device:       ch4:ofi
MPICH configure:    --prefix=/data/mambaforge/envs/env-fluidfft-mpich --disable-dependency-tracking --enable-cxx --enable-fortran --enable-f08 --with-wrapper-dl-type=none --disable-opencl --with-device=ch4
MPICH CC:           x86_64-conda-linux-gnu-cc -I/data/mambaforge/envs/env-fluidfft-mpich/include -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/mambaforge/envs/env-fluidfft-mpich/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/mpich-mpi_1722432564557/work=/usr/local/src/conda/mpich-4.2.2 -fdebug-prefix-map=/data/mambaforge/envs/env-fluidfft-mpich=/usr/local/src/conda-prefix -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/mambaforge/envs/env-fluidfft-mpich/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/mpich-mpi_1722432564557/work=/usr/local/src/conda/mpich-4.2.2 -fdebug-prefix-map=/data/mambaforge/envs/env-fluidfft-mpich=/usr/local/src/conda-prefix  -O2
MPICH CXX:          x86_64-conda-linux-gnu-c++ -I/data/mambaforge/envs/env-fluidfft-mpich/include -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/mambaforge/envs/env-fluidfft-mpich/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/mpich-mpi_1722432564557/work=/usr/local/src/conda/mpich-4.2.2 -fdebug-prefix-map=/data/mambaforge/envs/env-fluidfft-mpich=/usr/local/src/conda-prefix -O2
MPICH F77:          x86_64-conda-linux-gnu-gfortran -I/data/mambaforge/envs/env-fluidfft-mpich/include -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/mambaforge/envs/env-fluidfft-mpich/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/mpich-mpi_1722432564557/work=/usr/local/src/conda/mpich-4.2.2 -fdebug-prefix-map=/data/mambaforge/envs/env-fluidfft-mpich=/usr/local/src/conda-prefix -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/mambaforge/envs/env-fluidfft-mpich/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/mpich-mpi_1722432564557/work=/usr/local/src/conda/mpich-4.2.2 -fdebug-prefix-map=/data/mambaforge/envs/env-fluidfft-mpich=/usr/local/src/conda-prefix -O2
MPICH FC:           x86_64-conda-linux-gnu-gfortran -I/data/mambaforge/envs/env-fluidfft-mpich/include -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/mambaforge/envs/env-fluidfft-mpich/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/mpich-mpi_1722432564557/work=/usr/local/src/conda/mpich-4.2.2 -fdebug-prefix-map=/data/mambaforge/envs/env-fluidfft-mpich=/usr/local/src/conda-prefix -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /data/mambaforge/envs/env-fluidfft-mpich/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/mpich-mpi_1722432564557/work=/usr/local/src/conda/mpich-4.2.2 -fdebug-prefix-map=/data/mambaforge/envs/env-fluidfft-mpich=/usr/local/src/conda-prefix -O2
MPICH features:     threadcomm

Building fluidfft-fftwmpi with pip install -e . -v --no-build-isolation gives:

Using pip 24.2 from /data/mambaforge/envs/env-fluidfft-mpich/lib/python3.12/site-packages/pip (python 3.12)
Obtaining file:///home/users/augier3pi/dev/fluidfft/plugins/fluidfft-fftwmpi
  Running command Checking if build backend supports build_editable
  Checking if build backend supports build_editable ... done
  Running command Preparing editable metadata (pyproject.toml)
  + meson setup /home/users/augier3pi/dev/fluidfft/plugins/fluidfft-fftwmpi /home/users/augier3pi/dev/fluidfft/plugins/fluidfft-fftwmpi/build/cp312 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=/home/users/augier3pi/dev/fluidfft/plugins/fluidfft-fftwmpi/build/cp312/meson-python-native-file.ini
  The Meson build system
  Version: 1.5.99
  Source dir: /home/users/augier3pi/dev/fluidfft/plugins/fluidfft-fftwmpi
  Build dir: /home/users/augier3pi/dev/fluidfft/plugins/fluidfft-fftwmpi/build/cp312
  Build type: native build
  Project name: fluidfft-fftwmpi
  Project version: undefined
  C++ compiler for the host machine: /data/mambaforge/envs/env-fluidfft-mpich/bin/x86_64-conda-linux-gnu-c++ (gcc 12.4.0 "x86_64-conda-linux-gnu-c++ (conda-forge gcc 12.4.0-1) 12.4.0")
  C++ linker for the host machine: /data/mambaforge/envs/env-fluidfft-mpich/bin/x86_64-conda-linux-gnu-c++ ld.bfd 2.40
  Cython compiler for the host machine: cython (cython 3.0.11)
  Host machine cpu family: x86_64
  Host machine cpu: x86_64
  Found pkg-config: YES (/data/mambaforge/envs/env-fluidfft-mpich/bin/pkg-config) 0.29.2
  Run-time dependency fftw3 found: YES 3.3.10
  mpic++ found: NO
  Run-time dependency MPI for cpp found: NO (tried config-tool)

  ../../meson.build:15:10: ERROR: Dependency "mpi" not found, tried config-tool

Note that using

mpi_dep = dependency('mpi', language: 'cpp', method : 'config-tool')

does not fix the issue.

Expected behavior

Meson should be able to detect mpich from mpicc (and friends) which are in $PATH.

Explanation

The logic in https://github.com/mesonbuild/meson/blob/master/mesonbuild/dependencies/mpi.py is wrong as explained in

I particularly agree with https://github.com/mesonbuild/meson/pull/7373#issuecomment-1532046963

See also if one tries to improve MPI detection:

system parameters

Native build.

Debian 11 or 12 (but it does should be applicable on any Unix)

3.12 (but does not matter)

1.5.99 and master

1.12.1

eli-schwartz commented 2 weeks ago

That comment has already been deleted by github admins for malware, in multiple different issues. Please don't respond further to it. :)

paugier commented 2 weeks ago

We can install the different implementations with conda.

conda create -n env-openmpi openmpi c-compiler
conda create -n env-impi impi-devel c-compiler
conda create -n env-mpich mpich c-compiler

On Unix, one has to find a command mpi${LANG} (or mpi${INTEL_COMPILER_NAME} for intel compilers) (given by the corresponding environment variables or found in the path).

To find the compile and link options, one needs to run

# mpich and impi (and I guess mvapich)
mpicc -compile_info
mpicc -link_info
# openmpi
mpicc -showme:compile
mpicc -showme:link

Note that the -showme options only gives the options whereas -compile_info and -link_info gives the full command.

Note that the -show option (currently used for impi in Meson) seems to work for all implementations.

$ mpicc -show 
gcc -I"/data/mambaforge/envs/env-impi/include" -L"/data/mambaforge/envs/env-impi/lib/release" -L"/data/mambaforge/envs/env-impi/lib" -Xlinker --enable-new-dtags -Xlinker -rpath -Xlinker "/data/mambaforge/envs/env-impi/lib/release" -Xlinker -rpath -Xlinker "/data/mambaforge/envs/env-impi/lib" -lmpifort -lmpi -lrt -lpthread -Wl,-z,now -Wl,-z,relro -Wl,-z,noexecstack -Xlinker --enable-new-dtags -ldl

$ mpicc -show
x86_64-conda-linux-gnu-cc -I/data/mambaforge/envs/env-fluidfft-openmpi/include -pthread -L/data/mambaforge/envs/env-fluidfft-openmpi/lib -Wl,--allow-shlib-undefined -Wl,-rpath -Wl,/data/mambaforge/envs/env-fluidfft-openmpi/lib -lmpi

$ mpicc -show
x86_64-conda-linux-gnu-cc -I/data/mambaforge/envs/env-fluidfft-mpich/include -I/data/mambaforge/envs/env-fluidfft-mpich/include -L/data/mambaforge/envs/env-fluidfft-mpich/lib -Wl,-rpath,/data/mambaforge/envs/env-fluidfft-mpich/lib -I/data/mambaforge/envs/env-fluidfft-mpich/include -L/data/mambaforge/envs/env-fluidfft-mpich/lib -lmpi
paugier commented 2 weeks ago

Getting the version is not so simple:

Only for OpenMPI

$ mpicc --showme:version
mpicc: Open MPI 5.0.5 (Language: C)

For other implementation:

mpicc -v
mpicc for MPICH version 4.2.2
[...]

$ mpicc -v
mpigcc for the Intel(R) MPI Library 2021.13 for Linux*
[...]