'How to insert data into MPI communicator?
I have a Python script called manager.py starting some workers written in C++ using the MPI.COMM_WORLD.Spawn function from the mpi4py module. I can access the workers in the Python script with the returned communicator, which only contains the workers.
Is there a way to insert data from the Python script into the worker communicator? Something like Scatter but the data is comming from outside of the communicator. Later I need a vice versa function like Gather to get the data out of the communicator.
Solution 1:[1]
After some research I stumbled over the Iscatter and Igather methods.
When you call a program with MPI.COMM_WORLD.Spawn you create a new communicator, a so called Intercomm. That is because two groups are created. One containing all the manager processes and one for all the worker processes. An Intercomm is a communicator, which is capable of communicating between multiple groups.
Iscatter scatters data from the root process of one group to all processes of the other group.
Igather collects data from all processes of the other group to the group, where the root process is located.
Extra caution is necessary as this function calls are non-blocking. However they return a request object, which you have to wait on to make sure data transfer is finished. Otherwise you will provoke a segmentation fault.
Some documentations: OpenMPI Iscatter for C++, OpenMPI Igather for C++, mpi4py Iscatter, mpi4py Igather
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
