That nice XU4Q on the picture above was not waiting in a shelf. I bought it when I saw that it had a special price in Hardkernels shop. But an old Windows tablet and a Raspberry Pi 2 were laying unused in my shelf. What to do with 16 CPU cores? Use them for experiments with grid computing!
Is it a Cluster or is it a Grid?It will use my (W)LAN and not the internet - that's an argument for a cluster. But it uses heterogenous hardware, isn't centrally managed, every node can operate independently, and I will write the software so that it doesn't trust the nodes - let's call it a grid.
Preparing the Grid NodesI need at least Java 11 on the nodes. For the Windows tablet and the Raspberry Pi 2 I downloaded it from Azul. For older Raspberry Pis on their Zulu Community Downloads page choose "Java 11 (LTS)", "Linux", "ARM 32-bit HF" and "JDK" as filters. On the XU4Q a sudo apt install openjdk-11-jre-headless
does the job.
I want that the nodes run and run and run with high CPU load. For the Windows tablet there is not much what I can do. But on the Raspberry Pi and on the XU4Q I installed log2ram to reduce the wear of the SD card. With cd /var/log
and sudo du -sh .
I first checked the size of the logs. On the XU4Q they were quite big, so I cleaned them with sudo journalctl --rotate
and sudo journalctl --vacuum-time=1s
.
Then I installed log2ram:
cd
git clone https://github.com/azlux/log2ram.git
cd log2ram/
chmod +x install.sh
sudo ./install.sh
sudo reboot
The XU4Q has 8 cores and a passive heatsink. To reduce the thermal stress on the CPU I activated the Ondemand governor (a service that chooses the CPU frequency depending on the load) with sudo systemctl enable ondemand
and sudo systemctl start ondemand
.
And I reduced the maximum CPU frequency. I created a file with the following contents:
#! /bin/bash
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq; do echo "1300000" > $file; done
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
and executed it with sudo
. Be careful: Setting unsupported CPU frequencies can damage your hardware. The XU4Q has four A15 cores and four A7 ones. The value 1300000
(corresponding to 1.3 GHz) is ok for all eight cores.
Next, I downloaded tiles-11.0-jar-with-dependencies.jar
from https://bitbucket.org/amotzek/tiles-11/downloads/ on all the nodes. On Linux I started the JAR with nohup java -server -jar tiles-11.0-jar-with-dependencies.jar -headless &
. After verifying the output with tail -f nohup.out
, I deleted nohup.out
and logged out.
The grid can be used with Calc, the Lisp spreadsheet. I published it here on Hackster.io for the "Pi Day" contest in 2017. Besides calculating Pi it also has some features for distributed computing, especially for remote evaluation. You can download it as calc-11.0-jar-with-dependencies.jar
from https://bitbucket.org/amotzek/calc-11/downloads/.
On a computer in the same LAN as your grid nodes you start Calc with either a double-click on the JAR file or with java -jar calc-11.0-jar-with-dependencies.jar
in a console.
Select cell A1 and type (get-places)
into the textarea at the bottom of the window. The first call to get-places
starts the subsystem for recognizing grid nodes. It also waits half a minute. That's because the grid nodes announce themselves every 30 seconds.
If your grid contains some more nodes the result from (get-places)
is too long to be displayed in the cell - indicated by the little rhombus. Then you can double-click the cell or use the menu Cell > Magnify to see the value in a separate window. Above you can see the list of my four grid nodes.
Now let's give the grid nodes some work to do. Select cell A2 and enter (at (first @a1) (+ 2 3))
. The result should be 5
.
What happened here? at
is a special form that takes two arguments. The first one is a place - one of your grid nodes. And the second argument is a piece of code that should be evaluated at that place. (first @a1)
is the first element of the list of your grid nodes in cell A1. And (+ 2 3)
is the sum of 2
and 3
.
Maybe you think "Hey, that's lame. I don't need a grid for computing the sum of 2 and 3.". Yes, that's right. So, let's find the prime factors of 1361129477984805314731035883700620113667
. If you can do that by mental calculation too, you can stop reading here :-)
In the attachments section of this project you find the file distributed-factorization.sheet.xml
. Download it and open it in Calc via the menu File > Open. Finding the prime factors will take some seconds. The result is in cell B1: (7 181 313 1171 2341 31357 565111 1046371 67525252471)
.
The program uses the elliptic-curve factorization method and is fast if the prime factors are small. The size of the input number doesn't affect the needed time so much.
You can inspect the factorization program and its modules via the menu Sheet > Show Program and Sheet > Show Modules and use it as inspiration for your own distributed programs running on a grid.
The documentation of the Lisp dialect can be found here (sorry, German language only). Happy hacking!
Comments