Search code examples
cparallel-processingmpihpccommunicator

How to broadcast message from one process in a communicator A to all processes of a communicator B in MPI using C language?


I am a beginner in parallel-processing, I want to send one value from a process belonging to communicator A to all processes in a communicator B , I tried to use the MPI_Bcast(), the process_sender should belong to Communicator B but it doesn't

MPI_Bcast(&value ,value_size ,MPI_INT ,process_sender_rank, CommunicatorB);

how can I communicate between two separated communicators, please help me


Solution

  • In MPI processes can only communicate among processes within their communicator. From the source:

    Internally, MPI has to keep up with (among other things) two major parts of a communicator, the context (or ID) that differentiates one communicator from another and the group of processes contained by the communicator. The context is what prevents an operation on one communicator from matching with a similar operation on another communicator. MPI keeps an ID for each communicator internally to prevent the mixups.

    In your case you can form a new communicator compose by the process A and the processes belonging to the communicator B. Lets call it CommunicatorC, then you can call the routine again but this time using the new communicator:

    MPI_Bcast(&value ,value_size ,MPI_INT ,process_sender_rank, CommunicatorC);