Skip to content

Add MPI support to the Python API - #429

Draft
LourensVeen wants to merge 3 commits into
developfrom
issue_375_python_mpi_support
Draft

LourensVeen wants to merge 3 commits into
developfrom
issue_375_python_mpi_support

Conversation

@LourensVeen

Copy link
Copy Markdown
Contributor

This adds MPI support to the Python API, addressing #375.

I started with refactoring the C++ implementation a bit, before translating it to Python. I didn't have much MPI experience when I made it, and I've since learnt that with MPI-optional code it's easier to assume MPI and take the non-MPI version as the exception rather than the other way around.

That leads to pushing the MPI-specific stuff down the call hierarchy as much as possible, and there's some ordinary refactoring there as well, which simplifies everything nicely.

For the Python API, I've decided to add a keyword-only mpi=True argument to Instance which must be passed if you're using MPI. In C++, there's a preprocessor define and linking with the MPI version of the library for that, but that's not how Python works. If mpi=True is passed, then libmuscle will require mpi4py and run in MPI mode. With mpi=False or unspecified, mpi4py is not required and everything works as before.

(The Python side is still to be implemented, but I wanted to make sure the CI works with what I've got so far, hence the draft PR.)

This moves the checks for MPI from Instance down into the MPITcpBarrier
class, where they're much less in the way.
@LourensVeen LourensVeen self-assigned this Nov 17, 2026
@maarten-ic

Copy link
Copy Markdown
Collaborator

Had a quick look at the changes, and this looks much cleaner and easier than the previous #ifdef MUSCLE_ENABLE_MPI scattered in the implementation 😍

Let me know if/when you'd like a more in-depth review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants