mpi4py: Importing the C API fails on Windows
I am trying to build a C++ Python extension (with pybind11) that uses MPI and mpi4py on Windows. I am working in a conda environment and I installed mpi4py as follows:
conda install mpi4py -c conda-forge --yes
The following:
// import the mpi4py API
if (import_mpi4py() < 0) {
  throw std::runtime_error("Could not load mpi4py API.");
}
throws the exception with traceback:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\IEUser\VeloxChemMP\build_dbg_14.27\lib\python3.8\site-packages\veloxchem\__init__.py", line 2, in <module>
    from .veloxchemlib import AtomBasis
ImportError: Could not load mpi4py API.
Running mpiexec -n 4 python -c “from mpi4py import MPI; comm = MPI.COMM_WORLD; print(comm.Get_rank())” works as expected. I am not sure whether this is a bug or some silly mistake I am making.
This issue was migrated from moved from BitBucket #177
About this issue
- Original URL
 - State: closed
 - Created 3 years ago
 - Comments: 60 (38 by maintainers)
 
Commits related to this issue
- mpi-compat: support MPI_Message on MS-MPI MS-MPI does not define an accurate `MPI_VERSION`, so `MPI_Message` is mis-detected. See: https://github.com/mpi4py/mpi4py/issues/19 — committed to mathstuf/netcdf4-python by mathstuf 6 months ago
 - mpi-compat: support MPI_Message on MS-MPI MS-MPI does not define an accurate `MPI_VERSION`, so `MPI_Message` is mis-detected. See: https://github.com/mpi4py/mpi4py/issues/19 — committed to mathstuf/netcdf4-python by mathstuf 6 months ago
 
I’ll merge the
bugfix/msmpibranch soon.I will keep using the
#ifdef ... #define ...in my code, keeping an eye out for new releases. Thanks!After the rebase, it builds (https://gitlab.com/robertodr/pybind11-mpi4py/-/jobs/1226563962) and runs tests (https://gitlab.com/robertodr/pybind11-mpi4py/-/jobs/1226563986) without problems. Will there be a new release of mpi4py after the branch is merged?
@leofang thanks for your help!
Ha we replied at the same time. Yeah sorry I got confused too. Glad it worked out.
@robertodr @dalcinl Looks like the
bugfix/msmpibranch + the latestmsmpiconda package makes everything work! https://gitlab.com/robertodr/pybind11-mpi4py/-/pipelines/294561734OK, I misunderstood the whole conversation then 🤦🏻 Indeed with the new msmpi package and mpi4py from the bugfix branch the build works and tests pass: https://gitlab.com/robertodr/pybind11-mpi4py/-/jobs/1223946613
The build and test jobs are split in two stages. The test stage sets up the environment and picks up the build artifacts from the previous one. I can run them together, though I doubt it would make a difference.
Thank you for working on it so thoroughly!
Thanks for testing @robertodr! OK looks like we need a rebuild. @dalcinl Please check out https://github.com/conda-forge/mpi4py-feedstock/pull/43 when you have time.
It still fails: https://gitlab.com/robertodr/pybind11-mpi4py/-/jobs/1221796371 but at least we’re back to:
here you go: https://gitlab.com/robertodr/pybind11-mpi4py/-/jobs/1217865968
Uhm, now testing fails: https://gitlab.com/robertodr/pybind11-mpi4py/-/jobs/1211049781#L185
I believe this should be enough for current mpi4py release to build without any patch.
I believe that the problem comes from using MSMPI from conda-forge. mpi4py is not seeing the right MS MPI version number at build time, because that does not come from
mpi.h, but from the Windows registry (when MS MPI is installed from the official Microsoft installer packages).@leofang @RyanMcCarthy-NOAA The MSMPI package in conda-forge is slightly broken, MSMPI_VER from
mpi.hdoes not reflect the actual version number. Because of that, the mpi4py package is disabling a lot of MPI features (e.g.MPI_Messageand matched probes).Hopefully in the weekend!
@robertodr Could you please try the
bugfix/msmpibranch I just pushed (commit 2b8fc6f)?Thanks the help! Do you wish this issue to be kept open until you figure out a more permanent fix?
What about the following way? [link]
Oh, sorry, I should have figured it out… The problem is that your wrapper is swallowing the actual Python exception and traceback, so this is not really useful.
Can you try to build and run the code in mpi4py’s
demo/wrap-cdirectory? If that one fails, we should get the nice traceback we are looking for.