astromaddie
astromaddie

Reputation: 81

Intercommunication with spawned process in mpi4py?

Given a situation where master process A spawns a set of worker processes B, who each spawn their own unique worker process C, how can I open a communicator between C to A?

I'm trying to create a loop, using mpi4py, between several pieces of code that were written separately from one another while minimizing modifications to the codes. So, the general framework of the MPI code is going to be:

  1. Master A (one process) spawns 8 processes of worker B, and scatters an array to them.
  2. Each B process spawns a worker C, does some manipulation to the array, and broadcasts it to their own worker.
  3. Each worker C manipulates the array in their own way, and then (ideally) master A gathers an array back from each of C's arrays.

I know this will involve opening an intercommunicator between existing processes, possibly using group communication. What would be the best way to accomplish this?

Thank you.

Upvotes: 4

Views: 735

Answers (1)

Wesley Bland
Wesley Bland

Reputation: 9062

There are two ways you can do this off the top of my head. I wouldn't say one is better or worse than the other, though the first probably matches your use case better.

  1. Use the name publishing system (or some other method) to open a connection using MPI_COMM_CONNECT and MPI_COMM_ACCEPT to connect A to whomever needs to communicate with it. This might result in a bunch of communicators for A depending on how many processes you are creating so this may result in some bad things, but this is probably the most direct way to make this work. You'll just have to have A do a bunch of calls to MPI_COMM_ACCEPT (unfortunately there isn't a non-blocking version of this call).

  2. Continually merge your intercommunicators that you're creating with MPI_COMM_SPAWN to create one giant communicator containing all of the processes. Then you can just send messages as you usually would (or create new sub-communciators with A and all of the spawnees so you can do collectives among just them).

Upvotes: 2

Related Questions