多対1通信と多対多通信
多対1通信のチャネルでリッスン(待ち受け)し始める.
In[1]:=
![Click for copyable input](assets.ja/many-to-one-and-many-to-many-communication/In_1.png)
listener = ChannelListen["master"]
Out[1]=
![](assets.ja/many-to-one-and-many-to-many-communication/O_1.png)
複数のセッション(例えば,同じマシンの並列カーネル)からチャネルにメッセージを送信する.
In[2]:=
![Click for copyable input](assets.ja/many-to-one-and-many-to-many-communication/In_2.png)
ParallelEvaluate[ChannelSend["master", $KernelID]]
Out[2]=
![](assets.ja/many-to-one-and-many-to-many-communication/O_2.png)
受信されたメッセージ.
In[3]:=
![Click for copyable input](assets.ja/many-to-one-and-many-to-many-communication/In_3.png)
listener["Message", All]
Out[3]=
![](assets.ja/many-to-one-and-many-to-many-communication/O_3.png)
メッセージ交信のダイアグラム.
完全なWolfram言語入力を表示する
Out[5]=
![](assets.ja/many-to-one-and-many-to-many-communication/O_4.png)
複数の並列カーネルセッション内の同じチャネルでリッスンし始める.
In[6]:=
![Click for copyable input](assets.ja/many-to-one-and-many-to-many-communication/In_6.png)
ParallelEvaluate[l = ChannelListen["all"]]
Out[6]=
![](assets.ja/many-to-one-and-many-to-many-communication/O_5.png)
すべての並列カーネルがそれぞれのIDをチャネルに送信するようにする.
In[7]:=
![Click for copyable input](assets.ja/many-to-one-and-many-to-many-communication/In_7.png)
ParallelEvaluate[ChannelSend["all", $KernelID]]
Out[7]=
![](assets.ja/many-to-one-and-many-to-many-communication/O_6.png)
それぞれのカーネルIDとともにリスナによって受け取られたメッセージ.
In[8]:=
![Click for copyable input](assets.ja/many-to-one-and-many-to-many-communication/In_8.png)
ParallelEvaluate[$KernelID -> l["Message", All]]
Out[8]=
![](assets.ja/many-to-one-and-many-to-many-communication/O_7.png)
交信のダイアグラム.
完全なWolfram言語入力を表示する
Out[9]=
![](assets.ja/many-to-one-and-many-to-many-communication/O_8.png)