Wolfram Language

Channel Framework

Many-to-One and Many-to-Many Communication

Start listening on a channel for many-to-one communication.

In[1]:=
Click for copyable input
listener = ChannelListen["master"]
Out[1]=

Send messages to the channel from several sessionsfor instance, from parallel kernels on the same machine.

In[2]:=
Click for copyable input
ParallelEvaluate[ChannelSend["master", $KernelID]]
Out[2]=

The received messages.

In[3]:=
Click for copyable input
listener["Message", All]
Out[3]=

A diagram of the message exchange.

show complete Wolfram Language input
In[4]:=
Click for copyable input
spikey = ImageCrop@ Import["http://www.wolfram.com/spikey/img/spikey.png"];
In[5]:=
Click for copyable input
Graph[Table[i \[DirectedEdge] 0, {i, listener["MessageID", All]}], VertexShape -> spikey, VertexSize -> .5]
Out[5]=

Start listening on the same channel in multiple parallel kernel sessions.

In[6]:=
Click for copyable input
ParallelEvaluate[l = ChannelListen["all"]]
Out[6]=

Let all the parallel kernels send their respective IDs to the channel.

In[7]:=
Click for copyable input
ParallelEvaluate[ChannelSend["all", $KernelID]]
Out[7]=

Messages received by the listeners, with their respective kernel IDs.

In[8]:=
Click for copyable input
ParallelEvaluate[$KernelID -> l["Message", All]]
Out[8]=

A diagram of the exchange.

show complete Wolfram Language input
In[9]:=
Click for copyable input
ParallelEvaluate[$KernelID -> l["Message", All]]; Graph[Flatten[Thread /@ %], VertexShape -> spikey, VertexSize -> .5]
Out[9]=

Related Examples

de es fr ja ko pt-br ru zh