{"id":4122,"library":"mpi4py","title":"MPI for Python","description":"mpi4py provides Python bindings for the Message Passing Interface (MPI) standard, enabling parallel programming with Python. It allows Python applications to leverage high-performance distributed memory architectures. The current version is 4.1.1, and it typically sees a few minor and patch releases per year, with major feature updates (like MPI standard support) in new minor versions.","status":"active","version":"4.1.1","language":"en","source_language":"en","source_url":"https://github.com/mpi4py/mpi4py","tags":["mpi","parallel computing","hpc","distributed computing","scientific computing"],"install":[{"cmd":"pip install mpi4py","lang":"bash","label":"Install mpi4py"}],"dependencies":[],"imports":[{"note":"The 'MPI' object provides access to all MPI functions, types, and constants (e.g., MPI.COMM_WORLD, MPI.INT). Do not confuse 'mpi4py' (the package) with 'MPI' (the imported object).","symbol":"MPI","correct":"from mpi4py import MPI"}],"quickstart":{"code":"from mpi4py import MPI\nimport os\n\n# Get the default communicator (all processes)\ncomm = MPI.COMM_WORLD\n\n# Get the rank of the current process\nrank = comm.Get_rank()\n\n# Get the total number of processes\nsize = comm.Get_size()\n\n# Each process prints its rank and size\nprint(f\"Hello from process {rank} of {size} on host {os.uname().nodename}\")\n\n# Use a barrier to ensure all processes reach this point before exiting\ncomm.Barrier()","lang":"python","description":"This 'Hello, World!' example demonstrates how to initialize MPI, get the rank of the current process, and the total number of processes in the communicator. Save it as `hello.py` and run with `mpirun -np 4 python hello.py` for 4 processes."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer to use mpi4py versions 4.0.0+.","message":"Python 2.x support was dropped after mpi4py version 3.1.6. Versions 4.x and newer require Python 3.8+.","severity":"breaking","affected_versions":"<=3.1.6 (last supporting Python 2)"},{"fix":"Consult the official mpi4py documentation and MPI-4.0 standard for details on new features and potential API changes if migrating from older MPI standards.","message":"Version 4.0.0 introduced support for the MPI-4.0 standard, including new features like sessions, persistent collectives, and partitioned communication. While mostly backward compatible, existing code might need updates to leverage new functionalities or if it relied on specific MPI-3 behaviors that changed in MPI-4.","severity":"breaking","affected_versions":"4.0.0+"},{"fix":"Ensure a compatible MPI library (and its development headers if building from source) is installed on your system before installing and using mpi4py.","message":"mpi4py requires an underlying MPI implementation (e.g., Open MPI, MPICH, Intel MPI) to be installed on the system. It is a Python binding, not a standalone MPI library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Run your mpi4py script with `mpirun -np N python your_script.py`, replacing `N` with the desired number of processes.","message":"MPI programs, including those written with mpi4py, must be executed using an MPI launcher like `mpirun` or `mpiexec`, not simply `python your_script.py`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install the appropriate MPI development package for your system's MPI distribution.","message":"When installing mpi4py from source (e.g., if pre-built wheels are not available for your system/MPI configuration), you typically need MPI development headers installed (e.g., `libopenmpi-dev` or `mpich-dev` on Debian/Ubuntu, `openmpi-devel` or `mpich-devel` on CentOS/Fedora).","severity":"gotcha","affected_versions":"All versions (when building from source)"},{"fix":"Check `mpi4py` documentation for wheel ABI compatibility. If an incompatibility exists, build `mpi4py` from source (`pip install mpi4py --no-binary :all:`) after ensuring MPI development headers are present.","message":"Pre-built `mpi4py` wheels available on PyPI are built against specific MPI Application Binary Interfaces (ABIs), typically MPICH or Open MPI. If your system's MPI implementation is ABI-incompatible with the wheel, you may encounter runtime errors and will need to build `mpi4py` from source against your specific MPI library.","severity":"gotcha","affected_versions":"4.1.0+"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}