Message Boards Message Boards

Parallel computing environment with ZMQ on the Raspberry Pi cluster

Posted 3 years ago

Previous my parallel computing mechanism worked well, however, the sequence was little-bit complex. Mathematica introduced ZMQ from ver.11 and brushed up with ver.12. With ZMQ, we can develop a parallel computer system very easily. The basic code and first result are shown here, using Raspberry Pi cluster composed of, one Raspberry Pi 4B for the server, and two Raspberry Pi Zero. Three boards were build up to a computing cluster with Powered USB bus adapter connected to PC, in this case, Mac.

Preparation for the Raspberry Pi system

Each Raspberry Pi should be prepared for running RNDIS/Ethernet Gadget (with PC using a USB cable, Raspberry Pi can handle through the PC). Then we can control each Raspberry Pi through a X11 window of Mac Xquartz (should be started in advance). Also, you can use VNC viewer.

First step is starting Mathematica on each Raspberry Pi, as following steps.

a. with PC terminal, login to Raspberry Pi as (supposing Raspberry Pi name is "RspberryPi6, ..Pi3, and ...Pi12), where user name is "pi."

$ ssh -X pi@RaspberryPi6.local

b. with PC terminal, let's start Raspberry Pi Mathematica, and wait the opening of Mathematica X-window.

pi@raspberrypi6:~ $ mathematica &

c. repeat this process for raspberrypi3(another Raspberry Pi Zero) and for raspberrypi12(Raspberry Pi 4B, in my case).

Code for the server (raspberrypi12)

in my local net, IP of raspberrypi12 is 192.168.1.8, and the definition port number, here I chosen, 40001, and 40002. Then following code will open the Socket. Some warning will come up, but the socket will work.

client1 = SocketOpen[{"192.168.1.8", 40001}, "ZMQ"];
client2 = SocketOpen[{"192.168.1.8", 40002}, "ZMQ"];

Then, you should write a code for each client. The client code, on the raspberrypi3, is,

server = SocketConnect[{"raspberrypi12.local", 40002}, "ZMQ"];

listener = 
 SocketListen[server, (WriteString[server, ToExpression[#Data]]) &]

Next, you should write a code for the another client, for example, raspberrypi6 is,

server = SocketConnect[{"raspberrypi12.local", 40002}, "ZMQ"];

listener = SocketListen[server, (WriteString[server, ToExpression[#Data]]) &]

All the code required for the clients are only 2-lines.

You will return to the server.

Next code is purposed to deploy the clients (client1 and client2) sample calculation code. When you execute the code, you will see Null as return.

WriteString[client1, "f[x_]:=(Pause[4];x^2-1)"];
ByteArrayToString[SocketReadMessage[client1]]

WriteString[client2, "f[x_]:=(Pause[4];x^2+1)"];
ByteArrayToString[SocketReadMessage[client2]]

A cord part "Pause[4]" is a dummy code to demonstrate the parallel computation. At this point, you can see a deployed and executable code from the client (through X11 window).

C. Evaluation of the parallel computing system on the Raspberry Pi cluster

Sample codes on the server are,

Timing[{WriteString[client1, "f[200]"], 
  WriteString[client2, "f[200]"]};
 {ByteArrayToString[SocketReadMessage[client1]], 
  ByteArrayToString[SocketReadMessage[client2]]}]

result is,

{5.55364, {"39999", "40001"}}

Comparing single cpu calculation, you will see as,

Timing[WriteString[client1, "f[200]"];
 ByteArrayToString[SocketReadMessage[client1]]]

result is,

{5.81473, "39999"}

Certainly, the parallel computation system is now working well.

This preliminary parallel computer environment has shown some advantages ,

  1. Server code is very simple
  2. client code has no necessity of modification for any applications
  3. local net is fulfilling the requirements for parallel computer system
  4. parallel node with multi-core can be easily developed
  5. ZMQ will run not only usb network but (powerd, and/or fast) ether net

Enjoy!

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract