Skip to content

Conversation

@williamjameshandley
Copy link

Summary

  • Add optional comm parameter to BinMinMPI, BinMinBottomUp, and all interface functions
  • Allows users to pass custom MPI communicators instead of always using MPI.COMM_WORLD
  • Enables running binminpy on a subset of MPI ranks or integrating into larger MPI applications

Changes

  • BinMinMPI.__init__(): Added comm=None parameter, store as self.comm
  • BinMinBottomUp.__init__(): Added comm=None parameter, store as self.comm
  • All interface functions (minimize, differential_evolution, etc.): Added comm=None parameter
  • _run_optimizer(): Pass comm through to BinMinMPI constructor

Backward Compatibility

Fully backward compatible - when comm is not specified (or is None), defaults to MPI.COMM_WORLD.

Example Usage

from mpi4py import MPI

# Create a subcommunicator (e.g., first 4 ranks)
world = MPI.COMM_WORLD
subcomm = world.Split(color=0 if world.Get_rank() < 4 else 1)

# Use with binminpy
result = binminpy.minimize(
    target_function,
    binning_tuples,
    parallelization="mpi",
    comm=subcomm,  # Use custom communicator
)

Test plan

  • Added tests/test_custom_comm.py - Tests BinMinMPI with explicit COMM_WORLD and subcommunicators
  • Added tests/test_custom_comm_bottomup.py - Tests BinMinBottomUp with explicit COMM_WORLD
  • Run with mpiexec -np 4 python tests/test_custom_comm.py
  • Run with mpiexec -np 4 python tests/test_custom_comm_bottomup.py

🤖 Generated with Claude Code

Add optional `comm` parameter to BinMinMPI, BinMinBottomUp, and all
interface functions to allow users to pass custom MPI communicators
instead of always using MPI.COMM_WORLD.

This enables running binminpy on a subset of MPI ranks or integrating
it into larger MPI applications that need to partition communicators.

The change is fully backward compatible - when `comm` is not specified
(or is None), the default MPI.COMM_WORLD is used.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

1 participant