Many-to-One and Many-to-Many Communication
Start listening on a channel for many-to-one communication.
In[1]:=
![Click for copyable input](assets.en/many-to-one-and-many-to-many-communication/In_1.png)
listener = ChannelListen["master"]
Out[1]=
![](assets.en/many-to-one-and-many-to-many-communication/O_1.png)
Send messages to the channel from several sessions—for instance, from parallel kernels on the same machine.
In[2]:=
![Click for copyable input](assets.en/many-to-one-and-many-to-many-communication/In_2.png)
ParallelEvaluate[ChannelSend["master", $KernelID]]
Out[2]=
![](assets.en/many-to-one-and-many-to-many-communication/O_2.png)
The received messages.
In[3]:=
![Click for copyable input](assets.en/many-to-one-and-many-to-many-communication/In_3.png)
listener["Message", All]
Out[3]=
![](assets.en/many-to-one-and-many-to-many-communication/O_3.png)
A diagram of the message exchange.
show complete Wolfram Language input
Out[5]=
![](assets.en/many-to-one-and-many-to-many-communication/O_4.png)
Start listening on the same channel in multiple parallel kernel sessions.
In[6]:=
![Click for copyable input](assets.en/many-to-one-and-many-to-many-communication/In_6.png)
ParallelEvaluate[l = ChannelListen["all"]]
Out[6]=
![](assets.en/many-to-one-and-many-to-many-communication/O_5.png)
Let all the parallel kernels send their respective IDs to the channel.
In[7]:=
![Click for copyable input](assets.en/many-to-one-and-many-to-many-communication/In_7.png)
ParallelEvaluate[ChannelSend["all", $KernelID]]
Out[7]=
![](assets.en/many-to-one-and-many-to-many-communication/O_6.png)
Messages received by the listeners, with their respective kernel IDs.
In[8]:=
![Click for copyable input](assets.en/many-to-one-and-many-to-many-communication/In_8.png)
ParallelEvaluate[$KernelID -> l["Message", All]]
Out[8]=
![](assets.en/many-to-one-and-many-to-many-communication/O_7.png)
A diagram of the exchange.
show complete Wolfram Language input
Out[9]=
![](assets.en/many-to-one-and-many-to-many-communication/O_8.png)