I was inspired by a Technology blogger Gary Sims to build my own (small) super computer using Raspberry Pi’s and a message passing interface library. Following his
Prime Numbers example the key concepts are:
Scatter - the MPI program will see each core in your cluster as something it can ask to do work. It will scatter the numbers accross the nodes to check if they are prime.
Gather - the MPI program will then gather the results. This is done on the master node that you started the command from.
In this video Gary explains what a
Raspberry Pi Supercomputer Cluster is and the key concepts of the message passing interface.
Follow the OS Steps (For Cluster), then call them
The distro come with most applications already installed, some of the applications I used were
ssh. Additional installs:
sudo apt-get install git python-mpi4py keychain ansible
Keychain section on this passwordless SSH access post.
mpiexec python python_script.py it can be run with the switch
-hostfile HOSTFILENAME, so the full command is then
mpiexec -hostfile hostfile python python_script.py
The content of the hostfile is either the DNS name or IP address of all the nodes in the cluster.
The PI’s need some problems to solve! Clone https://github.com/carlpaton/python-hoon to the same dir on both PI’s. Its important that the directorys are the same as the MASTER node (using MPI) will look in these directorys for the script to run.
The script prints hostnames and ranks (process id in MPI) from each MPI process in a sequential manner.
This script was copied from chainermn.readthedocs.io
Use parallel computing to find prime numbers in the range
10000. This is a Python 2 script cloned from github.com/garyexplains
The results below show the time taken to complete the script
primenumbers27.py using 8 cores, 4 cores and finally just 1 core. The results should probably be averaged out or something but running just once like the below clearly shows speed improvements. Using Wifi and the speed of my SD cards would also come into play.
What Are Prime Numbers?
- Greater than 1
- Whole number with exactly two factors, itself and 1.
Some examples of prime numbers: 2,3,5,7,11,13,17,19
The number 4 is not a prime number because it can be divided evenly by 4, 2, and 1. The number 5 is a prime number because it cannot be divided evenly by any other numbers except for 5 and 1.
2 / 1 = 2