Skip to content

ParallelError in dune-grid Python bindings with OpenMPI

Hi everyone,

I encountered an issue with the DUNE Python bindings last week, which I can trigger by calling dune.grid.structuredGrid(). To summarize: I have to call from mpi4py import MPI before using functions from dune.grid, otherwise DUNE throws a ParallelError:

import dune.grid
# from mpi4py import MPI <-- this line will prevent the RuntimeError

dune.grid.structuredGrid([-1], [0], [10])
RuntimeError: ParallelError [Communication:/home/valentina/mambaforge/envs/richards-swe/include/dune/common/parallel/mpicommunication.hh:118]: 
You must call MPIHelper::instance(argc,argv) in your main() function before using the MPI Communication!

It seems like MPI is not initialized properly by the Python bindings in this setup.

Remark 1. The following additional import statements do not prevent this error:

  • import mpi4py
  • import dune.common
  • it also does not help to do from dune.grid import structuredGrid

Remark 2. If I use MPICH instead of OpenMPI, I do not need from mpi4py import MPI. Checking the DUNE source code for the error indicates that there is a difference between OpenMPI and MPICH with respect to how/if MPI is initialized by DUNE/the Python bindings?

Remark 3. Note that I never actually use MPI from mpi4py in this example. A linter will thus complain about the import statement, which is unfortunate.

Environment

Latest version of DUNE modules installed via PyPI (pip install dune-fem):

dune-alugrid                  2.9.0.2
dune-common                   2.9.0
dune-fem                      2.9.0.2
dune-geometry                 2.9.0
dune-grid                     2.9.0
dune-istl                     2.9.0
dune-localfunctions           2.9.0
...
mpi4py                        3.1.4
  • Python: 3.10.11 (inside a mamba/conda environment)
  • gcc/g++ 11.3 (Ubuntu 22.04)
  • OpenMPI: 4.1.2.

I verified that OpenMPI and mpi4py are installed and working correctly on my system, using a simple MPI example and the first example from the mpi4py tutorial.

Let me know if you need any additional information! Best, Valentina